configuration.vue
7.41 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<template>
<div style="padding: 10px;background-color:#F2F3F5">
<div class="integralPage">
<div style="height:58px;line-height:58px;">
<div style="color:#0006"> <span>积分管理</span> <span style="padding:0 5px;">></span> <span style="color:#000000e6">积分配置</span></div>
</div>
<div class="configuration">
<el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="240px" class="demo-ruleForm">
<el-form-item label="积分" prop="switch">
<el-radio-group v-model="ruleForm.switch" @change="updateConfig('credit_switch', ruleForm.switch)">
<el-radio label="1">开启</el-radio>
<el-radio label="0">关闭</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="下单后每1元赠送多少积分给客户" prop="proportion">
<el-input v-model.number="ruleForm.proportion" type="number" @blur="updateConfig('credit_order_rate', ruleForm.proportion)" />
</el-form-item>
<el-form-item label="满足多少元可以抵扣积分" prop="deduction">
<el-input v-model="ruleForm.deduction" @blur="updateConfig('credit_order_amount_threshold', ruleForm.deduction)" />
</el-form-item>
<el-form-item label="积分抵扣金额比例" prop="priceNum" class="priceNum">
<el-input v-model="ruleForm.priceNum" @blur="updateConfig('credit_exchange_rate', ruleForm.priceNum)" />
<span>1积分可抵扣多少额度</span>
</el-form-item>
<el-form-item label="每笔订单最多抵扣多少积分" prop="priceNum">
<el-input v-model="ruleForm.integralNum" @blur="updateConfig('credit_deduct_limit', ruleForm.integralNum)" />
</el-form-item>
</el-form>
</div>
</div>
</div>
</template>
<script>
import { dictGetChilds, dictUpdate } from '@/api/setup'
export default {
data () {
// 积分比例校验规则
const checkIntegralProportion = (rule, value, callback) => {
const reg = /^[0-9]*[1-9][0-9]*$/
if (!value || (value > 10000 || value < 1) || !reg.test(value)) {
return callback(new Error('请输入1-10000之间的整数'))
} else {
callback()
}
}
// 满多少抵扣
const checkFullMinus = (rule, value, callback) => {
if (!value) {
return callback(new Error('请输入满多少可以抵扣!'))
} else if (!Number(value)) {
return callback(new Error('请输入正确的数值!'))
} else {
callback()
}
}
// 积分支付比例
const checkProportion = (rule, value, callback) => {
if (!value) {
return callback(new Error('请输入积分支付金额比例!'))
} else if (!Number(value)) {
return callback(new Error('请输入正确的数值!'))
} else {
callback()
}
}
// 最高使用积分
const checkHighestUsed = (rule, value, callback) => {
if (!value) {
return callback(new Error('请输入每笔订单最多抵扣多少积分!'))
} else if (!Number(value)) {
return callback(new Error('请输入正确的数值!'))
} else {
callback()
}
}
return {
ruleForm: {
proportion: '',
deduction: '',
switch: '',
priceNum: '',
integralNum: ''
},
addForm: {
createTime: '',
dictDescribe: '',
dictId: '',
dictName: '',
dictPid: 1900,
updateTime: ''
},
oldData: {
proportion: '',
deduction: '',
switch: '',
priceNum: '',
integralNum: ''
},
sonInline: {
dictPid: '1900',
page: 1,
pageSize: 10
},
dictList: [],
rules: {
proportion: [
{ required: true, validator: checkIntegralProportion, trigger: 'blur' },
],
deduction: [
{ required: true, validator: checkFullMinus, trigger: 'blur' },
],
priceNum: [
{ required: true, validator: checkProportion, trigger: 'blur' },
],
integralNum: [
{ required: true, validator: checkHighestUsed, trigger: 'blur' },
],
switch: [
{ required: true, message: '请选择积分是否开关', trigger: 'change' }
]
}
}
},
created () {
},
mounted () {
this.getInfo()
},
methods: {
updateConfig (dictName, value) {
this.$refs.ruleForm.validate(valid => {
if (valid) {
if (value !== '') {
for (let i = 0; i < this.dictList.length; i++) {
if (this.dictList[i].dictName === dictName) {
this.addForm.dictId = this.dictList[i].dictId
break
}
}
if (dictName === 'credit_order_rate') {
if (this.ruleForm.proportion !== this.oldData.proportion) {
this.changeFn(dictName, value)
}
} else if (dictName === 'credit_order_amount_threshold') {
if (this.ruleForm.deduction !== this.oldData.deduction) {
this.changeFn(dictName, value)
}
} else if (dictName === 'credit_switch') {
this.changeFn(dictName, value)
} else if (dictName === 'credit_exchange_rate') {
if (this.ruleForm.priceNum !== this.oldData.priceNum) {
this.changeFn(dictName, value)
}
} else if (dictName === 'credit_deduct_limit') {
if (this.ruleForm.integralNum !== this.oldData.integralNum) {
this.changeFn(dictName, value)
}
}
}
}
})
},
changeFn (dictName, value) {
this.addForm.dictName = dictName
this.addForm.dictDescribe = value
dictUpdate(this.addForm).then(res => {
console.log(res)
if (res.code === '') {
this.$message({
message: '修改成功',
type: 'success'
})
this.getInfo()
}
})
},
// 初始化查询所有数据
getInfo () {
dictGetChilds(this.sonInline).then(res => {
this.dictList = res.data.list
this.dictList.forEach((item) => {
if (item.dictName === 'credit_switch') {
this.ruleForm.switch = item.dictDescribe
this.oldData.switch = item.dictDescribe
}
if (item.dictName === 'credit_order_amount_threshold') {
this.ruleForm.deduction = item.dictDescribe
this.oldData.deduction = item.dictDescribe
}
if (item.dictName === 'credit_order_rate') {
this.ruleForm.proportion = item.dictDescribe
this.oldData.proportion = item.dictDescribe
}
if (item.dictName === 'credit_exchange_rate') {
this.ruleForm.priceNum = item.dictDescribe
this.oldData.priceNum = item.dictDescribe
}
if (item.dictName === 'credit_deduct_limit') {
this.ruleForm.integralNum = item.dictDescribe
this.oldData.integralNum = item.dictDescribe
}
})
})
},
},
}
</script>
<style lang="scss" scpoed>
.integralPage {
padding: 0 20px 20px 20px;
min-height: calc(100vh - 50px - 20px);
background-color: #Fff;
.configuration {
width: 600px;
}
.integralBox {
span {
color: #999999;
font-size: 14px;
}
}
}
</style>