importTwo.vue
21.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
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
696
697
698
699
<!-- 导入明细&回单 第二步 -->
<template>
<d2-container>
<div class="infoDiv">
<div class="imgCon">
<img src="../image/twoStep.png"
class="imgSize">
</div>
<div class="describe">
<p class="describe-title">提示</p>
<p class="describe-text">
共导入{{ taskInfo.detailResultTotalCount }}条流水明细,成功{{ taskInfo.detailResultSuccessCount }}条,失败{{ taskInfo.detailResultFailCount }}条。<el-button
type="text"
v-if="taskInfo.detailResultFailUrl"
@click="downloadFailList">下载失败列表</el-button>
</p>
<p class="describe-text"
v-if="taskInfo.receiptResultSuccessCount != 0">
共导入{{ taskInfo.receiptResultSuccessCount }}条回单,成功关联{{ receiptCount }}条,可通过筛选项查询具体数据。</p>
<p class="describe-text-red"
v-if="taskInfo.receiptResultSuccessCount != 0">*
注:回单成功关联数据,使用导入明细为基础二次匹配,因此列表筛选结果与提示数可能不一致,为正常情况;手动上传回单时,需符合回单命名规则且为单文件。
</p>
</div>
<div class="footer">
<el-button @click="routerBack">上一步</el-button>
<el-button @click="submitForm"
type="primary"
:loading="$store.state.d2admin.loading.value">下一步</el-button>
</div>
</div>
<div class="d2-container-content">
<d2-search ref="showSearch"
class="show-search"
:search-form="searchForm"
:label-width="labelWidth"
:form-data="showFormData">
</d2-search>
<d2-table ref="recordTable"
:table-data="tableData"
:has-page="false"
:search-form="searchFormSearch"
:table-params="tableParams">
<div slot="absHtml"
slot-scope="scope">
<span>
<el-tooltip class="item"
effect="dark"
:content="scope.scope.detail.abs"
placement="right">
<span>
{{ scope.scope.detail.abs ? (scope.scope.detail.abs.length > 15 ? (scope.scope.detail.abs.slice(0, 15) + '...') : scope.scope.detail.abs) : '' }}
</span>
</el-tooltip>
</span>
</div>
<div slot="auth-button-other"
slot-scope="scope">
<!-- 删除 -->
<span>
<el-button type="text"
size="small"
@click="deleteRow(scope.scope)">删除</el-button>
</span>
<!-- 查看回单 -->
<span style="margin-left: 10px;"
v-if="scope.scope.receipt">
<el-button type="text"
size="small"
@click="handleReceipt(scope.scope)">查看回单</el-button>
</span>
<!-- 更新回单 -->
<span style="margin-left: 10px;"
v-if="scope.scope.receipt">
<el-button type="text"
size="small"
@click="handleImportReceipt(scope.scope)">更新回单</el-button>
</span>
<!-- 上传回单 -->
<span style="margin-left: 10px;"
v-if="!scope.scope.receipt">
<el-button type="text"
size="small"
@click="handleImportReceipt(scope.scope)">上传回单</el-button>
</span>
</div>
</d2-table>
<el-pagination background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="page.currentPage"
:page-sizes="[10,20,30,40]"
:page-size="page.pageSize"
:total="total"
layout="sizes,total,->,prev,pager,next,jumper" />
</div>
<d2-dialog :title="'回单上传'"
:is-visible="fileVisible"
@closeDialog="handleImport"
@confirmDialog="handleConfirmImport">
<slot>
<el-form :model="fileForm"
ref="fileRuleForm"
:rules="fileRules"
label-width="120px">
<el-form-item label="导入文件:"
prop="fileName">
<el-col :span="16">
<el-input readonly
v-model="fileForm.fileName" />
</el-col>
<el-col :span="4"
class="m-l-md">
<el-button class="import-btn">
导入文件
<input type="file"
id="fileUpload"
class="import-input"
accept="application/pdf"
@change="importFile($event)">
</el-button>
</el-col>
</el-form-item>
</el-form>
</slot>
</d2-dialog>
</d2-container>
</template>
<script>
import { Util, deepClone } from '@/common/util'
import { mapActions, mapState, mapMutations } from 'vuex'
import { cdSignOpt, receiptStatusOpt, associationOpt } from '@/common/constants.js'
import { receiptImport, association, saveAssociation, getImportTask } from '@api/theAssetData'
import alyOss from '@/common/oss.js'
export default {
name: 'ImportTwo',
props: {
taskInfo: {
type: Object,
default: () => { }
}
},
components: {
},
data() {
return {
userInfo: this.$store.state.d2admin.user.info,
labelWidth: '100px',
searchForm: {
jdSync: ''
},
searchFormSearch: {},
showFormData: [{
label: '关联状态',
name: 'jdSync',
type: 'select',
isClear: true,
optionList: [],
optionId: 'confId',
optionLabel: 'confValue',
optionsName: 'jdSyncOpt',
changeAttr: (value, targetItem) => {
console.log("this.allData", this.allData)
if (['', null].includes(value)) {
this.filterData = null
this.filterFlag = false // 关闭过滤
} else {
this.filterFlag = true // 开启过滤
if (value == 0) {
this.tableData = this.allData.filter(item => !item.receipt)
this.filterData = this.allData.filter(item => !item.receipt)
} else if (value == 1) {
this.tableData = this.allData.filter(item => item.receipt)
this.filterData = this.allData.filter(item => item.receipt)
}
}
console.log("this.tableData", this.tableData)
this.page.currentPage = 1
this.paginatedData() // 重新计算分页数据
}
}],
// getListApi: nbcbAccDetailPage,
tableParams: {
btnId: new Date().getTime() + parseInt(Math.random() * 1000),
listName: 'list',
tableOption: { width: '200px' },
tableColumns: [{
label: '本方户名',
prop: 'accName',
width: '250px',
formatter: (cellValue) => {
return cellValue?.detail?.accName || '-'
}
}, {
label: '本方账号',
prop: 'bankAcc',
width: '200px',
formatter: (cellValue) => {
return cellValue?.detail?.bankAcc || '-'
}
}, {
label: '对方户名',
prop: 'oppAccName',
width: '250px',
formatter: (cellValue) => {
return cellValue?.detail?.oppAccName || '-'
}
}, {
label: '对方账号',
prop: 'oppAccNo',
width: '200px',
formatter: (cellValue) => {
return cellValue?.detail?.oppAccNo || '-'
}
}, {
label: '收入',
prop: 'amt',
width: '150px',
formatter: (cellValue) => {
const cdSign = cellValue?.detail?.cdSign
let amtShow = '-'
if (cdSign == 0) {
amtShow = cellValue?.detail?.amt.toLocaleString()
}
return amtShow
}
}, {
label: '支出',
prop: 'amt',
width: '150px',
formatter: (cellValue) => {
const cdSign = cellValue?.detail?.cdSign
let amtShow = '-'
if (cdSign == 1) {
amtShow = cellValue?.detail?.amt.toLocaleString()
}
return amtShow
}
}, {
label: '账户余额',
prop: 'bal',
width: '150px',
formatter: (cellValue) => {
return cellValue?.detail?.bal.toLocaleString() || '-'
}
}, {
label: '交易时间',
prop: 'transTime',
width: '160px',
formatter: (cellValue) => {
return cellValue?.detail?.transTime ? Util.dateFormate(cellValue?.detail?.transTime, 'YYYY-MM-DD HH:mm:ss') : '-'
}
}, {
label: '币种',
prop: 'curCode',
width: '120px',
formatter: (cellValue) => {
return cellValue?.detail?.curCode || '-'
}
}, {
label: '备注',
prop: 'abs',
width: '200px',
addHtml: "absHtml"
}, {
label: '关联状态',
prop: 'jdSync',
width: '100px',
formatter: (cellValue) => {
const jdSync = cellValue.receipt ? 1 : 0
return this.baseData.jdSyncOpt.find(item => item.confId === jdSync)?.confValue
},
className: (cellValue) => {
const jdSync = cellValue.receipt ? 1 : 0
return {
0: 'redSpot',
1: 'greenSpot'
}[jdSync]
}
}
]
},
baseData: {
accNameList: [],
bankTypeList: [],
bankAccList: [],
bankNameList: [],
curCodeList: [],
cdSignOpt: deepClone(cdSignOpt),
jdSyncOpt: [
{ confId: 0, confValue: "未关联" },
{ confId: 1, confValue: "已关联" }
],
receiptStatusOpt: deepClone(receiptStatusOpt),
associationOpt: deepClone(associationOpt)
},
fileVisible: false,
fileForm: {},
fileRules: {
fileName: [{ required: true, message: '请上传文件', trigger: 'change' }]
},
receiptCount: 0,
allData: [], // 从后端获取的所有数据
tableData: [], // 当前展示的数据
filterData: [], // 当前筛选的数据
filterFlag: false, // 代表是否过滤
currentRow: null,
total: 0,
page: {
currentPage: 1,
pageSize: 10
}
}
},
computed: {
...mapState({
dowloadList: (state) => state.d2admin.user.dowloadList
})
},
mounted() {
console.log('taskInfo', this.taskInfo)
this.getBaseData()
this.getImportTask()
},
methods: {
...mapActions({
get: 'd2admin/base/get',
close: 'd2admin/page/close'
}),
...mapActions('d2admin/user', ['actionSetDownloadList']),
...mapMutations("d2admin/user", ["setTaskIdRefesh"]),
async getBaseData() {
this.getOptionsList()
},
getOptionsList() {
this.showFormData.forEach((item, index) => {
if (item.type === 'select') {
if (
this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this.showFormData[index].optionLabel] !== '全部'
) {
const temp = {}
temp[this.showFormData[index].optionId] = ''
temp[this.showFormData[index].optionLabel] = '全部'
this.baseData[item.optionsName].unshift(temp)
}
this.$set(
this.showFormData[index],
'optionList',
this.baseData[item.optionsName]
)
}
})
},
getImportTask() {
getImportTask({ taskId: this.taskInfo.taskId }).then(res => {
if (res) {
if (res.taskStatus == 3) { // 任务过期
this.$message({
message: "当前任务已过期,请重新导入",
type: "warning",
showClose: true
})
} else {
this.association()
}
}
})
},
association() {
association({ taskId: this.taskInfo.taskId }).then(res => {
this.allData = deepClone(res)
this.paginatedData()
this.statReceiptCount(res)
})
},
// 前端处理数据分页
paginatedData() {
console.log('filterData', this.filterData)
const start = (this.page.currentPage - 1) * this.page.pageSize
const end = start + this.page.pageSize
if (this.filterData && this.filterData.length > 0) { // 筛选时以筛选的数据进行分页
this.tableData = this.filterData.slice(start, end)
this.total = this.filterData.length
} else {
if (this.filterFlag) { // 过滤后的结果为空时
this.tableData = []
this.total = 0
} else {
this.total = this.allData.length
this.tableData = this.allData.slice(start, end)
}
}
console.log('this.tableData', this.tableData)
return this.tableData
},
// 统计回单关联数
statReceiptCount(records) {
this.receiptCount = records.filter(item => item.receipt).length
},
// 每页条数
handleSizeChange(value) {
this.page.pageSize = value
this.paginatedData() // 重新计算分页数据
},
handleCurrentChange(newPage) {
this.page.currentPage = newPage // 更新当前页码,触发计算属性重新计算paginatedData
this.paginatedData() // 重新计算分页数据
},
handleReceipt(row) {
window.open(row.receipt.pdfUrl)
},
deleteRow(row) {
this.$confirm('请确认是否要删除?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
closeOnClickModal: false
}).then(() => {
// 删除展示数组中对应的数据
const index = this.tableData.findIndex(item => item == row)
if (index !== -1) {
this.tableData.splice(index, 1)
}
// 删除原始数组中对应的数据
const index2 = this.allData.findIndex(item2 => item2 == row)
if (index2 !== -1) {
this.allData.splice(index2, 1)
}
console.log('删除后this.tableData', this.tableData)
console.log('删除后this.allData', this.allData)
this.paginatedData() // 重新计算分页数据
}).catch(err => {
console.log(err)
})
},
handleImportReceipt(row) {
this.currentRow = row
console.log('this.currentRow', this.currentRow)
this.fileVisible = true
},
// 上传文件,转码为base64
importFile(e) {
const size = e.target.files[0].size / 1024 / 1024
if (size < 10) {
this.$set(this.fileForm, '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.fileInfo = e.target.files[0].name.split('.')[e.target.files[0].name.split('.')?.length - 1] + '@' + arrBase64[1]
// document.getElementById('fileUpload').value = ''
// }
this.fileInfo = e.target.files[0]
} else {
this.notice.errorTips('上传文件不可超过10M')
}
document.getElementById('fileUpload').value = ''
},
handleImport() {
this.fileForm = {
fileName: ''
}
this.fileVisible = !this.fileVisible
},
handleConfirmImport() {
this.$refs.fileRuleForm.validate(valid => {
if (valid) {
// var params = {
// file: this.fileInfo,
// fileName: this.fileForm.fileName,
// fileType: this.fileForm.fileName.substr(this.fileForm.fileName.lastIndexOf('.') + 1)
// }
// receiptImport(params).then(res => {
// console.log('res', res)
// if (res && res.data && res.data.length > 0) {
// this.notice.okTips('上传成功')
// this.handleImport()
// this.tableData.find(item => item === this.currentRow).receipt = res.data[0]
// this.allData.find(item => item === this.currentRow).receipt = res.data[0]
// // this.statReceiptCount(this.allData) // 重新统计关联数
// console.log('this.tableData', this.tableData)
// }
// })
const bucketName = 'zzl-filerepostorypublic' // 桶名
const file = this.fileInfo
const fileType = this.fileForm.fileName.substr(this.fileForm.fileName.lastIndexOf('.') + 1)
alyOss.bucketUpload(
file,
(res) => {
var params = {
fileUrl: res.aliyunAddress,
fileName: res.attachment,
fileType: res.attachment.substr(res.attachment.lastIndexOf('.') + 1)
}
receiptImport(params).then(res => {
console.log('res', res)
if (res && res.data && res.data.length > 0) {
this.notice.okTips('上传成功')
this.handleImport()
this.tableData.find(item => item === this.currentRow).receipt = res.data[0]
this.allData.find(item => item === this.currentRow).receipt = res.data[0]
// this.statReceiptCount(this.allData) // 重新统计关联数
console.log('this.tableData', this.tableData)
}
})
},
(err) => {
console.log(err)
this.btLoading = false
},
bucketName,
fileType
)
}
})
},
routerBack() {
this.$confirm('当前操作会删除已导入数据,是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
closeOnClickModal: false
}).then(() => {
this.setTaskIdRefesh('')// 返回上一步时,清空taskId,销毁任务
this.$emit('goBackOneStep')
}).catch(err => {
console.log(err)
})
},
submitForm() {
this.$confirm('请确认是否要执行关联操作?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
closeOnClickModal: false
}).then(() => {
var params = {}
params.taskId = this.taskInfo.taskId
params.associationData = this.allData
console.log('params', params)
if (params.associationData.length == 0) {
this.$message({
message: "暂无数据,请重新导入",
type: "warning",
showClose: true
})
return false
}
for (const key in params.associationData) {
console.log('params.associationData[key]', params.associationData[key])
const detail = params.associationData[key].detail
const receipt = params.associationData[key].receipt
// 去除为null的值
for (const key in detail) {
if (detail[key] === null || detail[key] === '' || detail[key].length == 0) {
delete detail[key]
}
}
if (receipt) {
for (const key in receipt) {
if (receipt[key] === null || receipt[key] === '' || receipt[key].length == 0) {
delete receipt[key]
}
}
} else {
delete params.associationData[key].receipt
}
}
saveAssociation(params).then(res => {
this.setTaskIdRefesh('')// 任务完成,清空taskId,销毁任务
this.$emit('twoStepComplete', res)
})
}).catch(err => {
console.log(err)
})
},
downloadFailList() {
if (this.taskInfo.detailResultFailUrl) {
this.downLoadFile(this.taskInfo.detailResultFailUrl)
} else {
this.$message({
message: "无失败列表",
type: "warning",
showClose: true
})
}
},
/**
* url下载文件
*
*/
downLoadFile: function (url) {
const Temp = document.createElement("a")
Temp.href = url
document.body.append(Temp)
Temp.click()
document.body.removeChild(Temp)
}
}
}
</script>
<style scoped>
.count-txt {
font-weight: 700;
color: #2a58ad;
margin: 0 2px;
}
.leftSpan {
display: inline-block;
box-sizing: border-box;
margin-right: 10px;
}
.tableHeaderBtn {
margin-left: 10px;
}
.infoDiv {
width: 100%;
height: 400px;
background-color: #fff;
}
.imgCon {
text-align: center;
/* margin-bottom: 50px; */
}
.imgSize {
width: 1200px;
}
.describe {
border-radius: 4px;
opacity: 1;
background: #fafafa;
width: 98%;
height: 210px;
margin: 0 auto 20px;
.describe-title {
font-size: 16px;
font-weight: 600;
padding: 16px 0 0 20px;
}
.describe-text {
font-size: 14px;
padding-left: 20px;
color: #333333;
}
.describe-text-red {
font-size: 14px;
padding-left: 20px;
color: #eb4e4e;
}
}
.footer {
text-align: center;
/* margin-bottom: 40px; */
}
.m-l-md {
margin-left: 20px;
}
.import-btn {
position: relative;
}
.import-input {
opacity: 0;
position: absolute;
right: 0;
top: 0;
width: 98px;
height: 36px;
cursor: pointer;
font-size: 0;
}
</style>