CardDialog.vue
18.8 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
<template>
<div>
<!-- 选择发货卡号 -->
<baseDialog class="card-dialog" :is-show.sync="cardVisible" :config="dialogConfig.setting"
:dialog-config="dialogConfig.config" @closeDialog="handleClose">
<div class="flex head">
<div class="flex head-txt">
<div>已添加数量:{{ cardList.length }}</div>
<div>最大可添加数量:{{ cardMaxNum }}</div>
<div>
扫码框:<el-input style="width: 257px" placeholder="扫码输入请定位光标于此" v-model="scancode"
:maxlength="inputConfig.maxLen" clearable @change="handleScanChange"></el-input>
</div>
</div>
<div class="flex">
<el-button size="small" type="primary" @click="handleAdd">添加新的一行</el-button>
<el-button size="small" @click="handleBatchAdd">批量添加</el-button>
<el-button size="small" @click="handleExportCard">excel导入</el-button>
</div>
</div>
<div class="reject-dialog">
<d2-table ref="purchaseOrderDetailTable" :height="'500'" :table-params="tableParams" :has-page="hasPage"
:has-num="hasNum" :table-data="tableList">
<div slot="cardOne" slot-scope="scope">
<template v-if="cardList.length > (inputConfig.rowNum * scope.index)">
<el-input :class="{ 'border-red': cardList[inputConfig.rowNum * scope.index].errorType }"
:placeholder="inputConfig.placeholder" v-model="cardList[3 * scope.index].cardNum"
:maxlength="inputConfig.maxLen" clearable
@input="e => handleInput(e, scope, inputConfig.rowNum * scope.index)"></el-input>
<el-tooltip v-if="cardList[inputConfig.rowNum * scope.index].errorType" class="item" effect="light"
:content="errorTypeObj[cardList[inputConfig.rowNum * scope.index].errorType]" placement="top-start">
<i class="el-icon-warning"></i>
</el-tooltip>
<img src="../images/icon-delete.png" alt="" class="icon"
@click="handleDelete(inputConfig.rowNum * scope.index)">
</template>
</div>
<div slot="cardTwo" slot-scope="scope">
<template v-if="cardList.length > (inputConfig.rowNum * scope.index + 1)">
<el-input :class="{ 'border-red': cardList[inputConfig.rowNum * scope.index + 1].errorType }"
:placeholder="inputConfig.placeholder" v-model="cardList[3 * scope.index + 1].cardNum"
:maxlength="inputConfig.maxLen" clearable
@input="e => handleInput(e, scope, (inputConfig.rowNum * scope.index + 1))"></el-input>
<el-tooltip v-if="cardList[inputConfig.rowNum * scope.index + 1].errorType" class="item" effect="light"
:content="errorTypeObj[cardList[inputConfig.rowNum * scope.index + 1].errorType]" placement="top-start">
<i class="el-icon-warning"></i>
</el-tooltip>
<img src="../images/icon-delete.png" alt="" class="icon"
@click="handleDelete(inputConfig.rowNum * scope.index + 1)">
</template>
</div>
<div slot="cardThree" slot-scope="scope">
<template v-if="cardList.length > (inputConfig.rowNum * scope.index + 2)">
<el-input :class="{ 'border-red': cardList[inputConfig.rowNum * scope.index + 2].errorType }"
:placeholder="inputConfig.placeholder" v-model="cardList[3 * scope.index + 2].cardNum"
:maxlength="inputConfig.maxLen" clearable
@input="e => handleInput(e, scope, (inputConfig.rowNum * scope.index + 2))"></el-input>
<el-tooltip v-if="cardList[inputConfig.rowNum * scope.index + 2].errorType" class="item" effect="light"
:content="errorTypeObj[cardList[inputConfig.rowNum * scope.index + 2].errorType]" placement="top-start">
<i class="el-icon-warning"></i>
</el-tooltip>
<img src="../images/icon-delete.png" alt="" class="icon"
@click="handleDelete(inputConfig.rowNum * scope.index + 2)">
</template>
</div>
</d2-table>
</div>
<div class="footer">
<el-button @click="handleClose">取消</el-button>
<el-button @click="handleConfirm" type="primary" v-preventReClick
:loading="$store.state.d2admin.loading.value">确定</el-button>
</div>
</baseDialog>
<!-- 批量导入 -->
<baseDialog v-if="batchVisible" class="batch-dialog" :is-show.sync="batchVisible" :config="batchConfig.setting"
:dialog-config="batchConfig.config" @closeDialog="handleBatchClose">
<div>
<el-form :rules="batchRules" :model="batchData" label-width="150px" ref="batch-form">
<el-form-item label="起始卡号:" prop="startCode">
<el-input placeholder="请输入起始卡号" maxlength="50" show-word-limit v-model.trim="batchData.startCode"
class="dis-in-block" />
</el-form-item>
<el-form-item label="结束卡号:" prop="endCode">
<el-input placeholder="请输入结束卡号" maxlength="50" show-word-limit v-model.trim="batchData.endCode"
class="dis-in-block" />
</el-form-item>
<el-form-item>
<div class="tip-txt">请确保起始卡号与结束卡号格式一致且存在可识别区间,系统自动拆分并完成添加。</div>
</el-form-item>
</el-form>
</div>
<div class="footer">
<el-button @click="handleBatchClose">取消</el-button>
<el-button @click="handleBatchConfirm" type="primary" v-preventReClick
:loading="$store.state.d2admin.loading.value">确定</el-button>
</div>
</baseDialog>
<!-- excel导入 -->
<baseDialog v-if="exportVisible" class="export-dialog" :is-show.sync="exportVisible" :config="exportConfig.setting"
:dialog-config="exportConfig.config" @closeDialog="handleExportClose">
<div v-if="exportConfig.isTips" class="tip-content">
<img v-if="exportConfig.tipConfig.type == 'success'" src="../images/icon-success.png" alt="" class="icon" />
<img v-else src="../images/icon-error.png" alt="" class="icon" />
<div v-if="exportConfig.tipConfig.type == 'success'">导入成功,共导入{{ exportTipData.dataList.length }}条</div>
<div v-else>导入失败,
<el-link type="primary" class="import-template" @click="downError" icon="el-icon-link">
下载失败模板
</el-link>
</div>
</div>
<el-form v-else :rules="exportRules" :model="exportData" label-width="100px" ref="export-form"
class="tip-content">
<el-form-item label="上传文件:" prop="fileName">
<div class="flex">
<el-input style="width: 284px; margin-right: 8px;" placeholder="请选择" show-word-limit
v-model.trim="exportData.fileName" readonly class="dis-in-block" />
<el-button class="import-btn" type="text">
<input type="file" id="fileUpload" class="import-input"
accept="application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
@change="handleChooseFile($event)">
选择
</el-button>
</div>
<el-link type="primary" class="import-template" @click="downLoadTemplate">
下载模板
</el-link>
</el-form-item>
</el-form>
<div class="footer">
<el-button v-if="!exportConfig.isTips" @click="handleExportClose">取消</el-button>
<el-button v-if="!exportConfig.isTips" @click="handleExportConfirm" type="primary" v-preventReClick
:loading="$store.state.d2admin.loading.value">确定</el-button>
<el-button v-if="exportConfig.isTips" @click="handleTipsExportConfirm" type="primary" v-preventReClick
:loading="$store.state.d2admin.loading.value">我知道了</el-button>
</div>
</baseDialog>
</div>
</template>
<script>
import { deliveryCard, importDeliveryCard, checkCard } from '@/api/purchaseShopping.js'
import { downLoadFile } from '@/common/util'
export default {
name: 'CardDialog',
props: {
cardVisible: {
type: Boolean,
default: false
},
orderInfo: {
type: Object,
default: () => { }
},
selectedList: {
type: Array,
default: () => []
},
cardMaxNum: {
type: String,
default: '0'
}
},
data() {
return {
scancode: '',
inputConfig: {
maxLen: 50,
placeholder: '请使用扫码枪获取或输入发货卡号',
rowNum: 3
},
dialogConfig: {
setting: {
showClose: true,
appendToBody: true,
btnList: [
]
},
config: {
title: '选择发货卡号',
width: '1008px'
}
},
// 批量导入
batchConfig: {
setting: {
showClose: true,
appendToBody: true,
btnList: [
]
},
config: {
title: '批量添加',
width: '576px'
}
},
batchVisible: false,
batchData: {
startCode: '',
endCode: ''
},
batchRules: {
startCode: [{ required: true, message: '请输入起始卡号', trigger: 'blur' }],
endCode: [{ required: true, message: '请输入结束卡号', trigger: 'blur' }]
},
// 导出
exportConfig: {
isTips: false,
setting: {
showClose: true,
appendToBody: true,
btnList: [
]
},
config: {
title: '导入',
width: '576px'
},
tipConfig: {
// success, error
type: 'success'
}
},
exportTipData: {},
exportVisible: false,
exportData: {
fileName: '',
file: ''
},
exportRules: {
fileName: [{ required: true, message: '请选择上传文件', trigger: 'blur' }]
},
// 发货卡号
tableList: [],
cardConstObj: {
cardNum: '',
errorType: ''
},
errorTypeObj: {
empty: '请完善发货卡号',
repeat: '重复卡号',
invalid: '无效卡号'
},
cardList: [],
hasPage: false,
hasNum: false,
tableParams: {
btnId: new Date().getTime() + parseInt(Math.random() * 1000),
listName: 'list',
tableColumns: [
{
label: '发货卡号',
prop: '',
addHtml: 'cardOne'
},
{
label: '发货卡号',
prop: '',
addHtml: 'cardTwo'
},
{
label: '发货卡号',
prop: '',
addHtml: 'cardThree'
}
]
},
dialogRules: {
deliveryCompany: [{ required: true, message: '请输入承运物流公司', trigger: 'blur' }],
deliveryNumber: [{ required: true, message: '请输入承运物流单号', trigger: 'blur' }],
deliveryDate: [{ required: true, message: '请选择发货时间', trigger: 'blur' }]
}
}
},
mounted() {
// this.cardAddItem()
if (this.selectedList.length) {
this.dealBatchAdd(this.selectedList)
}
},
methods: {
// 添加卡号数量
cardAddItem() {
this.tableList.unshift({})
const _list = Array(this.inputConfig.rowNum).fill(0).map(() => (JSON.parse(JSON.stringify(this.cardConstObj))))
// const _list = Array.from({ length: _listNum }, () => (JSON.parse(JSON.stringify(this.cardConstObj))))
this.cardList.unshift(..._list)
},
handleAdd() {
this.cardAddItem()
},
// 找到第一个为空的idx
findEmptyIdx() {
const _idx = this.cardList.findIndex(item => !!item.cardNum)
return _idx == -1 ? (this.cardList.length - 1) : (_idx - 1)
},
// 处理表格的数据,每三个为一行
dealBatchTableRow(addListLen) {
const rowNum = Math.ceil((addListLen + this.cardList.length) / this.inputConfig.rowNum)
this.tableList = Array(rowNum).fill('').map(() => ({}))
},
// 处理批量写入卡号
dealBatchAdd(list) {
const _idx = this.findEmptyIdx()
this.cardList.reverse().splice(this.cardList.length - _idx - 1)
this.cardList.reverse()
this.dealBatchTableRow(list.length)
list.forEach(item => {
this.cardList.unshift({
cardNum: item
})
})
},
// 批量导入
handleBatchClose() {
this.batchVisible = !this.batchVisible
this.batchData = {
startCode: '',
endCode: ''
}
},
handleBatchAdd() {
this.handleBatchClose()
},
handleBatchConfirm() {
this.$refs['batch-form'].validate(valid => {
if (valid) {
deliveryCard(this.batchData).then(res => {
this.handleBatchClose()
this.dealBatchAdd(res)
})
}
})
},
// excel导入
handleExportCard() {
this.exportConfig.isTips = false
this.handleExportClose()
},
handleExportClose() {
this.exportVisible = !this.exportVisible
this.exportData = {}
},
downLoadTemplate() {
const url = 'https://img01.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/template/发货卡号模板.xlsx'
downLoadFile(url)
},
downError() {
const url = this.exportTipData.url
downLoadFile(url)
},
handleTipsExportConfirm() {
this.handleExportClose()
if (this.exportConfig.tipConfig.type == 'success') {
this.dealBatchAdd(this.exportTipData.dataList)
this.exportTipData = {}
}
},
handleExportConfirm() {
this.$refs['export-form'].validate((valid) => {
if (valid) {
importDeliveryCard({ file: this.exportData.file }).then((result) => {
const { url, dataList } = result
this.exportConfig.isTips = true
this.exportConfig.config.title = url ? '失败提示' : '成功提示'
this.exportConfig.tipConfig.type = url ? 'error' : 'success'
this.exportTipData.url = url
this.exportTipData.dataList = dataList || []
})
}
})
},
handleChooseFile(e) {
const size = e.target.files[0].size / 1024 / 1024
const type = e.target.files[0].type
var filetypes = ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"]
if (!filetypes.includes(type)) {
document.getElementById('fileUpload').value = ''
this.notice.errorTips('请按模版要求上传导入文件')
return true
}
if (size < 9) {
this.$set(this.exportData, 'fileName', e.target.files[0].name)
// // 转码base64
const reader = new FileReader()
reader.readAsDataURL(e.target.files[0])
reader.onload = event => {
const imgFile = event.target.result
const arrBase64 = imgFile.split(',')
this.exportData.file = e.target.files[0].name.split('.')[1] + '@' + arrBase64[1]
document.getElementById('fileUpload').value = ''
}
} else {
this.notice.errorTips('上传文件不可超过9M')
}
},
handleDelete(idx) {
this.cardList.splice(idx, 1)
this.dealBatchTableRow(0)
},
// 扫码
handleScanChange(e) {
this.dealBatchAdd([e])
this.scancode = ''
},
handleInput(val, scope, idx) {
this.cardList[idx].errorType = ''
this.cardList[idx].cardNum = val.replace(/[\W]/g, '')
},
handleClose() {
this.$emit('handleClose')
},
checkEmptyCard() {
let isEmpty = false
this.cardList.forEach((item, idx) => {
if (!item.cardNum) {
isEmpty = true
item.errorType = 'empty'
}
})
return isEmpty
},
handleConfirm() {
if (!this.cardList.length) {
this.notice.errorTips('请添加发货卡号')
return true
}
if (this.checkEmptyCard()) {
return true
}
const _cardList = this.cardList.map(item => item.cardNum)
checkCard({ dataString: JSON.stringify(_cardList) }).then(res => {
if (res && res.length == this.cardList.length) {
if (this.cardList.length > this.cardMaxNum) {
this.notice.errorTips('添加数量与发货数量不一致,请确认后重新保存')
return true
}
this.$emit('handleConfirm', _cardList)
} else {
const _correctList = res || []
this.cardList.forEach((item, idx) => {
const _beforeList = this.cardList.slice(0, idx).map(i => i.cardNum)
if (_beforeList.includes(item.cardNum)) {
this.$set(item, 'errorType', 'repeat')
} else if (!_correctList.includes(item.cardNum)) {
this.$set(item, 'errorType', 'invalid')
}
})
}
})
}
}
}
</script>
<style lang="scss" scoped>
.addressTitle {
display: flex;
align-items: center;
.title {
font-family: PingFangSC-Medium;
font-weight: 600;
font-size: 16px;
color: #333333;
}
.icon {
width: 28px;
height: 28px;
margin-right: 8px;
}
}
.address-info {
display: flex;
box-sizing: border-box;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
width: 100%;
// height: 36px;
// padding: 0 20px;
margin-top: 10px;
font-size: 14px;
color: #666666;
>span {
margin-right: 20px;
margin-bottom: 10px;
}
.label {
color: #333333;
}
.address {
min-width: 500px;
}
}
.form-content {
margin-top: 16px;
.dis-in-block {
width: 432px;
}
}
.footer {
display: flex;
justify-content: flex-end;
}
.card-dialog .el-input--medium {
width: calc(100% - 64px);
margin: 0 8px 0 16px;
}
.card-dialog .el-input--medium.border-red .el-input__inner {
border: 1px solid #eb4e4e;
}
.card-dialog {
.flex {
display: flex;
}
.head {
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
}
.head-txt {
font-weight: 400;
font-size: 12px;
color: #666666;
justify-content: center;
align-content: center;
div {
line-height: 36px;
margin-right: 40px;
flex-shrink: 0;
}
}
.icon {
width: 16px;
height: 16px;
cursor: pointer;
}
}
.batch-dialog {
.tip-txt {
font-size: 14px;
color: #666666;
line-height: 20px;
}
}
.export-dialog {
.tip-content {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-size: 16px;
color: #333333;
padding: 60px 0;
}
.icon {
width: 48px;
height: 48px;
margin-bottom: 8px;
}
.import-btn {
position: relative;
}
.import-input {
opacity: 0;
position: absolute;
right: 0;
top: 0;
width: 98px;
height: 36px;
cursor: pointer;
font-size: 0;
}
}
</style>