adjustDialog.vue
9.49 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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
<!-- 积分调整 -->
<template>
<d2-dialog btn-ok-label="提交审核"
class="adjustDialog"
:is-visible.sync="visible"
title="积分调整"
width="640px"
@closeDialog="handleClose"
@confirmDialog="handleConfirm">
<div class="tip-text">
提交审核通过后,积分将自动更新
</div>
<glsx-combi-form ref="editFormRef"
class="edit-form-container"
:default-width="defaultWidth"
:form-data="editFormData"
:form-obj="editData"
:form-ref="editChildRef"
:form-rules="formRules"
:is-block="isBlock"
:label-width="labelWidth">
<template #scoreHtml>
<div class="scroe-wrap">
<el-input v-model="editData.score"
maxlength="9"
placeholder="请输入"
:prefix-icon="prefixIcon"
style="width: 136px;">
</el-input>
</div>
</template>
<template #captcha>
<div class="captcha-wrap">
<el-input v-model="editData.captcha"
placeholder="请输入"
style="width: 338px;">
</el-input>
<div class="captcha-text" @click.prevent="getCode">
{{ !isCodeDisabled ? '获取验证码' : `${count}s` }}
</div>
</div>
</template>
</glsx-combi-form>
</d2-dialog>
</template>
<script>
// import { limitPrice } from "@/common/format";
import { getAdmin, getSms, manualAdd, manualSubtract } from "@/api/point";
import { deepClone, Util } from "@/common/util";
export default {
name: "AdjustDialog",
props: {
visible: {
type: Boolean,
default: false,
},
infoData: {
type: Object,
default: () => {},
},
},
data() {
return {
prefixIcon: "el-icon-plus",
labelWidth: "110px",
editChildRef: "editChildRef",
isBlock: true,
defaultWidth: "338px",
isCodeDisabled: false,
count: "",
timer: null,
editData: {
type: 1,
score: "",
captcha: "",
phone: "",
orderCode: "",
admin: "",
},
editFormData: [
{
label: "积分变更",
name: "type",
type: "radio",
optionList: [],
optionId: "confId",
optionLabel: "confValue",
optionsName: "pointChangeOpt",
handleRadioChange: (val) => {
this.prefixIcon = val === 1 ? "el-icon-plus" : "el-icon-minus";
},
},
{
label: "",
name: "score",
maxlength: 9,
addHtml: "scoreHtml",
style: {
marginLeft: "110px",
},
},
{
label: "关联订单编号",
name: "orderCode",
type: "input",
maxlength: "30",
placeholder: "请输入",
isClear: true,
},
{
label: "管理员",
name: "admin",
type: "select",
optionsName: "adminList",
optionId: "adminId",
optionLabel: "adminName",
changeAttr: (val) => {
this.editData.phone = val;
this.isCodeDisabled = false;
clearInterval(this.timer);
this.timer = null;
this.editData.captcha = "";
},
},
{
label: "验证码",
addHtml: "captcha",
name: "captcha",
},
{
label: "备注",
name: "remark",
type: "input",
inputType: "textarea",
maxlength: "200",
width: "436px",
rows: 4,
showLimit: true,
},
],
formRules: {
orderCode: [{ required: true, message: "请输入关联订单编号", trigger: "blur" }],
score: [
{ required: true, message: "请输入积分", trigger: "blur" },
{
validator(rule, value, callback) {
if (value === "" || value === null || value === undefined) {
callback(new Error("请输入积分"));
return;
}
const str = String(value).trim();
// 仅允许:0 或非0开头的整数,且可选最多两位小数
const pattern = /^(?:0|[1-9]\d*)(?:\.\d{1,2})?$/;
if (!pattern.test(str)) {
callback(new Error("积分必须为非负数,最多保留两位小数"));
return;
}
const num = Number(str);
if (!isFinite(num) || num < 0) {
callback(new Error("积分必须为非负数"));
return;
}
callback();
},
trigger: ["blur", "change"],
},
],
captcha: [{ required: true, message: "请输入验证码", trigger: "blur" }, {
validator(rule, value, callback) {
const str = String(value || "").trim();
if (str === "") {
// 空值交给 required 规则处理
callback();
return;
}
if (!/^\d+$/.test(str)) {
callback(new Error("验证码只能输入数字"));
return;
}
callback();
},
trigger: ["blur", "change"],
}],
admin: [{ required: true, message: "请选择管理员", trigger: "change" }],
remark: [{ required: true, message: "请输入备注", trigger: "blur" }],
},
baseData: {
pointChangeOpt: [
{
confId: 1,
confValue: "积分增加",
},
{
confId: 2,
confValue: "积分减少",
},
],
},
};
},
created() {
this.getAdminData();
},
methods: {
getAdminData() {
getAdmin().then((res) => {
if (res) {
this.baseData.adminList = res.map((item) => {
return {
adminId: `${item.phone}`,
adminName: `${item.name} ${item.phone}`,
name: item.name,
phone: item.phone,
};
});
this.getOptionsList(this, "editFormData", false);
if (this.baseData.adminList.length == 0) {
this.editData.admin = "";
this.editData.phone = "";
} else {
this.editData.admin = this.baseData.adminList[0].adminId;
this.editData.phone = this.baseData.adminList[0].phone;
}
}
});
},
getCode() {
if (!this.editData.phone) {
this.$message.error("请选择管理员");
return;
}
if (this.isCodeDisabled)
return;
if (!this.timer) {
this.count = 60;
getSms({
phone: this.editData.phone,
})
.then((res) => {
console.log(res, "res");
if (res) {
this.$message.success("短信验证码发送成功");
this.isCodeDisabled = true;
this.timer = setInterval(() => {
if (this.count > 0 && this.count <= 60) {
this.count--;
} else {
this.isCodeDisabled = false;
clearInterval(this.timer);
this.timer = null;
}
}, 1000);
} else {
this.$message.error(res.message);
}
});
}
},
handleConfirm() {
this.$refs.editFormRef.$refs[this.editChildRef].validate((valid1) => {
console.log(valid1);
if (valid1) {
let Methods = this.editData.type === 1 ? manualAdd : manualSubtract;
let params = {
phone: this.editData.phone,
score: this.editData.score,
orderCode: this.editData.orderCode,
remark: this.editData.remark,
captcha: this.editData.captcha,
merchantId: this.infoData.merchantId,
staffPhone: this.infoData.staffPhone,
};
Methods(params).then((res) => {
if (res) {
this.$message.success("积分调整成功");
this.$emit("handleConfirm");
}
});
}
});
},
handleClose() {
this.$emit("handleClose");
},
getOptionsList(that, formName, hasAll = true, refreshSigle) {
if (refreshSigle) {
let item = that[formName].find(k => k.name == refreshSigle);
let index = that[formName].findIndex(k => k.name == refreshSigle);
that.$set(
that[formName][index],
"optionList",
deepClone(that.baseData[item.optionsName]),
);
if (
hasAll
&& that.baseData[item.optionsName].length
&& that.baseData[item.optionsName][0][
that[formName][index].optionLabel
] !== "全部"
) {
const temp = {};
temp[that[formName][index].optionId] = "";
temp[that[formName][index].optionLabel] = "全部";
that[formName][index].optionList.unshift(temp);
}
} else {
that[formName].forEach((item, index) => {
if (
that.baseData[item.optionsName]?.length
) {
that.$set(
that[formName][index],
"optionList",
deepClone(that.baseData[item.optionsName]),
);
if (
hasAll
&& that.baseData[item.optionsName].length
&& that.baseData[item.optionsName][0][
that[formName][index].optionLabel
] !== "全部"
) {
const temp = {};
temp[that[formName][index].optionId] = "";
temp[that[formName][index].optionLabel] = "全部";
that[formName][index].optionList.unshift(temp);
}
}
});
}
},
},
};
</script>
<style scoped lang="scss">
.adjustDialog {
::v-deep {
.el-dialog__header {
border-bottom: 1px solid #e5e5e5;
}
.el-dialog__footer {
border-top: 1px solid #e5e5e5;
}
.el-input__count {
right: 12px;
bottom: 1px;
}
}
}
.tip-text {
border-radius: 4px;
background: #f7f7f7;
color: #333333;
font-size: 14px;
padding: 8px 0;
text-align: center;
margin-bottom: 26px;
margin-top: -10px;
}
.captcha-wrap {
.captcha-text {
font-size: 12px;
color: #2a58ad;
position: absolute;
right: 0;
top: 2px;
margin-right: 10px;
cursor: pointer;
width: 100px;
height: 32px;
text-align: right;
}
}
</style>