Blame view

src/components/fee/editFeeDiscount.vue 6.46 KB
6ec243d6   wuxw   v1.9 点击提交后,成功提示没有...
1
  <template>
76d4c8fc   wuxw   优惠需要申请测试中
2
3
4
5
6
    <el-dialog :title="$t('feeDiscountManage.edit.title')" :visible.sync="visible" width="40%" @close="handleClose">
      <el-form ref="form" :model="editFeeDiscountInfo" label-width="120px" :rules="rules">
        <el-form-item :label="$t('feeDiscountManage.edit.discountName')" prop="discountName">
          <el-input v-model.trim="editFeeDiscountInfo.discountName"
            :placeholder="$t('feeDiscountManage.edit.discountNamePlaceholder')" />
7505cb92   wuxw   开发完成折扣设置
7
        </el-form-item>
76d4c8fc   wuxw   优惠需要申请测试中
8
9
10
11
12
13
        <el-form-item :label="$t('feeDiscountManage.edit.discountType')" prop="discountType">
          <el-select v-model="editFeeDiscountInfo.discountType"
            :placeholder="$t('feeDiscountManage.edit.discountTypePlaceholder')" style="width:100%"
            @change="_changeEditFeeDiscountType">
            <el-option v-for="item in editFeeDiscountInfo.discountTypes" :key="item.statusCd" :label="item.name"
              :value="item.statusCd" />
7505cb92   wuxw   开发完成折扣设置
14
15
          </el-select>
        </el-form-item>
76d4c8fc   wuxw   优惠需要申请测试中
16
17
18
19
20
        <el-form-item :label="$t('feeDiscountManage.edit.rule')" prop="ruleId">
          <el-select v-model="editFeeDiscountInfo.ruleId" :placeholder="$t('feeDiscountManage.edit.rulePlaceholder')"
            style="width:100%" @change="_changeEditFeeDiscountRule">
            <el-option v-for="item in editFeeDiscountInfo.rules" :key="item.ruleId" :label="item.ruleName"
              :value="item.ruleId" />
7505cb92   wuxw   开发完成折扣设置
21
22
          </el-select>
        </el-form-item>
76d4c8fc   wuxw   优惠需要申请测试中
23
24
        <el-form-item v-for="(item, index) in editFeeDiscountInfo.feeDiscountRuleSpecs" :key="index" :label="item.specName"
          :prop="'feeDiscountRuleSpecs.' + index + '.specValue'" :rules="{
7505cb92   wuxw   开发完成折扣设置
25
            required: true,
76d4c8fc   wuxw   优惠需要申请测试中
26
            message: $t('feeDiscountManage.edit.specValueRequired', { specName: item.specName }),
7505cb92   wuxw   开发完成折扣设置
27
            trigger: 'blur'
76d4c8fc   wuxw   优惠需要申请测试中
28
29
          }">
          <el-input v-model.trim="item.specValue" type="number" :placeholder="item.remark" />
7505cb92   wuxw   开发完成折扣设置
30
31
        </el-form-item>
        <el-form-item :label="$t('feeDiscountManage.edit.discountDesc')">
76d4c8fc   wuxw   优惠需要申请测试中
32
33
          <el-input v-model.trim="editFeeDiscountInfo.discountDesc" type="textarea"
            :placeholder="$t('feeDiscountManage.edit.discountDescPlaceholder')" :rows="3" />
7505cb92   wuxw   开发完成折扣设置
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
        </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="editFeeDiscount">
          {{ $t('common.save') }}
        </el-button>
      </span>
    </el-dialog>
  </template>
  
  <script>
  import { getDict } from '@/api/community/communityApi'
  import { updateFeeDiscount, queryFeeDiscountRule } from '@/api/fee/feeDiscountManageApi'
  import { getCommunityId } from '@/api/community/communityApi'
  
  export default {
    name: 'EditFeeDiscount',
    data() {
      return {
        visible: false,
        editFeeDiscountInfo: {
          discountId: '',
          discountName: '',
          discountType: '',
          discountTypes: [],
          ruleId: '',
          discountDesc: '',
          rules: [],
          feeDiscountRuleSpecs: [],
          communityId: ''
        },
        rules: {
          discountName: [
            { required: true, message: this.$t('feeDiscountManage.edit.discountNameRequired'), trigger: 'blur' },
            { max: 256, message: this.$t('feeDiscountManage.edit.discountNameMaxLength'), trigger: 'blur' }
          ],
          discountType: [
            { required: true, message: this.$t('feeDiscountManage.edit.discountTypeRequired'), trigger: 'change' }
          ],
          ruleId: [
            { required: true, message: this.$t('feeDiscountManage.edit.ruleRequired'), trigger: 'change' }
          ],
          discountId: [
            { required: true, message: this.$t('feeDiscountManage.edit.discountIdRequired'), trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      open(row) {
        this.visible = true
        this.getCommunityId()
        this.getDictData()
        this.$nextTick(() => {
          this.editFeeDiscountInfo = {
            ...row,
            discountTypes: this.editFeeDiscountInfo.discountTypes,
            rules: this.editFeeDiscountInfo.rules,
            feeDiscountRuleSpecs: row.feeDiscountSpecs || [],
            communityId: this.editFeeDiscountInfo.communityId
          }
        })
      },
      async getCommunityId() {
        try {
          const communityId = await getCommunityId()
          this.editFeeDiscountInfo.communityId = communityId
        } catch (error) {
          console.error('获取communityId失败:', error)
        }
      },
      async getDictData() {
        try {
          const data = await getDict('fee_discount', 'discount_type')
          this.editFeeDiscountInfo.discountTypes = data
        } catch (error) {
          console.error('获取字典数据失败:', error)
        }
      },
      async _loadEditFeeDiscountRules() {
        if (!this.editFeeDiscountInfo.discountType) return
76d4c8fc   wuxw   优惠需要申请测试中
118
  
7505cb92   wuxw   开发完成折扣设置
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
        try {
          const params = {
            page: 1,
            row: 100,
            discountType: this.editFeeDiscountInfo.discountType
          }
          const { data } = await queryFeeDiscountRule(params)
          this.editFeeDiscountInfo.rules = data
        } catch (error) {
          console.error('获取规则列表失败:', error)
        }
      },
      _changeEditFeeDiscountRule() {
        const selectedRule = this.editFeeDiscountInfo.rules.find(
          item => item.ruleId === this.editFeeDiscountInfo.ruleId
        )
        if (selectedRule) {
          this.editFeeDiscountInfo.feeDiscountRuleSpecs = selectedRule.feeDiscountRuleSpecs.map(item => ({
            ...item,
            specValue: ''
          }))
        }
      },
      _changeEditFeeDiscountType() {
        this.editFeeDiscountInfo.ruleId = ''
        this.editFeeDiscountInfo.feeDiscountRuleSpecs = []
        this._loadEditFeeDiscountRules()
      },
      async editFeeDiscount() {
        this.$refs.form.validate(async valid => {
          if (!valid) return
76d4c8fc   wuxw   优惠需要申请测试中
150
  
7505cb92   wuxw   开发完成折扣设置
151
152
          try {
            await updateFeeDiscount(this.editFeeDiscountInfo)
6ec243d6   wuxw   v1.9 点击提交后,成功提示没有...
153
            this.$message.success(this.$t('common.operationSuccess'))
7505cb92   wuxw   开发完成折扣设置
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
            this.$emit('success')
            this.visible = false
            this.resetForm()
          } catch (error) {
            console.error('更新折扣信息失败:', error)
          }
        })
      },
      resetForm() {
        this.$refs.form.resetFields()
        this.editFeeDiscountInfo = {
          discountId: '',
          discountName: '',
          discountType: '',
          discountTypes: this.editFeeDiscountInfo.discountTypes,
          ruleId: '',
          discountDesc: '',
          rules: [],
          feeDiscountRuleSpecs: [],
          communityId: this.editFeeDiscountInfo.communityId
        }
      },
      handleClose() {
        this.resetForm()
      }
    }
  }
  </script>