artificerSelectPopup.js 3.42 KB
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/'
// components/subShopMerchant/subShopMerchant.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      observer: function(n) {
        if (n) {
          let { copyArtificerList, artificerSelectObj } = this.data
          copyArtificerList.map(i => {
            i.active = false
            if (i.id == artificerSelectObj?.technicianId) {
              i.active = true
            }
            return i
          })
          this.setData({
            artificerList: wx.$util.deepClone(copyArtificerList),
            selectedTechnicianId: artificerSelectObj?.technicianId,
            searchValue: ''
          })
        }
      }
    },
    title: String,
    orderInfo: Object,
    artificerSelectObj: Object,
    copyArtificerList: Array
  },

  /**
   * 组件的初始数据
   */
  data: {
    orderObj: {},
    IMG_URL,
    artificerList: [],
    searchValue: ''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    search(e) {
      let { copyArtificerList } = wx.$util.deepClone(this.data)
      let { selectedTechnicianId } = this.data
      let { value } = e.detail
      if (!value) {
        copyArtificerList.map(i => {
          i.active = false
          if (i.id == selectedTechnicianId) i.active = true
          return i
        })
        this.setData({
          artificerList: copyArtificerList
        })
      } else {
        let arr = []
        copyArtificerList.map(i => {
          i.active = false
          if (i.id == selectedTechnicianId) i.active = true
          if (i.staffName.indexOf(value) != -1) {
            arr.push(i)
          }
        })
        this.setData({
          artificerList: arr
        })
      }
    },
    changeItem(e) {
      let { target } = e.currentTarget.dataset
      let { artificerList } = this.data
      let { copyArtificerList } = wx.$util.deepClone(this.data)
      artificerList.forEach(i => {
        if (i.id != target?.id) i.active = false
        if (i.id == target?.id) i.active = !i.active 
      })
      copyArtificerList.forEach(i => {
        if (i.id != target?.id) i.active = false
        if (i.id == target?.id) i.active = !i.active 
      })
      this.setData({
        artificerList,
        copyArtificerList,
        selectedTechnicianId: target.id
      })
    },
    cancel() {
      let thisPage = wx.$router.getPageInstance()
      thisPage.setData({
        artificerSelectPopup: false
      })
    },
    // 打开生意助手小程序
    goMiniprogram() {
      wx.navigateToMiniProgram({
        appId: 'wx2c28337db96364d2'
      })
    },
    async confirm() {
      let { copyArtificerList, orderInfo, artificerSelectObj, selectedTechnicianId } = this.data
      let arr = copyArtificerList?.filter(v => v.active) || []
      if (!arr.length) {
        // return wx.$util.showToast('请选择技师')
        // 未选技师 将selectedTechnicianId清除
        this.setData({
          selectedTechnicianId: ''
        })
      }
      let obj = {
        ...artificerSelectObj,
        technicianUuid: arr[0]?.uuid || '',
        technicianId: arr[0]?.id || '',
        technicianName:  arr[0]?.staffName || ''
      }
      // orderInfo.technicianUuid = arr[0]?.uuid || ''
      // orderInfo.technicianId = arr[0]?.id || ''
      // orderInfo.technicianName = arr[0]?.staffName || ''
      this.triggerEvent('confirm', obj)
    }
  }
})