fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<template>
  <div class="activityRange">
    <div v-for="(item,index) in form.preferentialInfo" :key="index">
      <el-form-item v-show="form.preferentialWay === '1'">
        <p>
          {{index+1}} 级优惠
          <span class="buttonStyle">
            <el-button type="primary"
                       v-show="index <= 1 && index ===  form.preferentialInfo.length-1"
                       @click="addItem(item,index)">新增</el-button>
            <el-button type="danger" v-show="form.preferentialInfo.length !== 1"
                       @click="deleteItem(item,index)">删除</el-button>
          </span>
        </p>
      </el-form-item>
      <el-form-item label="优惠门槛:" :prop="'preferentialInfo.' + index + '.preferentialMaxAmount'"
                    :rules="formRules.maxAmount">
        <span>订单每满金额 </span>
        <el-input-number @keydown.native="limiInputType" :min="0"
                         v-model="item.preferentialMaxAmount"
                         @change="changeDiscountMoney(item,index)"></el-input-number>
        元
      </el-form-item>
      <el-form-item label="优惠内容:" :prop="'preferentialInfo.' + index + '.preferentialAmount'"
                    :rules="formRules.preferentialAmount">
        <div v-if="form.promotionType === '1'">
          <span>减 </span>
          <el-input-number @keydown.native="limiInputType" :min="0"
                           v-model="item.preferentialAmount"
                           @change="changeDiscountMoney(item,index)"></el-input-number>
          元
        </div>
        <div v-else>赠品</div>
      </el-form-item>
      <el-form-item v-show="form.promotionType === '2'"
                    :prop="'preferentialInfo.' + index + '.products'" :rules="formRules.products">
        <gift-component ref="table" :productData.sync="item.products" :form="form"
                        :formRules="formRules" @hand-selected="handSelected"
                        :preferentialIndex="index" :tableValidate='tableValidate'
                        :isShowSpuStorage="isShowSpuStorage">
          <template slot="productTableRow">
            <el-table-column label="限制总数" width="180px">
              <template slot-scope="scope">
                <el-form-item :prop="'preferentialInfo.' + index +'.products.' + scope.$index + '.maxbuyquantity'"
                              :rules="formRules.maxbuyquantity">
                  <el-input-number :min="0" @keydown.native="limiInputType"
                                   v-model="scope.row.maxbuyquantity"
                                   @change="changeMaxbuyquantity(scope.row, scope.$index, index)">
                  </el-input-number>
                </el-form-item>
              </template>
            </el-table-column>
          </template>
        </gift-component>
      </el-form-item>
      <el-form-item label="活动说明:" :prop="'preferentialInfo.' + index + '.memos'"
                    :rules="formRules.memos">
        <el-input placeholder="请输入活动说明" v-model="item.memos"></el-input>
      </el-form-item>
    </div>
  </div>
</template>
<script>
import giftComponent from '@/views/proActivity/components/giftComponent.vue'
import { limiInputType } from '@/utils/limiInputType'
export default {
  components: { giftComponent },
  props: ['form', 'formRules', 'isShowSpuStorage'],
  data() {
    return {
      // 表格内部表单验证prop
      tableValidate: {
        skuId(preferentialIndex, index) {
          return `preferentialInfo.${preferentialIndex}.products.${index}.skuId`
        },
        ensalequantity(preferentialIndex, index) {
          return `preferentialInfo.${preferentialIndex}.products.${index}.ensalequantity`
        }
      }
    }
  },
  methods: {
    /**
     * 当限制数量改变时判断与赠品数量的大小
     */
    changeMaxbuyquantity(row, index, parentIndex) {
      if (row.ensalequantity) {
        this.$parent.validateField(`preferentialInfo.${parentIndex}.products.${index}.ensalequantity`)
      }
    },
    // 当选择商品时
    handSelected() {
      this.$emit('hand-gift-selected')
    },
    /**
       * 当优惠门槛改变时触发设置优惠门槛金额
       */
    changeDiscountMoney(row, index) {
      if (row.preferentialMaxAmount && row.preferentialAmount) {
        console.log(this.$parent)
 
        this.$parent.validateField(`preferentialInfo.${index}.preferentialMaxAmount`)
        this.$parent.validateField(`preferentialInfo.${index}.preferentialAmount`)
      }
    },
 
    /**
     * 限制不能输入数字
     */
    limiInputType(e) {
      limiInputType(e)
    },
    /*
    * 新增
     */
    addItem(row, index) {
      this.form.preferentialInfo.push({
        memos: null,
        preferentialAmount: null,
        preferentialMaxAmount: null,
        preferentialMinAmount: null,
        preferentialWay: this.form.preferentialWay,
        products: []
      })
    },
    /*
    *删除
     */
    deleteItem(row, index) {
      this.form.preferentialInfo.splice(index, 1)
    }
  }
}
</script>
<style lang="scss">
.activityRange {
  p {
    background: #f2f3f6;
    padding-left: 10px;
    font-weight: 400;
    border-radius: 5px;
    position: relative;
  }
  .buttonStyle {
    position: absolute;
    right: 0;
  }
}
</style>