162 lines
3.4 KiB
JavaScript
162 lines
3.4 KiB
JavaScript
import commonApi from '../../../api/common';
|
|
import userApi from '../../../api/user';
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
stationList:[],
|
|
sendType:'DELIVERY_AT_DOORSTEP'
|
|
},
|
|
|
|
bottomBarButtonTap(){
|
|
const data = [];
|
|
this.data.stationList.map((item)=>{
|
|
if(item.package.length>0&&item.package[0]!=''){
|
|
data.push({
|
|
station_id:item.id,
|
|
station_name:item.name,
|
|
pickup_codes:item.package.filter((item)=>item!='').join(',')
|
|
});
|
|
}
|
|
})
|
|
if(data.length>0){
|
|
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 = [];
|
|
}
|
|
let hasEmptyInput = this.data.stationList[index].package.find((item)=>item=='')==undefined;
|
|
if(hasEmptyInput){
|
|
this.data.stationList[index].package.push('');
|
|
}
|
|
this.data.stationList[index].focus = true;
|
|
this.setData({
|
|
[`stationList[${index}]`]:this.data.stationList[index]
|
|
});
|
|
},
|
|
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[${itemIndex}].package`]:this.data.stationList[itemIndex].package
|
|
})
|
|
},
|
|
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,index)=>{
|
|
const __item = res.data.price_request.packages.find((_item)=>_item.station_id==item.id);
|
|
if(__item){
|
|
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
|
|
});
|
|
wx.nextTick(()=>{
|
|
this.setData({
|
|
[`stationList[0].focus`]:true
|
|
})
|
|
});
|
|
});
|
|
},
|
|
sendTypeChange(event){
|
|
this.setData({
|
|
sendType:event.detail.value
|
|
});
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {
|
|
|
|
}
|
|
}) |