Page({
|
data: {
|
selectedStoreIdList:[],
|
selectedStoreList:[] as any,
|
storeList:[] as any
|
},
|
async onLoad() {
|
let isVip = !wx.globalData.loginData.isExpired;
|
this.setData({
|
isVip
|
})
|
|
await this.getStoreList();
|
// this.getStoreList();
|
const eventChannel = this.getOpenerEventChannel();
|
eventChannel.on('getStoreListFromPromotionsPage', (data:any)=> {
|
console.log('获取新建活动时选中的门店',data)
|
this.handleSelectedStoreList(data.selectedStoreIdList);
|
})
|
},
|
async onShow() {
|
},
|
handleSelectedStoreList(list:[]){
|
let {storeList} = this.data;
|
console.log('handleSelectedStoreList',storeList);
|
let selectedStoreIdList = [] as any;
|
list.forEach((id)=>{
|
storeList.forEach((item:any)=>{
|
if (item.docCode == id) {
|
selectedStoreIdList.push(id)
|
}
|
})
|
})
|
console.log(selectedStoreIdList);
|
this.setData({
|
selectedStoreIdList
|
})
|
|
},
|
|
// getSelectedStoreList(){
|
// let {storeList, selectedStoreIdList,selectedStoreList} = this.data;
|
// selectedStoreIdList.forEach((id)=>{
|
// storeList.forEach((item:any)=>{
|
// if (item.StoreId == Number(id)) {
|
// selectedStoreList.push(item)
|
// }
|
// })
|
// })
|
// return selectedStoreList;
|
// },
|
selectStore(event:any) {
|
console.log(event)
|
this.setData({
|
selectedStoreIdList: event.detail
|
});
|
// wx.globalData.storeData = {
|
// selectedStoreIdList:event.detail,
|
// }
|
},
|
toggle(event:any) {
|
const { index } = event.currentTarget.dataset;
|
const checkbox = this.selectComponent(`.checkboxes-${index}`);
|
checkbox.toggle();
|
console.log(index);
|
},
|
toggle2(event:any){
|
console.log(event);
|
},
|
goStoreEdit(event:any){
|
let doccode = event.currentTarget.dataset.doccode || '';
|
wx.navigateTo({
|
url:`../storeEdit/storeEdit?doccode=${doccode}`,
|
success: (res)=> {
|
let selectedStoreIdList = this.data.selectedStoreIdList;
|
// 通过eventChannel向被打开页面传送数据
|
res.eventChannel.emit('getStoreListFromStoreListPage', {
|
selectedStoreIdList
|
})
|
},
|
events: {
|
// 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
|
getSelectedStoreIdListFromStoreEditPage: async (data: any)=> {
|
console.log('获取门店删除或编辑后选中的data',data)
|
await this.getStoreList();
|
this.setData({
|
selectedStoreIdList:data.selectedStoreIdList,
|
})
|
}
|
}
|
})
|
},
|
|
onSubmit(){
|
let {selectedStoreIdList} = this.data;
|
// let selectedStoreList = this.getSelectedStoreList();
|
console.log('选中的门店id与列表',selectedStoreIdList,
|
// selectedStoreList
|
);
|
let eventChannel = this.getOpenerEventChannel();
|
eventChannel.emit('getSelectedStoreList', {
|
selectedStoreIdList,
|
// selectedStoreList
|
});
|
// wx.globalData.storeData = {
|
// selectedStoreIdList,
|
// selectedStoreList
|
// }
|
wx.navigateBack();
|
},
|
// onUnload() {
|
// setTimeout(() => {console.log(777);},1000)
|
// console.log(666);
|
// },
|
|
async getStoreList() {
|
let [error, result] = await wx.$utils.to(
|
wx.$http.request({
|
url:`/shopping/customerStore.do?m=getCustomerStoreList`,
|
})
|
)
|
if (error){
|
console.log(error);
|
return;
|
}
|
console.log(result);
|
this.setData({
|
storeList:result.list,
|
})
|
wx.globalData.storeList = result.list;
|
}
|
})
|
export {}
|