Sanakey
2021-04-30 8724a444c8a1d09dc8f9efd005e8443aad8df1ab
pages/liveRoomGoodsSelect/liveRoomGoodsSelect.ts
@@ -3,15 +3,28 @@
    arrayList:[],
    checkResults: [] as any,
    doccode:'',
    roomid:'',
    hadRelationList:[]
  },
  onLoad(options) {
    let doccode = options.doccode || '';
    let from = options.from || '';
    let roomid = options.roomid || '';
    this.setData({
      doccode
      doccode,
      roomid,
      fromPage:from
    })
    this.getPromotionsRelationList();
    this.getHadRelationList();
    if (from=='myStock'){
      this.getPanicBuyingListForLiveGoods();
    }
    if (from=='myLive'){
      wx.setNavigationBarTitle({
        title: '选择直播商品'
      })
      this.getGoodsListForImportRoom();
    }
  },
  onChange(event:any) {
    console.log(event.detail);
@@ -26,13 +39,27 @@
    const checkbox = this.selectComponent(`.checkboxes-${index}`);
    checkbox.toggle();
  },
  async getPromotionsRelationList(){
    let doccode = this.data.doccode;
  async getPanicBuyingListForLiveGoods(){
    let [error, result] = await wx.$utils.to(
      wx.$http.request({
        url:`/shopping/panicBuying.do?m=getMayableRelationList`,
        data:{
          doccode
        url:`/shopping/panicBuyingLive/getPanicBuyingListForImportGoods.do`,
      })
    )
    if (error){
      console.log(error);
      return;
    }
    console.log(result);
    this.setData({
      goodsList:result.list
    })
  },
  async getGoodsListForImportRoom(){
    let [error, result] = await wx.$utils.to(
      wx.$http.request({
        url:`/shopping/panicBuyingLive/getGoodsListForImportRoom.do`,
        data: {
          roomid:this.data.roomid
        }
      })
    )
@@ -42,17 +69,14 @@
    }
    console.log(result);
    this.setData({
      relationList: result.mayableRelationList
      goodsList:result.list
    })
  },
  async getHadRelationList(){
    let doccode = this.data.doccode;
  async addGoods(data:any){
    let [error, result] = await wx.$utils.to(
      wx.$http.request({
        url:`/shopping/panicBuying.do?m=getHadRelationList`,
        data:{
          doccode
        }
        url:data.url,
        data: data.data
      })
    )
    if (error){
@@ -60,45 +84,32 @@
      return;
    }
    console.log(result);
    this.handleRelationList(result.hadRelationList);
  },
  handleRelationList(list:any[]){
    let checkResults: any[] = [];
    list.forEach((item:any)=>{
      if (item.doccode){
        checkResults.push(item.doccode)
      }
    })
    this.setData({
      checkResults
    })
  },
  async saveRelationList(){
    let docCode = this.data.doccode;
    let panicBuyingDocCodes = this.data.checkResults;
    let [error, result] = await wx.$utils.to(
      wx.$http.request({
        url:`/shopping/panicBuying.do?m=saveRelationList`,
        data:{
          docCode,
          panicBuyingDocCodes
        },
        method:'POST'
      })
    )
    if (error){
      console.log(error);
      return;
    }
    console.log(result);
    wx.showToast({title: '保存成功'})
    wx.showToast({title: '添加成功'})
    setTimeout(()=>{
      wx.navigateBack()
    },1000)
  },
  onSubmitSave(){
  onSubmitForStock(){
    console.log(this.data.checkResults);
    // this.saveRelationList();
    let doccode = this.data.checkResults.join();
    this.addGoods({
      url:`/shopping/panicBuyingLiveGoods.do?m=add`,
      data:{
        doccode
      }
    });
  },
  onSubmitForLiveRoom(){
    console.log(this.data.checkResults);
    let goodsid = this.data.checkResults.join();
    let roomid = this.data.roomid;
    this.addGoods({
      url:`/shopping/live/addGoodsToRoom.do`,
      data:{
        roomid,
        goodsid
      }
    });
  }
})
export {}