index.js 4.16 KB
// packageEquity/pages/employeeInspection/components/ItemSelectStore/itemSelectStore.js
import api from '../../api'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      observer: function (n) {
        if (n) {
          this.setData({
            pageNum: 1,
            storeIndex: null,
            nothing: false,
            keyword:'',
            merchantIdName:'',
            tempMerchantId: this.data.merchantId,
            scrollTop: 0
          }, () => {
            this.getData()

          })

        }
      }
    },
    sceneLabel: String,
    merchantId: String
  },

  /**
   * 组件的初始数据
   */
  data: {
    keyword: '',
    merchantIdName: '',
    scrollTop: 0,
    nothing: false,
    isFlag: false,
    total: 0,
    pageNum: 1,
    pageSize: 20,
    storeIndex: null,
    tempMerchantId: '',
    shopMerchantList: []
  },
  /**
   * 组件的方法列表
   */
  methods: {
    clear() {
      this.setData({
        keyword: "",
        merchantIdName:''
      });
      this.search();
    },
    input(e) {
      let {
        value
      } = e.detail;
      this.setData({
        keyword: value
      });
    },
    search() {
      this.setData({
        merchantIdName:this.data.keyword,
        pageNum:1,
        accountList: [],
        isFlag: false,
        nothing: false,
      }, () => {
        this.getData()
      });

    },
    getData() {
      let {
        shopMerchantList,
        total,
        merchantIdName,
        pageNum,
        pageSize
      } = this.data
      let params = {
        merchantIdName,
        pageNum,
        pageSize,
        sceneLabel: this.data.sceneLabel
      }
      api.getshopMerchantList(params).then(res => {
        if (res.code == 0) {
          let {
            list,
            total
          } = res.data;
          let tempList = pageNum == 1 ? list : [...shopMerchantList, ...res.data.list];
          this.setData({
            shopMerchantList: tempList,
            isFlag: true,
            total: total,
            nothing: pageNum == 1 ? false : total == tempList.length,
          }, () => {
            if (this.data.tempMerchantId ) this.initData()
          })

        }
      })
    },
    // 触底刷新
    mineReachBottom() {
      let {
        pageNum,
        total,
        pageSize
      } = this.data
      if (pageNum * pageSize >= total) {
        return
      }
      this.setData({
        pageNum: pageNum + 1
      }, () => {
        this.getData()
      })
    },
    initData(n) {
      let {
        shopMerchantList,
        storeIndex,
        tempMerchantId,

      } = this.data;
      storeIndex = null
      shopMerchantList.forEach((item, index) => {
        if (item.shopMerchantId == tempMerchantId) {
          storeIndex = index
        }
      })
      this.setData({
        storeIndex
      })
    },
    choose(e) {
      let {
        index
      } = e.currentTarget.dataset,
      {
        shopMerchantList
      } = this.data,
     {
        shopMerchantId
      } = shopMerchantList[index];
      this.setData({
        storeIndex: index,
        tempMerchantId:shopMerchantId
      })
    },
    confirm() {
      if (this.data.shopMerchantList.length == 0) return
      let {
        shopMerchantList,
        storeIndex
      } = this.data;
      if(storeIndex===null) {
        wx.$util.showToast('请选择门店');
        return 
      }
      let {
        shopMerchantId,
        shopMerchantName
      } = shopMerchantList[storeIndex];
      this.setData({
        show: false
      }, () => {
        let pageInstance = wx.$router.getPageInstance()
        let thisPage = pageInstance.selectComponent(`#componet-0`)

        thisPage.setData({
          shopMerchantBox: false,
          'staffObj.merchantId': shopMerchantId,
          'staffObj.merchantName': shopMerchantName
        }, () => {
          thisPage.getyqMerchantList()
        })
      })

    },
    hidePopup() {
      let pageInstance = wx.$router.getPageInstance()
      let thisPage = pageInstance.selectComponent(`#componet-0`)
      thisPage.setData({
        shopMerchantBox: false,
      })
      this.setData({
        storeIndex: 0
      })
    },
  }

})