Sanakey
2021-06-05 61abc9b654f78019a974c68916eb5718bc1c2992
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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 {}