assignStoreDialog.vue
17.6 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>
<baseDialog :config="config"
:dialog-config="dialogConfig"
:is-show.sync="visible"
@handleClick="handleAddConfirm">
<div class="detail-dialog">
<div class="section-block">
<div class="section-title">
1、选择门店并勾选业务场景,查询关联园区店
</div>
<el-form ref="editFormRef"
label-width="110px"
style="margin-top: 20px;"
:model="infoForm"
:rules="formRules">
<el-form-item label="入职门店:" prop="merchantId">
<el-select v-model="infoForm.merchantId"
placeholder="请选择入职门店"
style="width: 432px"
filterable
reserve-keyword
@change="changeMerchant">
<el-option v-for="(item, index) in merchantList"
:key="index"
:label="item.merchantName"
:value="item.merchantId">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="业务场景:" prop="sceneCodeList">
<template v-if="sceneOptionList.length">
<el-checkbox-group v-model="infoForm.sceneCodeList" @change="changeStaffSceneLabel">
<el-checkbox v-for="item in sceneOptionList"
:key="item.baseSceneCode"
:label="item.baseSceneCode">
{{ item.baseSceneCodeName }}
</el-checkbox>
</el-checkbox-group>
</template>
<span v-else style="color: #999;font-size: 14px;">请选择门店后自动带出场景</span>
<div style="margin-top: 10px;">
<el-button size="small"
type="primary"
:loading="queryLoading"
@click="queryRelatedParkStore">
查询关联园区店
</el-button>
</div>
</el-form-item>
</el-form>
</div>
<div class="section-block" style="margin-top: 20px;">
<div class="section-title">
2、人员上架至门店,请选择对应门店的开单业务场景
</div>
<div v-if="!hasQueried" class="empty-block">
<img src="@/assets/empty.png" style="width: 64px; height: 46px;" />
<div style="color: #999; margin-top: 10px;">
未查询关联园区店
</div>
</div>
<div v-else class="table-container">
<el-table style="width: 100%"
border
:data="tableData"
:span-method="objectSpanMethod">
<el-table-column align="center"
label="园区店"
prop="yqMerchantName"
width="180">
</el-table-column>
<el-table-column align="center"
label="门店名称"
prop="shopMerchantName"
width="220">
</el-table-column>
<el-table-column align="center"
label="开单业务场景(可多选)"
min-width="300">
<template #default="scope">
<el-checkbox-group v-model="scope.row.checkedScenes" @change="changeSceneLabel(scope.row)">
<el-checkbox v-for="scene in scope.row.sceneList"
:key="scene.baseSceneCode"
:label="scene.baseSceneCode">
{{ scene.sceneName }}
</el-checkbox>
</el-checkbox-group>
</template>
</el-table-column>
<el-table-column align="center"
label="驻店类型"
width="250">
<template #default="scope">
<el-radio-group v-model="scope.row.stationType"
:disabled="!scope.row.checkedScenes || scope.row.checkedScenes.length === 0">
<el-radio :label="1">
门店常驻
</el-radio>
<el-radio :label="2">
临时调动支援
</el-radio>
</el-radio-group>
</template>
</el-table-column>
<el-table-column align="center"
label="门店岗位"
min-width="180">
<template #default="scope">
<el-select v-model="scope.row.positionTypeList"
class="position-type-select"
placeholder="请选择门店岗位"
collapse-tags
multiple
:loading="positionTypeLoading">
<el-option v-for="item in positionTypeOptions"
:key="item.itemValue"
:label="item.itemName"
:value="item.itemValue">
</el-option>
</el-select>
</template>
</el-table-column>
</el-table>
</div>
<div class="tips-block">
<div style="display: flex; align-items: flex-start;">
<i class="el-icon-warning"
style="color: #2A58AD; margin-top: 3px; margin-right: 5px; font-size: 16px;">
</i>
<div>
<div style="font-weight: bold;">
提示:
</div>
<div>1. 不勾选某个门店的业务场景,视为该人员未开通该门店的业务权限。</div>
<div>2. 一次性不要超过10个门店的场景分配,避免页面卡顿负载。</div>
</div>
</div>
</div>
</div>
</div>
</baseDialog>
</template>
<script>
import { getDictList, queryLatestBusinessType } from "@api/recruitment";
import { assignStoreV2Api, findAllMerchantPageApi, findAllSceneByMerchantIdApi, query4sByYqMerchantApi } from "@api/resident";
export default {
name: "AssignStoreDialog",
props: {
visibleSync: {
type: Boolean,
default: false,
},
detail: {
type: Object,
default: () => ({}),
},
},
data() {
return {
config: {
showClose: true,
appendToBody: false, // 是否将自身插入至 body 元素,有嵌套的弹窗时一定要设置
isShowFooter: true,
cancel_name: "取消",
confirm_name: "确认分配",
},
dialogConfig: {
title: "新增分配门店",
width: "1180px",
},
infoForm: {
merchantId: "",
merchantName: "",
sceneCodeList: [],
yqMerchantList: [],
},
formRules: {
merchantId: [
{ required: true, message: "请选择入职门店", trigger: ["blur", "change"] },
],
sceneCodeList: [
{ type: "array", required: true, message: "请选择业务场景", trigger: ["blur", "change"] },
],
},
merchantList: [],
sceneOptionList: [],
positionTypeOptions: [],
defaultPositionTypeList: [],
positionTypeLoading: false,
queryLoading: false,
hasQueried: false,
tableData: [],
spanArr: [],
pos: 0,
};
},
computed: {
visible: {
get() {
return this.visibleSync;
},
set(newVal) {
this.$emit("update:visibleSync", newVal);
},
},
},
mounted() {
this.findAllMerchantPage();
this.initPositionType();
const initialMerchantName = this.detail.beisenMerchantName ? this.detail.beisenMerchantName : this.detail.staffBeisenBaseInfoDTO ? this.detail.staffBeisenBaseInfoDTO.merchantName : "";
const initialMerchantId = this.detail.beisenMerchantId ? this.detail.beisenMerchantId : this.detail.staffBeisenBaseInfoDTO ? this.detail.staffBeisenBaseInfoDTO.merchantId : "";
if (initialMerchantName && initialMerchantId) {
this.infoForm.merchantId = initialMerchantId;
this.infoForm.merchantName = initialMerchantName;
this.getSceneList(initialMerchantId);
}
},
methods: {
normalizePositionType(positionType) {
if (Array.isArray(positionType)) {
return positionType.map(item => String(item).trim()).filter(Boolean);
}
if (positionType === null || positionType === undefined || positionType === "") {
return [];
}
return String(positionType).split(/[,,]/).map(item => item.trim()).filter(Boolean);
},
async initPositionType() {
this.positionTypeLoading = true;
try {
const phoneNumber = this.detail.staffPhone;
const [positionTypeRes, businessType] = await Promise.all([
getDictList({
businessCode: "recruitment",
typeCode: "business_type",
}),
phoneNumber ? queryLatestBusinessType({ phoneNumber }) : Promise.resolve(""),
]);
this.positionTypeOptions = (positionTypeRes.list || []).map(item => ({
...item,
itemValue: String(item.itemValue),
}));
this.defaultPositionTypeList = this.normalizePositionType(businessType);
this.tableData.forEach((row) => {
if (!row.positionTypeList.length) {
row.positionTypeList = [...this.defaultPositionTypeList];
}
});
} catch (error) {
console.error(error);
} finally {
this.positionTypeLoading = false;
}
},
changeSceneLabel(row) {
if (row.checkedScenes && row.checkedScenes.length === 0) {
row.stationType = "";
}
},
findAllMerchantPage(query) {
const params = {
currentPage: 1,
pageSize: 99999,
};
findAllMerchantPageApi(params).then((res) => {
this.merchantList = res.list || [];
});
},
changeMerchant(val) {
const selected = this.merchantList.find(item => item.merchantId === val);
this.infoForm.merchantName = selected ? selected.merchantName : "";
this.infoForm.merchantId = selected ? selected.merchantId : "";
this.infoForm.sceneCodeList = [];
this.sceneOptionList = [];
this.hasQueried = false;
this.tableData = [];
if (val) {
this.getSceneList(val);
}
},
getSceneList(merchantId) {
findAllSceneByMerchantIdApi({ merchantId }).then((res) => {
this.sceneOptionList = res || [];
});
},
changeStaffSceneLabel() {
this.hasQueried = false;
this.tableData = [];
},
queryRelatedParkStore() {
this.$refs.editFormRef.validate((valid) => {
if (valid) {
const selectedScenes = this.sceneOptionList.filter(item =>
this.infoForm.sceneCodeList.includes(item.baseSceneCode),
);
const uniqueYqMerchantIds = new Set();
selectedScenes.forEach((scene) => {
if (scene.serviceList && scene.serviceList.length > 0) {
scene.serviceList.forEach((item) => {
uniqueYqMerchantIds.add(item.merchantId);
});
}
});
const yqMerchantIdList = Array.from(uniqueYqMerchantIds);
if (yqMerchantIdList.length === 0) {
this.$message.warning("未找到关联的园区店");
this.hasQueried = true;
this.tableData = [];
return;
}
this.queryLoading = true;
query4sByYqMerchantApi({ yqMerchantIdList }).then((res) => {
this.queryLoading = false;
this.hasQueried = true;
this.formatTableData(res || []);
}).catch(() => {
this.queryLoading = false;
});
} else {
this.$message.warning("请选择业务场景");
this.hasQueried = true;
this.tableData = [];
return;
}
});
},
formatTableData(data) {
const flatData = [];
data.forEach((park) => {
if (park.shopList && park.shopList.length > 0) {
park.shopList.forEach((shop) => {
// 默认勾选所有场景
// const checkedScenes = (shop.sceneList || []).map(s => s.baseSceneCode);
flatData.push({
yqMerchantId: park.yqMerchantId,
yqMerchantName: park.yqMerchantName,
shopMerchantId: shop.shopMerchantId,
shopMerchantName: shop.shopMerchantName,
sceneList: shop.sceneList || [],
checkedScenes: [],
stationType: "",
positionTypeList: [...this.defaultPositionTypeList],
});
});
}
});
this.tableData = flatData;
this.getSpanArr(this.tableData);
},
getSpanArr(data) {
this.spanArr = [];
this.pos = 0;
for (let i = 0; i < data.length; i++) {
if (i === 0) {
this.spanArr.push(1);
this.pos = 0;
} else {
if (data[i].yqMerchantId === data[i - 1].yqMerchantId) {
this.spanArr[this.pos] += 1;
this.spanArr.push(0);
} else {
this.spanArr.push(1);
this.pos = i;
}
}
}
},
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
if (columnIndex === 0) {
const _row = this.spanArr[rowIndex];
const _col = _row > 0 ? 1 : 0;
return {
rowspan: _row,
colspan: _col,
};
}
},
handleAddConfirm() {
console.log(this.tableData);
if (!this.hasQueried) {
return this.$message.warning("请先查询并配置关联园区店的业务场景");
}
// 校验:所有渲染出来的门店中,必须至少勾选一个场景才能提交
let hasSelectedAtLeastOneScene = false;
for (let i = 0; i < this.tableData.length; i++) {
if (this.tableData[i].checkedScenes && this.tableData[i].checkedScenes.length > 0) {
hasSelectedAtLeastOneScene = true;
break;
}
}
if (!hasSelectedAtLeastOneScene) {
return this.$message.warning("请至少勾选一个开单业务场景");
}
let hasStationType = false;
for (let i = 0; i < this.tableData.length; i++) {
if (this.tableData[i].checkedScenes && this.tableData[i].checkedScenes.length > 0 && this.tableData[i].stationType === "") {
hasStationType = true;
break;
}
}
console.log(hasStationType);
if (hasStationType) {
return this.$message.warning("请选择门店驻店类型");
}
const hasEmptyPositionType = this.tableData.some(row => row.checkedScenes
&& row.checkedScenes.length > 0
&& (!row.positionTypeList || row.positionTypeList.length === 0));
if (hasEmptyPositionType) {
return this.$message.warning("请选择门店岗位");
}
// 构建提交参数
const shopItemMap = new Map();
this.tableData.forEach((row) => {
// 如果没有勾选任何场景,则过滤掉该门店
if (!row.checkedScenes || row.checkedScenes.length === 0) {
return;
}
if (!shopItemMap.has(row.yqMerchantId)) {
shopItemMap.set(row.yqMerchantId, {
yqMerchantId: row.yqMerchantId,
yqMerchantName: row.yqMerchantName,
fourSShopList: [],
});
}
const parkStore = shopItemMap.get(row.yqMerchantId);
const sceneList = row.checkedScenes.map((code) => {
const sceneObj = row.sceneList.find(s => s.baseSceneCode === code);
return {
baseSceneCode: code,
sceneType: sceneObj ? sceneObj.sceneType : null,
};
});
parkStore.fourSShopList.push({
merchantId: row.shopMerchantId,
merchantName: row.shopMerchantName,
positionType: row.positionTypeList.join(","),
stationType: row.stationType,
sceneList,
});
});
const shopItemList = Array.from(shopItemMap.values());
if (shopItemList.length === 0) {
return this.$message.warning("请至少选择一个门店的业务场景进行分配");
}
if (shopItemList.length > 10) {
return this.$message.warning("最多只能分配10个门店");
}
const params = {
staffId: this.detail.staffId || this.detail.id,
staffPhone: this.detail.staffPhone,
staffName: this.detail.staffName,
shopItemList,
editFlag: false,
};
assignStoreV2Api(params).then(() => {
this.$message.success("分配门店成功");
this.$emit("refreshTable");
this.visible = false;
});
},
},
};
</script>
<style scoped lang="scss">
.detail-dialog {
padding: 0 10px;
}
.section-block {
background: #fff;
.section-title {
font-size: 16px;
color: #2a58ad;
padding: 10px;
background: #f5f7fa;
border-radius: 4px;
}
}
.empty-block {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 40px 0;
margin-top: 15px;
border-radius: 4px;
}
.table-container {
margin-top: 15px;
max-height: 400px;
overflow: auto;
}
.position-type-select {
width: 100%;
::v-deep .el-select__tags {
display: flex;
align-items: center;
flex-wrap: nowrap;
overflow: hidden;
white-space: nowrap;
max-width: calc(100% - 60px);
}
::v-deep .el-select__tags > span {
display: flex;
align-items: center;
flex-wrap: nowrap;
overflow: hidden;
min-width: 0;
max-width: 100%;
}
::v-deep .el-select__tags .el-tag {
display: inline-flex !important;
align-items: center !important;
width: auto !important;
min-width: 0 !important;
overflow: hidden !important;
flex: 0 1 auto !important;
}
::v-deep .el-select__tags .el-tag .el-select__tags-text {
display: block;
white-space: nowrap;
overflow: hidden !important;
text-overflow: ellipsis !important;
}
::v-deep .el-select__tags > span .el-tag:first-of-type {
flex: 1 1 auto !important;
min-width: 0 !important;
}
::v-deep .el-select__tags > span .el-tag:last-of-type:not(:first-of-type) {
flex: 0 0 auto !important;
overflow: visible !important;
max-width: none !important;
margin-left: 6px;
}
::v-deep .el-select__tags > span .el-tag:last-of-type:not(:first-of-type) .el-select__tags-text {
overflow: visible !important;
text-overflow: clip !important;
}
::v-deep .el-select__tags input {
flex: 0 0 auto;
width: 0 !important;
padding: 0 !important;
}
::v-deep .el-tag__close {
flex-shrink: 0;
}
}
.tips-block {
background: rgba(42, 88, 173, 0.08);
padding: 12px;
margin-top: 15px;
border-radius: 4px;
font-size: 14px;
color: #333333;
line-height: 20px;
}
</style>