const app = getApp(); import commonApi from '../../../api/common'; import user from '../../../api/user'; import userApi from '../../../api/user'; Page({ /** * 页面的初始数据 */ data: { // communityList:[], isLogin:!!app.globalData.accessToken, currentAddress:null, currentCommunity:{ id:null, name:'' }, package:{ name:'', count:0 }, isShowOrderConfirm:false, preOrder:{} // addressList:[], // addressIndex:0 }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.getAddress(); wx.getStorage({ key:'pre-order', success:(res)=>{ console.log(res.data); const name = []; let count = 0; res.data.price_request.package.map((item)=>{ name.push(item.station_name); count+=item.pickup_codes.split(',').length; }); this.setData({ package:{ name:name.join('|'), count:count } }) } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { //这里要要重新过滤当前送达地址,因为可能会重新选择社区 }, getAddress(communityId){ commonApi.address.list(communityId).then((data)=>{ let currentAddress = data[0]||{}; data.map((item,index)=>{ if(item.is_default){ currentAddress = item; } }) this.setData({ currentAddress, }); if(currentAddress.id){ this.setData({ currentCommunity:{ id:currentAddress.community_id, name:currentAddress.community_name } }) } }); }, changeCommunity(community){ this.setData({ currentCommunity:{ id:community.id, name:community.name } }); this.getAddress(community.id); }, changeAddress(address){ this.setData({ currentAddress:address }) }, preOrder(){ wx.getStorage({ key:'pre-order', success:(res)=>{ userApi.order.pre({ packages:res.data.price_request.package }).then((data)=>{ this.setData({ isShowOrderConfirm:true, preOrder:data }); }) } }) }, getOrder(){ wx.getStorage({ key:'pre-order', success:(res)=>{ // let packages = []; // res.data.price_request.package.map((item)=>{ // packages.push({ // station_id:item.station_id, // pickup_codes:item.pickup_codes // }); // }); res.data.addressid = this.data.currentAddress.id; userApi.order.real(res.data).then((data)=>{ wx.navigateTo({ url: '/pages/help/success', }) }); } }); }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { }, goToAddPackage(){ wx.navigateTo({ url: `/pages/help/package/index?communityId=${this.data.currentCommunity.id}`, }) }, goToCommunity(){ wx.navigateTo({ url: `/pages/help/community/index?communityId=${this.data.currentCommunity.id}`, }) }, goToAddress(){ if(app.globalData.accessToken){ wx.navigateTo({ url: `/pages/help/address/index/index?communityId=${this.data.currentCommunity.id}`, }) }else{ app.navToLogin(); } } })