// var util = require('../../../../../utils/util.js'); // var api = require('../../../../../utils/api.js'); // const pay = require('../../../../../services/pay.js'); // const app = getApp() var Parse = getApp().Parse; const activeColor = getApp().globalData.activeColor // 触底上拉刷新 TODO 这里要将page传给服务器,作者没写 Page({ data: { addresses: [], nowAddress: 0, activeColor: null, titleColor:'#ffffff' }, goAddressDetail: function (e) { let { titleColor, activeColor } = this.data let id = e.currentTarget.dataset.addressid; wx.navigateTo({ url: `/common-page/pages/info/ucenter/address-detail/index?id=${id}&activeColor=${activeColor || '#ffffff'}&titleColor=${titleColor}`, }) }, async getAddresses() { let that = this; let addList = [] let user = Parse.User.current(); let query = new Parse.Query("ShopAddress"); query.equalTo("user", user.id); let address = await query.find() if (address) { address.map(item => { addList.push({ id: item.id, name: item.get("name"), province_name: item.get("province_name"), city_name: item.get("city_name"), district_name: item.get("district_name"), full_region: item.get("full_region"), address: item.get("address"), mobile: item.get("mobile") }) }) } that.setData({ addresses: addList }) // util.request(api.GetAddresses).then(function(res) { // if (res.errno === 0) { // that.setData({ // addresses: res.data // }) // } // }); }, selectAddress: function (e) { let { typeAddress } = this.data let addressId = e.currentTarget.dataset.addressid let address = e.currentTarget.dataset.address wx.setStorageSync('addressId', addressId); let pages = getCurrentPages() // 获取上一界面的页面内容 let perPage = pages[pages.length - 2] perPage.setData({ address: address }) if (typeAddress) { perPage.setData({ [typeAddress]: address }) } wx.navigateBack(); }, onLoad: function (options) { let { type, activeColor, titleColor, typeAddress } = options; this.setData({ type: type, activeColor: activeColor, titleColor:titleColor, typeAddress: typeAddress }) }, onUnload: function () {}, onShow: function () { this.getAddresses(); let addressId = wx.getStorageSync('addressId'); if (addressId) { this.setData({ nowAddress: wx.getStorageSync('addressId') }); } else { this.setData({ nowAddress: 0 }); } }, // 新增地址 addAddress: function () { let {activeColor}=this.data wx.navigateTo({ url: '/common-page/pages/info/ucenter/address-detail/index?activeColor='+activeColor+'&titleColor=#ffffff', }) }, onPullDownRefresh: function () { wx.showNavigationBarLoading() this.getAddresses(); wx.hideNavigationBarLoading() //完成停止加载 wx.stopPullDownRefresh() //停止下拉刷新 } })