Blame view

src/components/scm/addCouponPropertyPool.vue 5.04 KB
71def04c   wuxw   优化优惠
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
  <template>
    <el-dialog
      :title="$t('couponPropertyPoolManage.add.title')"
      :visible.sync="visible"
      width="50%"
      @close="handleClose"
    >
      <el-form
        ref="form"
        :model="formData"
        :rules="rules"
        label-width="120px"
      >
        <el-form-item
          :label="$t('couponPropertyPoolManage.add.couponName')"
          prop="couponName"
        >
          <el-input
            v-model="formData.couponName"
            :placeholder="$t('couponPropertyPoolManage.add.couponNamePlaceholder')"
          />
        </el-form-item>
  
        <el-form-item
          :label="$t('couponPropertyPoolManage.add.toType')"
          prop="toType"
        >
          <el-select
            v-model="formData.toType"
            :placeholder="$t('couponPropertyPoolManage.add.toTypePlaceholder')"
            style="width:100%"
            @change="handleToTypeChange"
          >
            <el-option
              v-for="item in toTypeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
  
        <el-form-item
          v-for="(item, index) in formData.toTypes"
          :key="index"
          :label="item.name"
        >
          <el-input
            v-model="item.columnValue"
            :placeholder="item.remark"
          />
        </el-form-item>
  
        <el-form-item
          :label="$t('couponPropertyPoolManage.add.stock')"
          prop="stock"
        >
          <el-input
            v-model="formData.stock"
            :placeholder="$t('couponPropertyPoolManage.add.stockPlaceholder')"
          />
        </el-form-item>
  
        <el-form-item
          :label="$t('couponPropertyPoolManage.add.validityDay')"
          prop="validityDay"
        >
          <el-input
            v-model="formData.validityDay"
            :placeholder="$t('couponPropertyPoolManage.add.validityDayPlaceholder')"
          />
        </el-form-item>
  
        <el-form-item
          :label="$t('couponPropertyPoolManage.add.remark')"
          prop="remark"
        >
          <el-input
            v-model="formData.remark"
            type="textarea"
            :placeholder="$t('couponPropertyPoolManage.add.remarkPlaceholder')"
            :rows="3"
          />
        </el-form-item>
      </el-form>
  
      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">{{ $t('common.cancel') }}</el-button>
        <el-button type="primary" @click="handleSubmit">{{ $t('common.confirm') }}</el-button>
      </span>
    </el-dialog>
  </template>
  
  <script>
  import { saveCouponPropertyPool, listCouponKey } from '@/api/scm/couponPropertyPoolManageApi'
  import { getCommunityId } from '@/api/community/communityApi'
  
  export default {
    name: 'AddCouponPropertyPool',
    data() {
      return {
        visible: false,
        formData: {
          couponName: '',
          fromType: '2002',
          toType: '',
          stock: '',
          validityDay: '',
          remark: '',
          toTypes: [],
          communityId: getCommunityId()
        },
        rules: {
          couponName: [
            { required: true, message: this.$t('couponPropertyPoolManage.validate.couponNameRequired'), trigger: 'blur' },
            { max: 64, message: this.$t('couponPropertyPoolManage.validate.couponNameMaxLength'), trigger: 'blur' }
          ],
          toType: [
            { required: true, message: this.$t('couponPropertyPoolManage.validate.toTypeRequired'), trigger: 'change' }
          ],
          stock: [
            { required: true, message: this.$t('couponPropertyPoolManage.validate.stockRequired'), trigger: 'blur' }
          ],
          validityDay: [
            { required: true, message: this.$t('couponPropertyPoolManage.validate.validityDayRequired'), trigger: 'blur' }
          ],
          remark: [
            { required: true, message: this.$t('couponPropertyPoolManage.validate.remarkRequired'), trigger: 'blur' }
          ]
        },
        toTypeOptions: [
          { value: '1011', label: this.$t('couponPropertyPoolManage.toType.shopping') },
          { value: '4004', label: this.$t('couponPropertyPoolManage.toType.parking') },
          { value: '5005', label: this.$t('couponPropertyPoolManage.toType.charging') }
        ]
      }
    },
    methods: {
      open() {
        this.visible = true
      },
      handleClose() {
        this.$refs.form.resetFields()
        this.formData.toTypes = []
      },
      async handleToTypeChange(val) {
        if (!val) return
        try {
          const params = {
            beanName: val,
            page: 1,
            row: 100
          }
          const { data } = await listCouponKey(params)
          this.formData.toTypes = data
        } catch (error) {
          console.error('获取优惠券属性失败:', error)
        }
      },
      handleSubmit() {
        this.$refs.form.validate(async valid => {
          if (valid) {
            try {
              await saveCouponPropertyPool(this.formData)
              this.$message.success(this.$t('couponPropertyPoolManage.add.success'))
              this.visible = false
              this.$emit('success')
            } catch (error) {
              this.$message.error(error.message || this.$t('couponPropertyPoolManage.add.error'))
            }
          }
        })
      }
    }
  }
  </script>