InfoVerifyMerchantDialog.vue
15.3 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
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
<template>
<d2-dialog :title="dialogTitle" class="info-verify-merchant-dialog" :width="dialogWidth" :append-to-body="true"
:is-visible="dialogVisible" @closeDialog="closeDialog" @confirmDialog="handleConfirm">
<div v-loading="loading" class="dialog-body-inner">
<div v-if="$scopedSlots.storeDetail">
<slot name="storeDetail" :customer-row="customerRow" />
</div>
<div class="merchant-form-section-title">新建商户</div>
<glsx-combi-form ref="editFormRef" class="info-verify-form" default-width="205px" :is-edit="true"
:form-data="editFormData" :form-obj="editData" :form-ref="editChildRef" :form-rules="formRules"
:is-block="isBlock" label-width="120px">
<template #parentId="scope">
<div class="parent-select-wrap">
<el-select v-model="editData[scope.scope.name]" v-el-select-loadmore="interestsLoadmoreMerchant"
v-loading="merchantLoading" filterable :placeholder="scope.scope.placeholder || '请选择'" remote
:remote-method="(event) => remoteMethod(event, scope.scope.searchKey, 'store')" style="width: 205px"
@change="scope.scope.changeAttr($event, scope.scope)"
@visible-change="(event) => selectVisibleChange(event, scope.scope)">
<el-option v-for="subItem in scope.scope.optionList" :key="subItem[scope.scope.optionId]"
:label="subItem[scope.scope.optionLabel]" :value="subItem[scope.scope.optionId]" />
</el-select>
</div>
</template>
<template #provinceCity>
<div class="province-city-slot">
<ProvinceCity ref="provinceForm" embed-mode :embed-select-width="100"
:detail-address-label="detailAddressLabel" province-label="商户地址:" :subdistrict="subdistrict"
@selectAddressByMap="selectAddressByMap" @selectCity="selectCity" @selectProvince="selectProvince"
@selectTown="selectTown" @merchant-address-part-blur="validateMerchantAddressOnBlur" />
</div>
</template>
<template #selectBrand>
<div class="brand-select-slot">
<SelectBrand ref="brandListTree" :brand-list-tree="brandListTree" @clickBrand="clickBrand"
@brand-change="onBrandFieldChange" />
</div>
</template>
</glsx-combi-form>
</div>
</d2-dialog>
</template>
<script>
import ProvinceCity from "@/components/province-city/index.vue";
import SelectBrand from "@/components/SelectBrand/index.vue";
import merchantVerifyFormMixin from "./merchantVerifyFormMixin";
import util from "@/libs/util";
import { pickCoordDisplayString as pickCoordString } from "./merchantVerifyDisplay";
import {
showMerchantCreateSuccess,
showMerchantSubmitConfirm,
} from "./merchantVerifyDialogs";
/** 表单 id 字段转 number;空不传 */
function submitNumber(val) {
if (val === "" || val === null || val === undefined) return undefined;
const n = typeof val === "number" && Number.isFinite(val) ? val : parseInt(val, 10);
return Number.isNaN(n) ? undefined : n;
}
/** 提交流:统一转成字符串(行政区划 code 在表单里可能是 number) */
function submitStringField(val) {
return String(val ?? "").trim();
}
/**
* merchantBrandList[].cars(integer 车系 id)、
* merchantBrandList[].merchantBrandId(integer[] 二级车品牌 id)
*/
function normalizeMerchantBrandListForSubmit(list) {
if (!Array.isArray(list) || !list.length) return [];
return list
.map((row) => {
const cars = parseInt(row.cars, 10);
const merchantBrandId = Array.isArray(row.merchantBrandId)
? row.merchantBrandId
.map((id) => parseInt(id, 10))
.filter((n) => !Number.isNaN(n))
: [];
return { cars, merchantBrandId };
})
.filter((row) => !Number.isNaN(row.cars));
}
export default {
name: "InfoVerifyMerchantDialog",
components: {
ProvinceCity,
SelectBrand,
},
mixins: [merchantVerifyFormMixin],
props: {
visible: {
type: Boolean,
default: false,
},
submitApi: {
type: Function,
required: true,
},
/** 弹窗标题(客户列表信息核验传「信息核验」,默认「新增」) */
dialogTitle: {
type: String,
default: "新增",
},
dialogWidth: {
type: String,
default: "980px",
},
customerRow: {
type: Object,
default: null,
},
/** 商户类型选项(字典 label),如客户信息核验仅 4S:['4S店'];园区店/服务商新增:['园区店'];不传则三种都展示 */
merchantTypeLabels: {
type: Array,
default: null,
},
},
computed: {
dialogVisible: {
get() {
return this.visible;
},
set(v) {
this.$emit("update:visible", v);
},
},
},
watch: {
visible(val) {
if (val) {
this.$nextTick(() => {
this.onDialogOpened();
});
} else {
this.onDialogClose();
}
},
},
mounted() {
if (this.visible) {
this.$nextTick(() => {
this.onDialogOpened();
});
}
},
created() {
this.debouncedOnBrandFieldChange = util.debounce(() => {
this.syncMerchantBrandSlotPlaceholder();
// 避免 getCheckList 初始化等在未展开品牌区时就标红;展开后 isFirstBrand 为 true 再即时校验
if (this.isFirstBrand) {
this.$refs.editFormRef?.$refs[this.editChildRef]?.validateField(
"merchantBrandSlot"
);
}
}, 120);
},
beforeDestroy() {
if (
this.debouncedOnBrandFieldChange &&
typeof this.debouncedOnBrandFieldChange.cancel === "function"
) {
this.debouncedOnBrandFieldChange.cancel();
}
},
methods: {
async onDialogOpened() {
this.resetMerchantVerifyForm();
await this.initMerchantVerifyForm();
this.$nextTick(() => {
this.$refs.editFormRef?.$refs[this.editChildRef]?.clearValidate();
});
},
onDialogClose() {
if (
this.debouncedOnBrandFieldChange &&
typeof this.debouncedOnBrandFieldChange.cancel === "function"
) {
this.debouncedOnBrandFieldChange.cancel();
}
this.resetMerchantVerifyForm();
},
closeDialog() {
this.dialogVisible = false;
},
onBrandFieldChange() {
this.debouncedOnBrandFieldChange();
},
/**
* 组装信息核验提交请求体(与货架 AddMerchant.saveMerchant 字段对齐)。
*/
buildSubmitVerificationPayload(merchantBrandList) {
const d = this.editData;
const payload = {};
payload.contactPhone = submitStringField(d.contactPhone);
payload.loginAccount = submitStringField(d.loginAccount);
payload.loginPassword = submitStringField(d.loginPassword);
const contactTrim = submitStringField(d.contactName);
if (contactTrim) payload.contactName = contactTrim;
const nameTrim = submitStringField(d.merchantName);
if (nameTrim) payload.merchantName = nameTrim;
const lngStr = pickCoordString(d.lng, d.longitude);
const latStr = pickCoordString(d.lat, d.latitude);
if (lngStr) payload.longitude = lngStr;
if (latStr) payload.latitude = latStr;
const pc = submitStringField(d.provinceCode);
if (pc) payload.provinceCode = pc;
const pn = submitStringField(d.provinceName);
if (pn) payload.provinceName = pn;
const cc = submitStringField(d.cityCode);
if (cc) payload.cityCode = cc;
const cn = submitStringField(d.cityName);
if (cn) payload.cityName = cn;
const dc = submitStringField(d.districtCode);
if (dc) payload.districtCode = dc;
const dn = submitStringField(d.districtName);
if (dn) payload.districtName = dn;
const addrTrim = submitStringField(d.detailAddress);
if (addrTrim) {
payload.merchantAddress = addrTrim;
payload.detailAddress = addrTrim;
}
const mal = submitNumber(d.merchantAccountLevel);
if (mal !== undefined) payload.merchantAccountLevel = mal;
const chId = submitNumber(d.channelId);
if (chId !== undefined) payload.channelId = chId;
const accessModeId = submitNumber(d.merchantModel);
if (accessModeId !== undefined) {
payload.accessModeId = accessModeId;
payload.merchantModel = accessModeId;
}
const yqNo = submitNumber(
d.yqMerchantNo ?? this.customerRow?.yqMerchantNo
);
if (yqNo !== undefined) payload.yqMerchantNo = yqNo;
const merchantTypeNum = submitNumber(d.accounttypeId);
if (merchantTypeNum !== undefined) payload.merchantType = merchantTypeNum;
const parentMerchantId = submitNumber(d.parentId);
if (parentMerchantId !== undefined) {
payload.parentMerchantId = parentMerchantId;
payload.parentId = parentMerchantId;
const parentRow = this.baseData.parentMerchantList.find(
(p) => String(p.id) === String(d.parentId)
);
const parentNo = submitNumber(parentRow?.merchantNo);
if (parentNo !== undefined) payload.parentMerchantNo = parentNo;
}
if (this.customerRow != null && this.customerRow.id != null && this.customerRow.id !== "") {
const pid = submitNumber(this.customerRow.id);
if (pid !== undefined) payload.id = pid;
}
const normalizedBrandList =
normalizeMerchantBrandListForSubmit(merchantBrandList);
payload.merchantBrandList = normalizedBrandList;
payload.status = 2;
payload.isloginName = 0;
payload.source = "DJ";
const createdByTrim = submitStringField(
this.$store.state.d2admin.user?.info?.detail?.userName
);
if (createdByTrim) payload.createdBy = createdByTrim;
return payload;
},
async handleConfirm() {
const formRef = this.$refs.editFormRef?.$refs[this.editChildRef];
if (!formRef) return;
this.syncMerchantBrandSlotPlaceholder();
formRef.validate(async (valid) => {
if (!valid) {
return;
}
const merchantBrandList = this.$refs.brandListTree.getMerchantBrandList();
if (!merchantBrandList?.length) {
this.$message({
message: "请选择主营品牌",
type: "error",
});
return;
}
try {
await showMerchantSubmitConfirm(this);
} catch {
return;
}
this.syncEditDataRegionFromProvinceCityRef();
const params = this.buildSubmitVerificationPayload(
merchantBrandList
);
this.loading = true;
try {
await Promise.resolve(this.submitApi(params));
await showMerchantCreateSuccess(this);
this.$emit("success");
this.closeDialog();
} catch (e) {
/* 接口失败由全局封装提示,此处不再弹成功框 */
} finally {
this.loading = false;
}
});
},
},
};
</script>
<style lang="scss" scoped>
// 勿强制 el-form-item 宽度:与 Element inline + label-width 叠加会产生巨大空隙与红星错位
// 表单内容区占位插槽例外(省市区/主营品牌用各自宽度)
$slot-exclude: ":not(.province-city-slot):not(.brand-select-slot)";
.dialog-body-inner {
min-height: 120px;
max-height: 70vh;
overflow-y: auto;
>.merchant-form-section-title:not(:first-child) {
margin-top: 16px;
}
}
// 与潜客「门店详情」分区标题(PotentialCustomerStoreDetailSection .title)一致
.merchant-form-section-title {
width: 100%;
height: 50px;
line-height: 50px;
font-size: 16px;
font-weight: bold;
color: #333333;
margin-bottom: 16px;
border-bottom: 1px solid #e5e5e5;
}
.province-city-slot,
.brand-select-slot,
.parent-select-wrap {
width: 100%;
}
:v-deep.info-verify-merchant-dialog {
.el-dialog {
margin-top: 8vh !important;
}
.el-dialog__header {
padding: 16px 20px;
border-bottom: 1px solid #e5e5e5;
}
.el-dialog__title {
font-size: 16px;
font-weight: 600;
color: #333;
}
.el-dialog__body {
padding: 20px 24px 8px;
}
.info-verify-form {
&.glsx-combi-form {
.glsx-combi-form-block {
display: flex;
flex-wrap: wrap;
align-items: flex-start;
margin-right: 0;
>.el-form-item .el-form-item__content>div#{$slot-exclude} {
width: auto;
box-sizing: border-box;
.el-select,
.el-input {
width: 205px !important;
max-width: 205px;
box-sizing: border-box;
}
}
}
// 主营品牌:抵消 glsx-combi-form 全局 .el-tag--info
.brand-select-slot .el-tag.el-tag--info .el-tag__close {
color: #909399;
}
.brand-select-slot .el-tag--plain.el-tag--info .el-tag__close:hover,
.brand-select-slot .el-tag.el-tag--info .el-tag__close:hover {
color: #909399;
background-color: #c6cacd;
}
}
.el-form-item--small.el-form-item {
margin-right: 0;
margin-bottom: 16px;
vertical-align: top;
}
.isBlock {
display: inline-block !important;
}
.combi-form-label {
white-space: nowrap;
}
// 商户地址:外层表单项 flex,省份与上行控件左缘对齐
#detailAddress {
&.el-form-item {
display: flex !important;
align-items: flex-start;
width: 100% !important;
box-sizing: border-box;
}
.el-form-item__label {
flex: 0 0 120px !important;
width: 120px !important;
max-width: 120px !important;
box-sizing: border-box;
}
.el-form-item__content {
flex: 1 !important;
min-width: 0 !important;
max-width: 100% !important;
width: auto !important;
margin-left: 0 !important;
padding-left: 0 !important;
box-sizing: border-box;
}
}
}
.province-city-slot {
>div {
width: 100%;
min-width: 0;
}
.province-city--embed {
&.el-form {
display: flex;
flex-wrap: nowrap;
align-items: center;
gap: 8px;
width: 100%;
min-width: 0;
overflow-x: auto;
overflow-y: visible;
}
.el-form-item {
margin-bottom: 0 !important;
display: flex;
align-items: center;
>.el-form-item__label {
display: none !important;
width: 0 !important;
min-width: 0 !important;
padding: 0 !important;
margin: 0 !important;
}
>.el-form-item__content {
margin-left: 0 !important;
padding-left: 0 !important;
max-width: none !important;
}
&:first-child {
flex: 0 0 auto;
max-width: 100%;
>.el-form-item__content {
display: flex;
flex-wrap: nowrap;
gap: 8px;
align-items: center;
width: auto !important;
}
}
&:nth-child(2) {
flex: 1 1 200px;
min-width: 0;
>.el-form-item__content {
flex: 1;
width: auto !important;
min-width: 0;
max-width: 100%;
}
}
}
.map-input {
margin-top: 0;
width: 100%;
min-width: 0;
}
}
}
}
</style>
<style lang="scss">
@import "./merchantSubmitMsgbox.scss";
/* MessageBox 挂载在 document.body,不能使用 scoped。
* 不使用 Element「居中模式」(center:true):标题左上、按钮右对齐与站内常规提示一致;
* 正文区单独居中叠放图标与文案(与同流程其它提示样式对齐)。 */
.el-message-box.potential-customers-merchant-name-dup-msgbox {
width: 440px;
padding-bottom: 0px;
.el-message-box__header {
padding: 12px 16px;
border-bottom: 1px solid #ebeef5;
}
.el-message-box__title {
font-size: 16px;
font-weight: 600;
color: #303133;
text-align: left;
}
.el-message-box__content {
padding: 24px 24px;
}
.el-message-box__container {
display: flex;
flex-direction: column;
align-items: center;
padding-left: 0 !important;
}
.el-message-box__btns {
padding: 12px 16px;
border-top: 1px solid #ebeef5;
text-align: right;
.el-button {
padding: 8px 18px;
min-height: 32px;
line-height: 1;
}
}
.el-message-box__status {
position: static !important;
top: auto !important;
transform: none !important;
display: block;
margin: 0 auto 16px;
font-size: 56px !important;
padding-right: 0;
text-align: center;
+.el-message-box__message {
padding-left: 0 !important;
padding-right: 0 !important;
}
}
.el-message-box__message {
margin: 0;
padding: 0;
width: 100%;
text-align: center;
line-height: 22px;
font-size: 14px;
color: #606266;
}
}
</style>