address.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. var app = getApp();
  4. Page({
  5. data: {
  6. addressList: [],
  7. total: 0
  8. },
  9. onLoad: function(options) {
  10. // 页面初始化 options为页面跳转所带来的参数
  11. },
  12. onReady: function() {
  13. // 页面渲染完成
  14. },
  15. onShow: function() {
  16. // 页面显示
  17. this.getAddressList();
  18. },
  19. getAddressList() {
  20. let that = this;
  21. util.request(api.AddressList).then(function(res) {
  22. if (res.errno === 0) {
  23. that.setData({
  24. addressList: res.data.list,
  25. total: res.data.total
  26. });
  27. }
  28. });
  29. },
  30. addressAddOrUpdate(event) {
  31. console.log(event)
  32. //返回之前,先取出上一页对象,并设置addressId
  33. var pages = getCurrentPages();
  34. var prevPage = pages[pages.length - 2];
  35. if (prevPage.route == "pages/checkout/checkout") {
  36. try {
  37. wx.setStorageSync('addressId', event.currentTarget.dataset.addressId);
  38. } catch (e) {
  39. }
  40. let addressId = event.currentTarget.dataset.addressId;
  41. if (addressId && addressId != 0) {
  42. wx.navigateBack();
  43. } else {
  44. wx.navigateTo({
  45. url: '/pages/ucenter/addressAdd/addressAdd?id=' + addressId
  46. })
  47. }
  48. } else {
  49. wx.navigateTo({
  50. url: '/pages/ucenter/addressAdd/addressAdd?id=' + event.currentTarget.dataset.addressId
  51. })
  52. }
  53. },
  54. deleteAddress(event) {
  55. console.log(event.target)
  56. let that = this;
  57. wx.showModal({
  58. title: '',
  59. content: '确定要删除地址?',
  60. success: function(res) {
  61. if (res.confirm) {
  62. let addressId = event.target.dataset.addressId;
  63. util.request(api.AddressDelete, {
  64. id: addressId
  65. }, 'POST').then(function(res) {
  66. if (res.errno === 0) {
  67. that.getAddressList();
  68. wx.removeStorage({
  69. key: 'addressId',
  70. success: function(res) {},
  71. })
  72. }
  73. });
  74. console.log('用户点击确定')
  75. }
  76. }
  77. })
  78. return false;
  79. },
  80. onHide: function() {
  81. // 页面隐藏
  82. },
  83. onUnload: function() {
  84. // 页面关闭
  85. }
  86. })