address.js 2.3 KB

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