Sanakey
2021-06-04 355a84d740a2a9dfa1d67cb2d2e11843d42809ac
pages/sellerList/sellerList.ts
@@ -4,52 +4,70 @@
    selectedSellerIdList:[],
    selectedSellerList:[] as any,
    sellerList:[
      {DocItem: 10, SellerId: 111, SellerName: "好几十", Telephone: "15555555555", isDefaultSellerName: false},
      {DocItem: 10, SellerId: 222, SellerName: "好", Telephone: "15588885555", isDefaultSellerName: false},
      {DocItem: 10, SellerId: 333, SellerName: "555", Telephone: "18888555555", isDefaultSellerName: false},
      {DocItem: 10, SellerId: 444, SellerName: "666", Telephone: "18333333333", isDefaultSellerName: false},
      {DocItem: 10, SellerId: 555, SellerName: "777", Telephone: "18666666666", isDefaultSellerName: false},
    ]
      // {DocItem: 10, SellerId: 111, SellerName: "好几十", Telephone: "15555555555", isDefaultSellerName: false},
      // {DocItem: 10, SellerId: 222, SellerName: "好", Telephone: "15588885555", isDefaultSellerName: false},
      // {DocItem: 10, SellerId: 333, SellerName: "555", Telephone: "18888555555", isDefaultSellerName: false},
      // {DocItem: 10, SellerId: 444, SellerName: "666", Telephone: "18333333333", isDefaultSellerName: false},
      // {DocItem: 10, SellerId: 555, SellerName: "777", Telephone: "18666666666", isDefaultSellerName: false},
    ] as any
  },
  onLoad() {
  async onLoad() {
    console.log(app);
    let isVip = !wx.globalData.loginData.isExpired;
    this.setData({
      isVip
    })
    await this.getSellerList();
    // this.getSellerList();
    const eventChannel = this.getOpenerEventChannel();
    eventChannel.on('getSellerListFromPromotionsPage', (data:any)=> {
      console.log('获取新建活动时选中的营销人员',data)
      this.setData({
        selectedSellerIdList:data.selectedSellerIdList,
      })
      // this.setData({
      //   selectedSellerIdList:data.selectedSellerIdList,
      // })
      this.handleSelectedSellerList(data.selectedSellerIdList);
    })
  },
  // handleSelectedSellerList(list:[]){
  //   let {sellerList, selectedSellerIdList} = this.data;
  //   selectedSellerIdList.forEach((id)=>{
  //     sellerList.forEach((item)=>{
  //       if (item.SellerId == id) {
  //
  //       }
  //     })
  //   })
  // },
  onShow() {
  getSelectedSellerList(){
    let {sellerList, selectedSellerIdList,selectedSellerList} = this.data;
    selectedSellerIdList.forEach((id)=>{
      sellerList.forEach((item)=>{
        if (item.SellerId == Number(id)) {
          selectedSellerList.push(item)
  },
  handleSelectedSellerList(list:[]){
    let {sellerList} = this.data;
    console.log('handleSelectedSellerList',sellerList);
    let selectedSellerIdList = [] as any;
    list.forEach((id)=>{
      sellerList.forEach((item:any)=>{
        if (item.sellerId == id) {
          selectedSellerIdList.push(id)
        }
      })
    })
    return selectedSellerList;
    console.log(selectedSellerIdList);
    this.setData({
      selectedSellerIdList
    })
  },
  // getSelectedSellerList(){
  //   let {sellerList, selectedSellerIdList,selectedSellerList} = this.data;
  //   selectedSellerIdList.forEach((id)=>{
  //     sellerList.forEach((item:any)=>{
  //       if (item.SellerId == Number(id)) {
  //         selectedSellerList.push(item)
  //       }
  //     })
  //   })
  //   return selectedSellerList;
  // },
  selectSeller(event:any) {
    console.log(event)
    this.setData({
      selectedSellerIdList: event.detail
    });
    // wx.globalData.sellerData = {
    //   selectedSellerIdList:event.detail,
    // }
  },
  toggle(event:any) {
    const { index } = event.currentTarget.dataset;
@@ -61,28 +79,55 @@
    console.log(event);
  },
  goSellerEdit(event:any){
    let id = event.currentTarget.dataset.id;
    let id = event.currentTarget.dataset.id || '';
    wx.navigateTo({
      url:`../sellerEdit/sellerEdit?id=${id}`
      url:`../sellerEdit/sellerEdit?id=${id}`,
      success: (res)=> {
        let selectedSellerIdList = this.data.selectedSellerIdList;
        // 通过eventChannel向被打开页面传送数据
        res.eventChannel.emit('getSellerListFromSellerListPage', {
          selectedSellerIdList
        })
      },
      events: {
        // 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
        getSelectedSellerIdListFromSellerEditPage: async (data: any)=> {
          console.log('获取营销人员删除或编辑后选中的data',data)
          await this.getSellerList();
          this.setData({
            selectedSellerIdList:data.selectedSellerIdList,
          })
        }
      }
    })
  },
  onSubmit(){
    let {selectedSellerIdList} = this.data;
    let selectedSellerList = this.getSelectedSellerList();
    console.log('选中的营销人员id与列表',selectedSellerIdList,selectedSellerList);
    // let selectedSellerList = this.getSelectedSellerList();
    console.log('选中的营销人员id与列表',selectedSellerIdList,
      // selectedSellerList
    );
    let eventChannel = this.getOpenerEventChannel();
    eventChannel.emit('getSelectedSellerList', {
      selectedSellerIdList,
      selectedSellerList
      // selectedSellerList
    });
    // wx.globalData.sellerData = {
    //   selectedSellerIdList,
    //   selectedSellerList
    // }
    wx.navigateBack();
  },
  // onUnload() {
  //   setTimeout(() => {console.log(777);},1000)
  //   console.log(666);
  // },
  async getSellerList() {
    let [error, result] = await wx.$utils.to(
      wx.$http.request({
        url:`/shopping/panicBuying.do?m=getMyVisiteTraceList`,
        url:`/shopping/panicBuyingSeller.do?m=getSellerList`,
      })
    )
    if (error){
@@ -90,6 +135,10 @@
      return;
    }
    console.log(result);
    this.setData({
      sellerList:result.sellerList,
    })
    wx.globalData.sellerList = result.sellerList;
  }
})
export {}