order-goods-row.js 3.02 KB
Component({
  options: {
    addGlobalClass: true
  },
  properties: {
    product: {
      type: Object,
      value: {}
    },
    djOrderType: {
      type: Number,
      value: 1
    },
    selectPayType: {
      type: Number,
      value: 0
    },
    lowPriceFlag: {
      type: Number,
      value: 0
    },
    index: {
      type: Number,
      value: 0
    },
    gindex: {
      type: Number,
      value: -1
    },
    count: {
      type: Number,
      value: 1
    },
    isPackageSubItem: {
      type: Boolean,
      value: false
    },
    positionTypeList: {
      type: Array,
      value: []
    },
    baseConfigData: {
      type: Object,
      value: {}
    },
    positionNum: {
      type: String,
      value: ''
    },
    popupType: {
      type: String,
      value: '2'
    },
    showPopupName: {
      type: String,
      value: 'goodsBox'
    },
    productName: {
      type: String,
      value: ''
    },
    /** selectOrderGoods.list 返回,1 展示活动标 */
    marketingFlag: {
      type: Number,
      value: 0
    },
    /** 行级 activityId,与 marketingFlag 共同判定活动商品不可改价 */
    activityId: {
      type: null,
      value: null
    }
  },

  methods: {
    changePrice(e) {
      const { marketingFlag, activityId, product } = this.data
      const locked =
        product?.goodsPriceModify ||
        ((marketingFlag == 1 || product?.marketingFlag == 1) &&
          (activityId || product?.activityId))
      if (locked) return
      this.triggerEvent('priceChange', {
        value: e.detail.value,
        index: this.data.index,
        gindex: this.data.gindex,
        item: this.data.product
      })
    },
    priceBlur(e) {
      this.triggerEvent('priceBlur', {
        index: this.data.index,
        gindex: this.data.gindex
      })
    },
    changeProductDiscountType(e) {
      const { type } = e.currentTarget.dataset
      this.triggerEvent('discountTypeChange', {
        type,
        index: this.data.index,
        gindex: this.data.gindex
      })
    },
    inputDiscountValue(e) {
      this.triggerEvent('discountValueInput', {
        value: e.detail.value,
        index: this.data.index,
        gindex: this.data.gindex
      })
    },
    toggleGift(e) {
      this.triggerEvent('toggleGift', {
        value: e.detail.value,
        index: this.data.index,
        gindex: this.data.gindex
      })
    },
    delGoodsList() {
      this.triggerEvent('delete', {
        index: this.data.index
      })
    },
    showPopup(e) {
      const dataset = e.currentTarget.dataset
      // Pass the dataset needed for popup
      this.triggerEvent('showPopup', {
        ...dataset,
        index: this.data.index,
        gindex: this.data.gindex
      })
    },
    // For package sub-items, sometimes we need to know if it's the package itself or item inside
    changeMealPrice(e) {
      this.triggerEvent('mealPriceChange', {
        value: e.detail.value,
        index: this.data.index,
        gindex: this.data.gindex,
        item: this.data.product
      })
    }
  }
})