index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // var util = require('../../../../../utils/util.js');
  2. // var api = require('../../../../../utils/api.js');
  3. // const pay = require('../../../../../services/pay.js');
  4. // const app = getApp()
  5. var Parse = getApp().Parse;
  6. const activeColor = getApp().globalData.activeColor
  7. // 触底上拉刷新 TODO 这里要将page传给服务器,作者没写
  8. Page({
  9. data: {
  10. addresses: [],
  11. nowAddress: 0,
  12. activeColor: null,
  13. titleColor:'#ffffff'
  14. },
  15. goAddressDetail: function (e) {
  16. let { titleColor, activeColor } = this.data
  17. let id = e.currentTarget.dataset.addressid;
  18. wx.navigateTo({
  19. url: `/common-page/pages/info/ucenter/address-detail/index?id=${id}&activeColor=${activeColor || '#ffffff'}&titleColor=${titleColor}`,
  20. })
  21. },
  22. async getAddresses() {
  23. let that = this;
  24. let addList = []
  25. let user = Parse.User.current();
  26. let query = new Parse.Query("ShopAddress");
  27. query.equalTo("user", user.id);
  28. let address = await query.find()
  29. if (address) {
  30. address.map(item => {
  31. addList.push({
  32. id: item.id,
  33. name: item.get("name"),
  34. province_name: item.get("province_name"),
  35. city_name: item.get("city_name"),
  36. district_name: item.get("district_name"),
  37. full_region: item.get("full_region"),
  38. address: item.get("address"),
  39. mobile: item.get("mobile")
  40. })
  41. })
  42. }
  43. that.setData({
  44. addresses: addList
  45. })
  46. // util.request(api.GetAddresses).then(function(res) {
  47. // if (res.errno === 0) {
  48. // that.setData({
  49. // addresses: res.data
  50. // })
  51. // }
  52. // });
  53. },
  54. selectAddress: function (e) {
  55. let {
  56. typeAddress
  57. } = this.data
  58. let addressId = e.currentTarget.dataset.addressid
  59. let address = e.currentTarget.dataset.address
  60. wx.setStorageSync('addressId', addressId);
  61. let pages = getCurrentPages()
  62. // 获取上一界面的页面内容
  63. let perPage = pages[pages.length - 2]
  64. perPage.setData({
  65. address: address
  66. })
  67. if (typeAddress) {
  68. perPage.setData({
  69. [typeAddress]: address
  70. })
  71. }
  72. wx.navigateBack();
  73. },
  74. onLoad: function (options) {
  75. let {
  76. type,
  77. activeColor,
  78. titleColor,
  79. typeAddress
  80. } = options;
  81. this.setData({
  82. type: type,
  83. activeColor: activeColor,
  84. titleColor:titleColor,
  85. typeAddress: typeAddress
  86. })
  87. },
  88. onUnload: function () {},
  89. onShow: function () {
  90. this.getAddresses();
  91. let addressId = wx.getStorageSync('addressId');
  92. if (addressId) {
  93. this.setData({
  94. nowAddress: wx.getStorageSync('addressId')
  95. });
  96. } else {
  97. this.setData({
  98. nowAddress: 0
  99. });
  100. }
  101. },
  102. // 新增地址
  103. addAddress: function () {
  104. let {activeColor}=this.data
  105. wx.navigateTo({
  106. url: '/common-page/pages/info/ucenter/address-detail/index?activeColor='+activeColor+'&titleColor=#ffffff',
  107. })
  108. },
  109. onPullDownRefresh: function () {
  110. wx.showNavigationBarLoading()
  111. this.getAddresses();
  112. wx.hideNavigationBarLoading() //完成停止加载
  113. wx.stopPullDownRefresh() //停止下拉刷新
  114. }
  115. })