shortLightAlloction.vue
23 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
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
<!-- 短课程配课 -->
<template>
<div class="short-dialog">
<baseDialog class="accountDailog"
:config="config"
:dialog-config="dialogConfig"
:is-show.sync="visible"
@closeDialog="handleClose"
@handleClick="handleConfirm">
<div class="dialog-content">
<el-form ref="formRef"
:model="configData"
:rules="rules">
<el-form-item label="开启课程:" label-width="100px">
<el-switch v-model="configData.openFlag"
active-value="Y"
inactive-value="N">
</el-switch>
<span class="unit-text">{{ configData.openFlag === 'Y' ? '开启' : '关闭' }}</span>
</el-form-item>
<h4 class="group-title">
学习条件
</h4>
<div class="rule-item rule-item--inline">
<!-- <el-form-item label="本周门店渗透率 <"
prop="storePenetrationWeekly">
<el-input v-model="configData.storePenetrationWeekly"
placeholder="请输入"
style="width: 120px"
@blur="validateNumber('storePenetrationWeekly', 30, 90)">
<template #append>
%
</template>
</el-input>
</el-form-item>
<el-form-item label=",且驻店人员上月渗透率 ≤"
prop="storePenetrationMonthly">
<el-input v-model="configData.storePenetrationMonthly"
placeholder="请输入"
style="width: 120px"
@blur="validateNumber('storePenetrationMonthly', 30, 90)">
<template #append>
%
</template>
</el-input>
</el-form-item> -->
<el-form-item label="每天 09:00 推送前一天驻店接待记录为"></el-form-item>
<span class="defeat-tag">战败</span>
<el-form-item label="的短课程学习" style="margin-left: 12px;"></el-form-item>
</div>
<div class="rule-item" style="margin-top: 12px;">
<el-form-item label="适用人员(白名单手机号导入):"
prop="phoneWhitelistFileUrl">
<div class="whitelist-upload-wrap">
<div v-if="uploadFileList.length === 0"
class="whitelist-upload-row">
<el-upload ref="whitelistUpload"
accept=".xlsx,.xls"
action=""
:auto-upload="false"
class="upload-file"
:file-list="uploadFileList"
:limit="1"
:on-change="handleWhitelistFileChange"
:on-exceed="handleWhitelistExceed"
:on-remove="importFileChange"
:show-file-list="false">
<div class="upload-txt">
+ 点击上传Excel表格
</div>
</el-upload>
<span class="unit-text link-like"
@click="downloadTemplate">
下载模版
</span>
</div>
<div class="file-box">
<div v-for="(subItem, subIndex) in whitelistFiles"
:key="subIndex">
<div v-if="!filterEmpty(subItem.uploadProgress) || subItem.fileUrl"
class="file-item">
<div class="file-content"
@click="handleWhitelistFileView(subItem)">
<el-progress define-back-color="#F5F7FA"
:percentage="subItem.uploadProgress"
:show-text="false"
stroke-linecap="butt"
:stroke-width="32"
text-color="#333333"
:text-inside="true">
</el-progress>
<div class="file-name">
{{ subItem.fileName }}
</div>
<i v-if="!subItem.fileUrl"
class="el-icon-delete"
@click.stop="doCancelWhitelistUpload(subIndex)">
</i>
<i v-if="subItem.fileUrl"
class="el-icon-delete"
@click.stop="handleWhitelistFileDelete(subIndex)">
</i>
</div>
</div>
</div>
</div>
<div v-if="uploadFileList.length === 0" class="upload-tips">
仅支持包含驻店销售手机号的 .xlsx 或 .xls 文件
</div>
<div v-if="phoneWhitelistStaffList.length > 0"
class="upload-tips import-result-line">
已成功导入{{ phoneWhitelistStaffList.length }}人
<span class="link-like"
@click="openWhiteStaffListDialog">
查看明细
</span>
</div>
</div>
</el-form-item>
</div>
<h4 class="group-title">
学习要求
</h4>
<div class="rule-item">
<el-form-item label="短课程学习需要在课程发布后" prop="finishTime">
<el-input v-model="configData.finishTime"
placeholder="请输入"
style="width: 80px"
@blur="validateNumber('finishTime', 24, 168)">
</el-input>
<span class="unit-text">小时内完成</span>
</el-form-item>
</div>
<div class="rule-item">
<el-form-item label="如果在限时内未完成则">
<el-select v-model="configData.punishType" placeholder="请选择">
<el-option v-for="item in punishTypeOpt"
:key="item.confId"
:label="item.confValue"
:value="item.confId">
</el-option>
</el-select>
</el-form-item>
</div>
<div class="rule-item">
<el-form-item label="生效时间为">
<el-select v-model="configData.effectiveType"
placeholder="请选择">
<el-option v-for="item in effectiveTypeOpt"
:key="item.confId"
:label="item.confValue"
:value="item.confId">
</el-option>
</el-select>
</el-form-item>
</div>
</el-form>
</div>
</baseDialog>
<WhiteStaffList :staff-list="phoneWhitelistStaffList"
:staff-list-visible="whiteStaffListVisible"
@dialogClose="handleWhiteStaffListDialogClose" />
</div>
</template>
<script>
import { getLightChangeConfig, importLightChangePhone, updateLightChangeConfig } from "@api/serviceCentre";
import { mapActions, mapState } from "vuex";
import { effectiveTypeOpt, punishTypeOpt } from "@/common/constants.js";
import whiteStaffList from "./whiteStaffList.vue";
export default {
name: "ShortLightAlloction",
components: {
WhiteStaffList: whiteStaffList,
},
props: {
shortLightVisible: {
type: Boolean,
default: false,
},
},
data() {
return {
dialogConfig: {
title: "短课程配课",
width: "720px",
},
config: {
showClose: true,
appendToBody: false, // 是否将自身插入至 body 元素,有嵌套的弹窗时一定要设置
isShowFooter: true,
cancel_name: "取 消",
confirm_name: "提 交",
},
punishTypeOpt,
effectiveTypeOpt,
rules: {
finishTime: [
{ required: true, message: "请输入短课程学习时间", trigger: "blur" },
],
},
uploadFileList: [],
whitelistFiles: [],
/** 白名单 Excel 导入接口返回的 staffList,用于人数展示与明细弹窗 */
phoneWhitelistStaffList: [],
whiteStaffListVisible: false,
configData: {
effectiveType: "",
storePenetrationMonthly: "",
storePenetrationWeekly: "",
punishType: "",
inspectionScore: "",
finishTime: 72,
openFlag: "",
phoneWhitelistFileUrl: "",
},
};
},
computed: {
...mapState({
dowloadList: state => state.d2admin.user.dowloadList,
}),
visible: {
get() {
return this.shortLightVisible;
},
set(newVal) {
this.$emit("dialogClose", {
flag: newVal,
attrName: "shortLightVisible",
});
},
},
/** 已有上传成功的文件时隐藏上传区,删除后再次展示 */
showWhitelistUploadRow() {
return !this.whitelistFiles.some(item => item.fileUrl);
},
},
watch: {
whitelistFiles: {
handler(newVal) {
if (!newVal)
return;
this.uploadFileList = newVal.filter(
v => !this.filterEmpty(v.uploadProgress) || v.fileUrl,
);
},
deep: true,
},
},
created() {
this.getSopConfigData();
},
methods: {
...mapActions("d2admin/user", ["actionSetDownloadList"]),
validateNumber(field, min, max) {
let value = this.configData[field];
value = Number.parseInt(value);
if (Number.isNaN(value))
value = "";
// 限制最大值
if (Number.parseInt(value) > max) {
value = "";
this.$message.warning(`输入值不能超过 ${max}`);
}
if (Number.parseInt(value) < min) {
value = "";
this.$message.warning(`输入值不能小于${min}`);
}
this.$set(this.configData, field, value);
},
getSopConfigData() {
getLightChangeConfig({})
.then((res) => {
console.log(res, "getSopConfig");
this.configData = Object.assign({}, this.configData, res);
this.configData.openFlag = Number(this.configData.openFlag) === 1 ? "Y" : "N";
const url = this.configData.phoneWhitelistFileUrl
|| res.phoneWhitelistFileUrl
|| res.whitelistPhoneFileUrl
|| res.uploadFile
|| "";
this.$set(this.configData, "phoneWhitelistFileUrl", url);
if (url) {
this.whitelistFiles = [
{
fileUrl: url,
uploadProgress: 100,
fileName: this.fileNameFromUrl(url),
fileSize: 0,
cancelAxios: {},
},
];
} else {
this.whitelistFiles = [];
}
if (Array.isArray(res.staffList))
this.phoneWhitelistStaffList = res.staffList;
})
.catch((err) => {
console.error(err);
});
},
// 提交
handleConfirm() {
this.$refs.formRef.validate((valid, invalidFields) => {
if (valid) {
const params = {
punishType: this.configData.punishType,
finishTime: this.configData.finishTime,
effectiveType: this.configData.effectiveType,
openFlag: this.configData.openFlag === "Y" ? 1 : 0,
staffList: this.phoneWhitelistStaffList,
};
console.log(params, "params");
updateLightChangeConfig(params)
.then((res) => {
console.log(res, "updateLightChangeConfig");
this.$message.success("修改成功");
this.handleClose();
})
.catch((err) => {
console.error(err);
});
}
});
},
handleClose() {
this.visible = false;
},
fileNameFromUrl(url) {
try {
const path = url.split("?")[0];
const name = path.substring(path.lastIndexOf("/") + 1);
return name || "已上传文件";
} catch (e) {
return "已上传文件";
}
},
downloadTemplate() {
const params = {
method: "dj.api.smartcarlife.servicecenter.short.course.phone.template.export",
};
const list = [
...this.dowloadList,
{
name: "轻改业务短课程名单导入模板",
exportParam: JSON.stringify(params),
status: "waiting",
timeid: new Date().getTime(),
},
];
this.actionSetDownloadList({ list, type: "dowloadList" });
},
filterEmpty(data) {
return (data ?? "") === "";
},
importFileChange(file, fileList) {
this.uploadFileList = fileList;
if (!fileList || fileList.length === 0) {
this.whitelistFiles = [];
this.configData.phoneWhitelistFileUrl = "";
this.phoneWhitelistStaffList = [];
}
},
handleWhitelistFileChange(file) {
console.log(file, "file");
const fileInfo = file.raw;
if (!fileInfo)
return;
const lower = fileInfo.name.toLowerCase();
const okExt = lower.endsWith(".xlsx") || lower.endsWith(".xls");
if (!okExt) {
this.$message.error("仅支持 .xlsx、.xls 格式");
this.$refs.whitelistUpload && this.$refs.whitelistUpload.clearFiles();
return;
}
const limitSize = 5;
const isLt = fileInfo.size / 1024 / 1024 < limitSize;
if (!isLt) {
this.$message.error(`上传文件大小不能超过 ${limitSize}MB`);
this.$refs.whitelistUpload && this.$refs.whitelistUpload.clearFiles();
return;
}
const item = {
fileUrl: "",
uploadProgress: 0,
fileName: fileInfo.name?.substring(0, 128),
fileSize: fileInfo.size,
cancelAxios: {},
};
this.whitelistFiles = [item];
const index = 0;
const fail = (msg) => {
this.whitelistFiles = [];
this.configData.phoneWhitelistFileUrl = "";
this.phoneWhitelistStaffList = [];
this.$refs.whitelistUpload && this.$refs.whitelistUpload.clearFiles();
msg && this.$message.error(msg);
};
const onProcess = (progressEvent) => {
const total = progressEvent?.total || 0;
const loaded = progressEvent?.loaded || 0;
if (!total)
return;
const percent = Math.min(99, Math.max(0, Math.floor((loaded / total) * 100)));
this.$set(this.whitelistFiles[index], "uploadProgress", percent);
};
// 与 ROP UploadFile / SingleUploadRequest 约定一致:字符串「扩展名@base64正文」(同 importProfit、d2-file-import-dialog)
const reader = new FileReader();
reader.onload = (e) => {
const dataUrl = e.target?.result || "";
const parts = String(dataUrl).split(",");
const b64 = parts[1];
if (!b64) {
fail("文件编码失败,请重试");
return;
}
const ext = (fileInfo.name.split(".").pop() || "xlsx").toLowerCase();
const filePayload = `${ext}@${b64}`;
importLightChangePhone({
file: filePayload,
onProcess,
cancelFun: this.whitelistFiles[index].cancelAxios,
})
.then((res) => {
// 接口 data 内员工列表(axios 拦截器已解包为 data 对象)
const raw = res && typeof res === "object" ? res : {};
const list = Array.isArray(raw.staffList)
? raw.staffList
: (Array.isArray(raw.data?.staffList) ? raw.data.staffList : []);
// 优先判断:无匹配员工时不落库、不覆盖原有名单与文件地址,仅清空本次上传控件
if (!list.length) {
this.whitelistFiles = [];
this.uploadFileList = [];
this.$refs.whitelistUpload && this.$refs.whitelistUpload.clearFiles();
this.$message.warning("文件无匹配数据请重新上传");
return;
}
this.$set(this.whitelistFiles[index], "uploadProgress", 100);
this.phoneWhitelistStaffList = list;
// 尝试从返回值中取可预览的 url(不同后端可能字段不同)
const url = (typeof res === "string" && /^https?:\/\//.test(res))
? res
: (raw?.fileUrl || raw?.url || raw?.aliyunAddress || "");
if (url) {
this.$set(this.whitelistFiles[index], "fileUrl", url);
this.configData.phoneWhitelistFileUrl = url;
}
this.$message.success("上传成功");
})
.catch((err) => {
console.error(err);
fail(err?.message || "上传失败");
});
};
reader.onerror = () => fail("读取文件失败");
reader.readAsDataURL(fileInfo);
},
handleWhitelistExceed() {
this.$message.error("最多可上传 1 个文件");
},
doCancelWhitelistUpload(subIndex) {
const cancelUploadObj = this.whitelistFiles[subIndex]
&& this.whitelistFiles[subIndex].cancelAxios;
cancelUploadObj && cancelUploadObj.cancel && cancelUploadObj.cancel();
this.whitelistFiles.splice(subIndex, 1);
this.configData.phoneWhitelistFileUrl = "";
this.phoneWhitelistStaffList = [];
this.$refs.whitelistUpload && this.$refs.whitelistUpload.clearFiles();
},
handleWhitelistFileDelete(subIndex) {
this.whitelistFiles.splice(subIndex, 1);
this.configData.phoneWhitelistFileUrl = "";
this.phoneWhitelistStaffList = [];
this.uploadFileList = [];
this.$refs.whitelistUpload && this.$refs.whitelistUpload.clearFiles();
},
openWhiteStaffListDialog() {
if (!this.phoneWhitelistStaffList.length)
return;
this.whiteStaffListVisible = true;
},
handleWhiteStaffListDialogClose({ flag, attrName } = {}) {
if (attrName === "staffListVisible")
this.whiteStaffListVisible = !!flag;
},
handleWhitelistFileView(item) {
if (item.fileUrl)
window.open(item.fileUrl, "_blank");
},
},
};
</script>
<style scoped lang="scss">
.short-dialog {
::v-deep .el-dialog__headerbtn .el-dialog__close {
color: #333333;
font-weight: 600;
font-size: 20px;
}
::v-deep .el-form-item__label {
color: #333333;
font-size: 16px;
}
::v-deep .el-form-item__content {
display: flex;
}
::v-deep .el-divider--horizontal {
margin: 16px 0;
}
::v-deep .el-switch {
margin-top: 8px;
}
::v-deep .el-input-group__append {
padding: 0 10px;
}
.group-title {
color: #111111;
font-size: 16px;
font-weight: 500;
padding: 10px 0;
border-bottom: 1px solid #e5e5e5;
}
.rule-item {
display: flex;
align-items: center;
padding-left: 20px;
}
.rule-item--inline {
align-items: center;
flex-wrap: wrap;
::v-deep .el-form-item {
margin-bottom: 0;
align-items: center;
}
::v-deep .el-form-item__content {
min-height: 0;
}
}
.unit-text {
margin-left: 12px;
font-size: 16px;
}
.defeat-tag {
display: inline-flex;
align-items: center;
align-self: center;
flex-shrink: 0;
color: #eb4e4e;
font-size: 14px;
font-weight: 500;
border-radius: 2px;
opacity: 1;
background: #eb4e4e1a;
padding: 6px 12px;
}
::v-deep .el-form-item.is-required:not(.is-no-asterisk) > .el-form-item__label::before {
display: none;
content: none;
}
::v-deep .el-switch__label,
.el-switch__label.is-active {
color: #333;
}
.whitelist-upload-wrap {
display: flex;
flex-direction: column;
align-items: flex-start;
max-width: 100%;
}
.whitelist-upload-row {
display: flex;
align-items: center;
flex-wrap: wrap;
}
.link-like {
cursor: pointer;
color: #2a58ad;
font-size: 14px;
font-weight: 400;
}
.upload-file {
display: flex;
align-items: center;
justify-content: center;
margin-right: 12px;
width: 172px;
height: 32px;
border-radius: 4px;
border: 1px solid #00000026;
background: #ffffff;
text-align: center;
.upload-txt {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
color: #666666;
font-size: 14px;
line-height: 1;
}
}
.upload-tips {
margin-top: 6px;
max-width: 420px;
color: #999999;
font-size: 14px;
font-weight: 400;
line-height: 1.4;
}
.import-result-line .link-like {
margin-left: 8px;
}
.file-box {
width: 100%;
max-width: 380px;
.file-item {
margin-top: 8px;
position: relative;
display: flex;
justify-content: space-between;
align-items: center;
.file-content {
flex: 1;
min-width: 0;
cursor: pointer;
position: relative;
display: flex;
height: 32px;
align-items: center;
justify-content: space-between;
}
::v-deep .el-progress-bar {
width: 100%;
max-width: 320px;
}
// ::v-deep .el-progress-bar__outer {
// height: 32px;
// border-radius: 4px;
// opacity: 1;
// border: 1px solid #e5e5e5;
// background: #f5f7fa;
// }
::v-deep .el-progress-bar__inner {
height: 32px;
border-radius: 4px;
background: #f5f7fa;
}
.file-name {
box-sizing: border-box;
min-width: 318px;
// position: absolute;
// left: 0;
// top: 0;
height: 32px;
line-height: 32px;
border-radius: 4px;
opacity: 1;
border: 1px solid #e5e5e5;
background: #f5f7fa;
color: #333333;
font-size: 14px;
display: flex;
align-items: center;
justify-content: flex-start;
text-align: left;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
padding: 0 32px 0 12px;
}
.del-icon,
.el-icon-delete {
cursor: pointer;
color: #909399;
flex-shrink: 0;
font-size: 16px;
line-height: 1;
z-index: 2;
margin-left: 17px;
}
}
}
}
</style>