index.vue
17 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
<template>
<div class="container">
<GLCombiForm ref="searchRef" :rowNumber="1" :formObj="searchForm" :formData="searchFormData" @handleOk="handleOk" @handleRest="handleRest"></GLCombiForm>
<el-button type="primary" :size="size" style="float:right;margin-bottom:10px;" @click="createCode">生成核销码</el-button>
<GLTable :pageSizes="pageSizes" ref="tableRef" :pageConf="pageConf" :searchForm="searchForm" :tableParams="tableParams" :beforeSearchFn="beforeSearchFn" :getListApi="getListApi"></GLTable>
<GLDialog class="dialog_wrap" title="生成核销码" mode="mid" :visible.sync="isVisible" :show-close="showClose" :before-close="handleClose" @onOk="onOk"
@onCancel="handleClose" :close-on-click-modal="false">
<div>
<label class="label_class" for="">合同号:</label>
<el-radio-group @change="changeAddMethod" v-model="addType">
<el-radio :label="1">手动输入</el-radio>
<el-radio :label="2">导入</el-radio>
</el-radio-group>
</div>
<div class="manual" v-if="addType == 1">
<el-input type="textarea" class="contract_input" v-model="contractNoStr" placeholder="请输入合同号"></el-input>
<p class="textarea_tip" :style="{color: contractNoList.length > 20 ? 'red': '#999999'}">{{contractNoList.length > 20 ? '最多输入20个合同号':'多个合同号换行输入,最多20个合同号'}}</p>
<p class="textarea_tip" v-if="requestTip">以下红色标记为合同号不存在,判断为无效合同</p>
<div class="contract_area">
<div :class="['contract_item', {valid: item.valid}]" v-for="(item, index) in contractNoList" :key="index">
<span class="contract_no">{{ item.val }}</span>
<i style="cursor:pointer" class="el-icon-close" @click="delContractNo(item.val)"></i>
</div>
</div>
</div>
<div class="import" v-else>
<div class="upload_wrap">
<div class="upload_btn">
<el-button icon="el-icon-plus" :size="size" @click="upload">
上传文件
<input type="file" style="opacity: 0;width: 0;height: 0;" ref="file" accept="*" @change="uploadFile" />
</el-button>
<div class="preview">
<el-popover
placement="right-start"
width="160"
trigger="hover"
>
<!-- <img style="width: 100%;" :src="require('@/assets/example.png')"> -->
<el-image
style="width: 100px;"
:src="exampleImg"
:preview-src-list="[exampleImg]">
</el-image>
<span slot="reference">模版预览</span>
</el-popover>
</div>
</div>
<div class="file_name" v-if="fileData && fileData.name">{{fileData.name}}</div>
</div>
<div class="file_info">
<div class="file_num">
<div class="num_wrap">
<span class="num valid">{{errorFileInfo.effectiveSize || 0}}</span>
<span class="title">有效数量</span>
</div>
<div class="num_wrap">
<span class="num invalid">{{errorFileInfo.invalidSize || 0}}</span>
<span class="title">
无效数量
<span class="download" v-if="errorFileInfo.invalidSize" @click="handleExport">下载</span>
</span>
</div>
</div>
<div class="tip_txt">
<p class="tip_title">数据异常的可能原因:</p>
<p>1. 合同号格式不正确</p>
<p>2. 合同号不存在</p>
</div>
</div>
</div>
</GLDialog>
</div>
</template>
<script>
import util from '@/util/util'
import exampleImg from '@/assets/example.png'
import { ConcatSource } from 'webpack-sources'
export default {
name: 'index',
data() {
return {
size: 'small',
exampleImg,
uploaded: false,
isVisible: false,
requestTip: false,
contractNoStr: '',
addType: 1,
contractNoList: [],
errorNoList: [],
errorFileInfo:{},
fileData: {},
getListApi: this.$apis.addCode.getcodeList,
pageConf: { pageSize: 'pageSize', pageNum: 'pageCount', totalCount: 'total' },
pageSizes: [5, 10, 20, 30, 40],
tableParams: {
listName: 'list',
tableOption: false,
tableColumns: [
{
label: '核销码',
prop: 'writeOffCode'
},
{
label: '客户姓名',
prop: 'customerName'
},
{
label: '合同号',
prop: 'contractNo'
},
{
label: '门店名称',
prop: 'merchantName'
},
{
label: '报案时间',
formatter: cell => {
return util.dateFormat(cell.createdDate, 'YYYY-MM-DD HH:mm:ss')
}
}
]
},
searchForm: {
writeOffCode: '',
contractNo: '',
merchantName: '',
reportDate: ''
},
searchFormData: [
{
label: '核销码',
name: 'writeOffCode',
type: 'input',
isClear: true
},
{
label: '合同号',
name: 'contractNo',
type: 'input',
isClear: true
},
{
label: '门店名称',
name: 'merchantName',
type: 'input',
isClear: true
},
{
label: '报案时间',
name: 'reportDate',
type: 'datePicker',
isClear: true
}
]
}
},
methods: {
upload() {
this.$refs.file.click()
},
//查询表格
handleOk() {
this.$refs.tableRef.refreshTable()
},
// 重置表格
handleRest() {
this.searchForm = {
writeOffCode: '',
contractNo: '',
merchantName: '',
reportDate: ''
}
this.handleOk()
},
getParams() {
let params = { ...this.searchForm }
if (params.reportDate) {
params.beginCreateTime = new Date(this.searchForm.reportDate[0]).toLocaleDateString().replace(/\//g, '-') + ' 00:00:00'
params.endCreateTime = new Date(this.searchForm.reportDate[1]).toLocaleDateString().replace(/\//g, '-') + ' 23:59:59'
}
return params
},
beforeSearchFn() {
return new Promise(resolve => {
this.searchForm = this.getParams()
resolve()
})
},
//解析合同号,
formatContractNo() {
let contractNoList = this.contractNoStr.split('\n').filter(item => !!item?.trim()) || []
this.contractNoList = contractNoList.map(item =>{
return {val: item, valid: this.errorNoList?.includes(item)}
})
// 给点一个值判断是否有效
const target = this.contractNoList.find(item => item.valid)
!target && (this.requestTip = false)
},
// 删除合同号,同时删除多余的空格换行
delContractNo(val){
let contractNo = '\n' + this.contractNoStr + '\n'
contractNo = contractNo.replace(/[\n]/g, '\n\n')
contractNo = contractNo.replace(new RegExp('[\n]' + val + '[\n]'), '\n')
contractNo = contractNo.replace(/[\n]+/g, '\n')
contractNo = contractNo.replace(/^[\n]+/, '')
this.contractNoStr = contractNo
this.formatContractNo()
},
// 上传excel
uploadFile(e) {
const file = e.srcElement.files[0]
let AllImgExt = '.xlsx' //文件格式判断
let extName = file.name.substring(file.name.lastIndexOf('.')).toLowerCase()
if (AllImgExt !== extName) {
this.$message.error('文件格式不正确')
this.$refs.file.value = ''
return false
}
this.uploaded = false
this.fileData = file
},
handleUploadFile(){
if(!this.fileData.size) return this.$message({
message:'请上传文件',
type: 'error',
customClass: 'msgHierarchy'
});
if(this.uploaded){
if(this.errorFileInfo.effectiveSize<=0){
this.$message({
message:'有效合同号为0',
type: 'error',
customClass: 'msgHierarchy'
})
this.fileData = {}
}else{
this.clearData()
}
this.uploaded = false
return false
}
const file = this.fileData
const reader = new FileReader()
reader.readAsDataURL(file)
reader.onload = event => {
const imgFile = event.target.result
const arrBase64 = imgFile.split(',')
const fileName = file.name.split('.')
//fileUrl: 文件名 + @ + base64拼接
const fileUrl = fileName.pop() + '@' + arrBase64[1]
const loading = this.$loading({
lock: true,
text: 'Loading',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.3)'
})
this.$apis.addCode.uploadCodeFile({ file: fileUrl }).then(res => {
loading.close()
if(res?.batchNo) {
this.$message({
message:'生成核销码成功',
type: 'success',
customClass: 'msgHierarchy'
})
this.errorFileInfo = res
this.uploaded = true
}
this.$refs.file.value = ''
}).catch(err =>{
loading.close()
})
}
},
// 下载错误的合同号
handleExport() {
const params = {
batchNo: this.errorFileInfo.batchNo,
codeStatus: 0
}
this.$apis.addCode.exportInvalidClaimsCodeApi(params).then(res => {
// window.open(res)
let tempaa = util.getExplorer()
if (tempaa == 'QQ') {
window.open(res)
} else {
let iframe = document.createElement('iframe')
iframe.style.display = 'none'
iframe.src = res
document.body.appendChild(iframe)
}
})
},
createCode() {
this.uploaded = false
this.isVisible = true
},
onOk(){
if(this.addType==1){
this.formatContractNo()
if(this?.contractNoList?.length>20){
return this.$message({
message:'最多输入20个合同号',
type: 'error',
customClass: 'msgHierarchy'
})
}
const params = {
contractNoList: this.contractNoList.map(item => item.val)
}
const loading = this.$loading({
lock: true,
text: 'Loading',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.3)'
})
this.$apis.addCode.createCode(params).then(res => {
loading.close()
if(res?.batchNo){
if(res?.invalidList?.length){
this.$message({
message:'存在无效合同',
type: 'error',
customClass: 'msgHierarchy'
})
this.errorNoList = res?.invalidList || []
this.contractNoList.map(item =>{
if(res?.invalidList?.includes(item.val)){
item.valid = true
}
return item
})
this.requestTip = true
}else{
this.clearData()
this.$message.success('操作成功')
}
}
}).catch(err =>{
loading.close()
})
}else{
this.handleUploadFile()
}
},
clearData(){
this.isVisible = false
this.requestTip = false
this.contractNoStr = ''
this.addType = 1
this.contractNoList = [],
this.errorNoList = []
this.errorFileInfo = {}
this.fileData = {}
this.handleRest()
},
handleClose() {
if(this.addType==1){
this.clearData()
}else{
this.$confirm('确定关闭弹窗吗', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
callback: action => {
if (action == 'confirm') {
this.clearData()
}
}
})
}
},
changeAddMethod(type) {
this.addType = type
}
}
}
</script>
<style lang="scss" scoped>
.container {
background-color: #fff;
padding: 20px;
.dialog_wrap {
.label_class {
display: inline-block;
width: 154px;
text-align: right;
&::before {
content: '*';
color: #f56c6c;
margin-right: 4px;
}
}
.manual {
margin-top: 10px;
.contract_input {
margin-left: 154px;
width: 432px;
/deep/ .el-textarea__inner {
width: 432px;
height: 79px;
border: 1px solid #e5e5e5;
border-radius: 4px;
font-family: unset;
}
}
.textarea_tip{
margin-left: 154px;
font-weight: 400;
font-size: 12px;
color: red;
margin-top: 10px;
}
.contract_area{
margin-top: 10px;
width: 600px;
max-height: 340px;
overflow-y: auto;
margin-left: 60px;
.contract_item{
height: 26px;
width: 280px;
white-space: nowrap;
display: inline-flex;
justify-content: space-between;
align-items: center;
padding: 0 8px;
background: #fafbfe;
border: 1px solid #E8E8EA;
border-radius: 4px;
color: #666666;
margin: 0 10px 8px 0;
box-sizing: border-box;
}
.valid {
background: #fff1f0;
border: 1px solid #ffa39e;
color: #ff4d4f;
}
}
}
.import {
.upload_wrap {
// display: flex;
margin-left: 154px;
margin-top: 10px;
.upload_btn {
display: flex;
.preview {
margin-left: 8px;
position: relative;
.example{
width: 160px;
height: 64px;
}
span {
line-height: 32px;
height: 32px;
color: #5850ff;
cursor: pointer;
}
}
}
.file_name {
width: 320px;
height: 26px;
line-height: 26px;
background: #f5f7fa;
border-radius: 4px;
margin-top: 8px;
padding: 0 12px;
}
}
.file_info {
border: 1px solid #e5e5e5;
border-radius: 4px;
padding: 20px 0;
margin-top: 32px;
display: flex;
flex-direction: column;
align-items: center;
.file_num {
display: flex;
width: 100%;
.num_wrap {
flex: 1;
text-align: center;
&:first-child{
border-right: 1px solid #e5e5e5;
}
.num {
display: block;
height: 32px;
font-family: Helvetica-Bold;
font-weight: 700;
font-size: 26px;
color: #2cca74;
text-align: center;
line-height: 32px;
}
.title {
margin-top: 4px;
display: block;
height: 20px;
line-height: 20px;
font-family: PingFangSC-Regular;
font-weight: 400;
font-size: 14px;
color: #333333;
}
.invalid {
color: #eb4e4e;
}
.download {
margin-left: 4px;
color: #5850ff;
cursor: pointer;
}
}
}
.tip_txt{
width: 536px;
margin-top: 16px;
font-size: 14px;
color: #333333;
line-height: 20px;
background: #F5F7FA;
padding: 8px 16px;
.tip_title{
color: #666666;
}
}
}
}
}
.cno_input {
width: 200px;
}
.edit,
.del {
cursor: pointer;
margin-left: 4px;
}
}
</style>