index.js 3.0 KB

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