changePhoneDialog.vue
12.5 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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
<!-- 更换手机号 -->
<template>
<d2-dialog btn-ok-label="提交"
class="phoneDialog"
:is-visible.sync="visible"
title="更换手机号"
width="1140px"
@closeDialog="handleClose"
@confirmDialog="handleConfirm">
<div class="tip-text">
提交审核通过后,原手机号剩余积分将全部转移至新手机号
</div>
<div class="staff-info">
<img src="@/assets/personnel.png" />
{{ dataInfo.staffName }}
</div>
<el-form :inline="true" label-width="166px">
<el-form-item label="原门店名称:">
<div class="info">
{{ dataInfo.merchantName }}
</div>
</el-form-item>
<el-form-item label="原手机号:">
<div class="info">
{{ dataInfo.staffPhone }}
</div>
</el-form-item>
</el-form>
<glsx-combi-form ref="formRef"
class="edit-form-container"
:default-width="defaultWidth"
:form-data="formData"
:form-obj="editData"
:form-ref="editChildRef1"
:form-rules="formRules"
:is-block="isBlock"
:label-width="labelWidth">
</glsx-combi-form>
<div class="line"></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 #captcha>
<div class="captcha-wrap">
<el-input v-model="editData.captcha"
placeholder="请输入"
style="width: 358px;">
</el-input>
<div class="captcha-text" @click.prevent="getCode">
{{ !isCodeDisabled ? '获取验证码' : `${count}s` }}
</div>
</div>
</template>
</glsx-combi-form>
<div v-if="recordList && recordList.length > 0" class="record-wrap">
<div class="record-title">
操作记录
</div>
<div class="record-list">
<div v-for="item in recordList"
:key="item.id || `${item.operatedAt}-${item.oldPhone}-${item.newPhone}`"
class="record-item">
<span> <i class="dot"></i>原手机号:{{ item.sourceStaffPhone }}</span>
<span>新手机号:{{ item.targetStaffPhone }}</span>
<span>操作人:{{ item.operator }}</span>
<span>操作时间:{{ item.operateTime }}</span>
</div>
</div>
</div>
</d2-dialog>
</template>
<script>
import { changePhone, changePhoneRecord, getAdmin, getShopMerchantList, getSms } from "@/api/point";
import { deepClone, Util } from "@/common/util";
// import { limitPrice } from "@/common/format";
export default {
name: "PhoneDialog",
props: {
visible: {
type: Boolean,
default: false,
},
dataInfo: {
type: Object,
default: () => {},
},
},
data() {
return {
labelWidth: "154px",
editChildRef1: "editChildRef1",
editChildRef: "editChildRef",
isBlock: false,
defaultWidth: "358px",
isCodeDisabled: false,
count: "",
timer: null,
editData: {
sourceStaffPhone: "",
targetStaffPhone: "",
sourceMerchantId: "",
targetMerchantId: "",
admin: "",
phone: "",
captcha: "",
},
formData: [
{
label: "新门店名称",
name: "targetMerchantId",
type: "select",
optionsName: "merchantList",
optionId: "merchantId",
optionLabel: "merchantName",
changeAttr: (val) => {
},
},
{
label: "新手机号",
name: "targetStaffPhone",
maxlength: 11,
type: "input",
},
],
editFormData: [
{
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",
},
],
formRules: {
targetMerchantId: [{ required: true, message: "请选择新门店名称", trigger: "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" }],
targetStaffPhone: [
{ required: true, message: "请输入新手机号", trigger: "blur" },
{
validator(rule, value, callback) {
const str = String(value || "").trim();
if (!/^\d{11}$/.test(str)) {
callback(new Error("请输入11位数字手机号"));
return;
}
callback();
},
trigger: ["blur", "change"],
},
],
},
recordList: [],
baseData: {
adminList: [],
merchantList: [],
},
};
},
created() {
this.getAdminData();
this.getShopMerchantList();
},
mounted() {
this.getChangePhoneRecord();
},
methods: {
getChangePhoneRecord() {
changePhoneRecord({
searchStaffPhone: this.dataInfo.staffPhone,
}).then((res) => {
res.list && res.list.length > 0 && (res.list.forEach((item) => {
item.operateTime = Util.dateFormate(item.operateTime, "YYYY-MM-DD HH:mm:ss");
}));
this.recordList = res.list;
});
},
getShopMerchantList() {
getShopMerchantList({}).then((res) => {
this.baseData.merchantList = res;
this.getOptionsList(this, "formData", false);
});
},
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) => {
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() {
const formA = this.$refs.editFormRef?.$refs?.[this.editChildRef];
const formB = this.$refs.formRef?.$refs?.[this.editChildRef1];
const validateForm = (formRef) => {
return new Promise((resolve, reject) => {
if (!formRef || !formRef.validate) {
resolve(true);
return;
}
try {
formRef.validate((valid) => {
valid ? resolve(true) : reject("表单校验未通过");
});
} catch (e) {
const p = formRef.validate();
if (p && typeof p.then === "function") {
p.then(() => resolve(true)).catch(err => reject(err));
} else {
reject(e);
}
}
});
};
Promise.all([validateForm(formA), validateForm(formB)])
.then(() => {
// if (this.dataInfo.staffPhone === this.editData.targetStaffPhone) {
// this.$message.error("新手机号不能与原手机号相同");
// return;
// }
const params = {
sourceStaffPhone: this.dataInfo.staffPhone,
targetStaffPhone: this.editData.targetStaffPhone,
sourceMerchantId: this.dataInfo.merchantId,
targetMerchantId: this.editData.targetMerchantId,
captcha: String(this.editData.captcha || "").trim(),
phone: this.editData.phone,
sourceStaffId: this.dataInfo.staffId,
};
changePhone(params).then((res) => {
if (res) {
this.$message.success("操作成功");
this.$emit("handleConfirm");
}
});
})
.catch(() => {
// this.$message.error("请先修正表单中的错误后再提交");
});
},
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">
.phoneDialog {
::v-deep {
.el-form-item__label {
color: #666666;
font-size: 14px;
}
.info {
width: 365px;
color: #333333;
font-size: 14px;
}
.el-dialog__header {
border-bottom: 1px solid #e5e5e5;
}
.el-dialog__footer {
border-top: 1px solid #e5e5e5;
}
.el-input__count {
right: 12px;
bottom: 1px;
}
.line {
border-top: 1px solid #e5e5e5;
margin-bottom: 20px;
}
}
.staff-info {
color: #333333;
font-size: 16px;
display: flex;
align-items: center;
margin-bottom: 10px;
img {
width: 24px;
height: 24px;
margin-right: 8px;
}
}
.record-wrap {
padding: 20px 0;
.record-title {
color: #333333;
font-size: 16px;
border-bottom: 1px solid #e5e5e5;
padding: 0 0 8px 0;
}
.record-list {
padding: 20px 0;
}
/* 每一条记录行:5列(圆点 + 4列文本) */
.record-list .record-item {
display: flex;
align-items: center;
color: #333333;
font-size: 14px;
white-space: nowrap; /* 保持单行展示 */
margin-bottom: 16px;
span {
min-width: 160px;
display: inline-block;
margin-right: 50px;
}
}
/* 左侧蓝色圆点 */
.record-list > *::before {
content: "";
width: 6px;
height: 6px;
background: #2a58ad;
border-radius: 50%;
display: inline-block;
margin-right: 8px;
}
}
.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>