selectServicePopup.js 2.8 KB
// pages/tab/output/components/accountSwitchingPop/accountSwitchingPop.js
import { IMG_URL } from '~/utils/constantData.js'
Component({
  options: {
    addGlobalClass: true
  },
  /**
   * 组件的属性列表
   */
  properties: {
    popShow: {
      type: Boolean,
      value: false,
      observer: function (n) {
        if (n) {
          let { serviceRange, selectInfo } = this.data
          let activeIndex = serviceRange.findIndex(v => v.yqMerchantId == selectInfo.yqMerchantId)
          if (serviceRange.length) serviceRange.unshift({yqMerchantId: '', yqMerchantName: '全部'})
          serviceRange.forEach((item, ind) => {
            item.show = true
            if (activeIndex == (ind - 1)) {
              item.act = true
            } else {
              item.act = false
            }
          })
          this.setData({
            searchKeyword: '',
            serviceRange
          })
        }
      }
    },
    serviceRange: Object,
    selectInfo: Object
  },

  /**
   * 组件的初始数据
   */
  data: {
    IMG_URL,
    serviceList: [],
    searchKeyword: ''
  },
  observers: {
    serviceRange: function (e) {
      this.setData({
        serviceList: e || []
      })
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    hidePopup() {
      this.triggerEvent('hidePopup')
    },
    confirm() {
      let { serviceRange, subIndex } = this.data
      let actObj = serviceRange.find((item, index) => {
        if (item.act) {
          subIndex = index
        }
        return item.act
      })
      if (!actObj) {
        return wx.$api.showToast({
          title: '请选择服务中心',
          icon: 'error'
        })
      } else {
        if (actObj.yqMerchantId == '' && actObj.yqMerchantName == '全部') actObj.yqMerchantName = '全部服务中心'
        this.changePicker(actObj)
      }
    },
    changePicker(actObj) {
      // 修改对应下标显示
      wx.$api.showLoading('加载中...')
      this.triggerEvent('getStaffList', {...actObj})
      this.hidePopup()
    },
    select(e) {
      let { index } = e.currentTarget.dataset
      let { serviceRange } = this.data
      serviceRange.forEach((item, ind) => {
        if (index == ind) {
          item.act = true
        } else {
          item.act = false
        }
      })
      this.setData({
        serviceRange
      })
    },
    search(e) {
      let { serviceRange } = this.data
      let { value } = e.currentTarget.dataset && Object.keys(e.currentTarget.dataset).length ? e.currentTarget.dataset : e.detail
      serviceRange.forEach(item => {
        item.act = false
        item.show = item.yqMerchantName?.includes(value)
      })
      this.setData({
        serviceRange
      })
    },
    input(e) {
      let { value } = e.detail
      this.setData({
        searchKeyword: value
      })
    }
  }
})