index.js 1.6 KB
// tabRepairOrder/components/relateGoodsPop/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    goodsList: Array,
    selected: Array,
    baseConfigData: Object,
    show: {
      type: Boolean,
      observer: function (n) {
        if (n) {
          let { goodsList, selected } = this.data
          goodsList?.map(val => {
            val.active = false
            if (
              selected?.findIndex(v => v.subOrderCode == val.subOrderCode) > -1
            )
              val.active = true
            return val
          })
          this.setData({ goodsList })
        }
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {},

  /**
   * 组件的方法列表
   */
  methods: {
	openInventoryPopup(e){
		console.log(e)
		let {inventory:{
			upgradeGoodsCommodityCode,
			upgradeGoodsCustomCode,
			specification,
			stock
		  }} = e.target.dataset
		  const inventoryData ={
			upgradeGoodsCommodityCode,
			upgradeGoodsCustomCode,
			specification,
			stock
		  }
		this.triggerEvent('openInventory', inventoryData)
	},
    choose(e) {
      let { item } = e.currentTarget.dataset
      let { goodsList } = this.data
      goodsList?.forEach(val => {
        if (val.subOrderCode == item.subOrderCode) val.active = !val.active
      })
      this.setData({
        goodsList
      })
    },
    cancel() {
      this.triggerEvent('cancel')
    },
    confirm() {
      let { goodsList } = this.data
      const arr = goodsList?.filter(val => val.active)
      if (!arr.length) return wx.$util.showToast('请选择关联商品')
      this.triggerEvent('confirm', arr)
    }
  }
})