import commonApi from '../../../api/common'; import userApi from '../../../api/user'; Page({ /** * 页面的初始数据 */ data: { stationList:[], sendType:'DELIVERY_AT_DOORSTEP' }, bottomBarButtonTap(){ const data = []; let hasPackage = false; this.data.stationList.map((item)=>{ if(item.package.length>0&&item.package[0]!=''){ hasPackage = true; } data.push({ station_id:item.id, station_name:item.name, pickup_codes:item.package.filter((item)=>item!='').join(',') }); }) if(hasPackage){ wx.setStorage({ key:'pre-order', data:{ price_request:{ packages:data }, delivery_method:this.data.sendType }, success(){ wx.navigateBack(); } }) }else{ wx.removeStorage({ key: 'pre-order', success(){ wx.navigateBack(); } }) } }, addPackage(event){ const index = event.currentTarget.dataset.index; if(!this.data.stationList[index].package){ this.data.stationList[index].package = []; } this.data.stationList[index].package.push(''); this.setData({ stationList:this.data.stationList }); }, deletePackage(event){ const itemIndex = event.currentTarget.dataset.index; const packageIndex = event.currentTarget.dataset.p_index; this.data.stationList[itemIndex].package.splice(packageIndex,1); this.setData({ stationList:this.data.stationList }) }, setPackageCode(event){ const itemIndex = event.currentTarget.dataset.index; const packageIndex = event.currentTarget.dataset.p_index; this.data.stationList[itemIndex].package[packageIndex] = event.detail.value; }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { commonApi.station.list(options.communityId).then((data)=>{ wx.getStorage({ key:'pre-order', success:(res)=>{ data.items.map((item)=>{ const __item = res.data.price_request.packages.find((_item)=>_item.station_id==item.id); item.package = __item.pickup_codes.split(',')||['']; }); this.setData({ sendType:res.data.delivery_method, stationList:data.items }) } }); data.items.map((item)=>{ item.package = ['']; }); this.setData({ stationList:data.items }) }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })