ReceivePayEditDialog.vue
18.4 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
<template>
<div>
<d2-dialog :title="billTypeStr == 'receive' ? '应收单详情' : '应付单详情'" :is-visible="billVisible" class="privacyDailog" width="80%" btnOkLabel="关闭" noCancel="true" @closeDialog="handleClose" @confirmDialog="handleConfirm">
<div class="flex">
<div v-if="tableList.length">适用对象:{{ billTypeStr == 'receive' ? tableList[0].customerName: tableList[0].supplierIdName }}</div>
<div v-if="pageType != 'detail'">
<el-button @click="handleAdd">新增详情</el-button>
<el-button @click="handlePushToJd">推送金蝶</el-button>
</div>
</div>
<d2-table ref="jdBillTable" :table-data="tableList" :table-params="tableParams" :hasNum="false" :table-total="page.total" @refreshTable="pageChange">
<div slot="edit" slot-scope="scope">
<div class="flex-center">
<div :class="[hasError(scope.scope, scope.prop) ? 'red-txt' : '']">{{ scope.scope[scope.prop] }}</div>
<img src="@/assets/icon-edit.png" style="cursor: pointer;margin-left: 5px;width: 16px;height: 16px;" v-if="pageType != 'detail'" @click="handleEditTableItem(scope.index, scope.scope, scope.prop)" />
</div>
</div>
</d2-table>
<!-- 手动添加 -->
<div style="margin-top: 20px;">{{ billTypeStr == 'receive' ? '新增应收明细' : '新增应付明细' }}</div>
<d2-table ref="userTable" :table-data="userTableList" :table-params="userTableParams" :hasNum="false" :hasPage="false">
<div slot="edit" slot-scope="scope">
{{ scope.scope[scope.prop] }}
</div>
<div slot="auth-button" slot-scope="scope">
<el-button type="text" v-if="pageType != 'detail'" @click="handleDelete(scope.scope)">删除</el-button>
</div>
</d2-table>
<!-- 操作日志 -->
<div style="margin-top: 20px;">操作日志</div>
<d2-table ref="logTable" :table-data="logTableList" :table-params="logTableParams" :hasNum="false" :hasPage="false">
</d2-table>
</d2-dialog>
<add-detail-dialog v-if="addVisible" :addVisible="addVisible" :info="info" @handleConfirm="handleAddConfirm" @dialogClose="handleAddVisible"></add-detail-dialog>
<!-- 批量輸入 -->
<d2-dialog :title="'编辑' + headObj.fieldName" :is-visible="batchVisible" class="privacyDailog" width="480px" @closeDialog="handleBatchClose" @confirmDialog="handleBatchConfirm">
<div class="batch-box">
<!-- 输入框 -->
<template v-if="headObj.editType == 'input'">
<el-input placeholder="请输入" :prefix-icon="headObj.prefixIcon" v-model.trim="batchForm[headObj.fieldCode]" :maxlength="headObj.maxlength" :type="headObj.inputType || 'text'" :style="{ width: headObj.width || defaultWidth }" :class="{ 'is-error': dialogErrors[headObj.fieldCode] }">
<span v-if="headObj.editObj.prepend" slot="prepend">{{ headObj.editObj.prepend }}</span>
<span v-if="headObj.editObj.append" slot="suffix">{{ headObj.append }}</span>
</el-input>
<div v-if="dialogErrors[headObj.fieldCode]" class="el-form-item__error">{{ dialogErrors[headObj.fieldCode] }}</div>
</template>
<!-- 选择框 -->
<div v-else-if="headObj.editType == 'select'">
<el-select style="width: 500px" v-model="batchForm[headObj.fieldCode]" placeholder="请选择" no-data-text="无数据" filterable remote reserve-keyword :class="{ 'is-error': dialogErrors[headObj.fieldCode] }" @change="handleSelectChange" @focus="remoteMethod" :remote-method="(event) => remoteMethod(event)" v-el-select-loadmore="interestsLoadmoreMerchant">
<el-option v-for="k in baseData[headObj.editObj.optionsName]" :key="k[headObj.editObj.optionId]" :label="k[headObj.editObj.optionLabel]" :value="k[headObj.editObj.optionId]"></el-option>
</el-select>
<div v-if="dialogErrors[headObj.fieldCode]" class="el-form-item__error">{{ dialogErrors[headObj.fieldCode] }}</div>
</div>
</div>
</d2-dialog>
</div>
</template>
<script>
import { deepClone, Util } from '@/common/util'
import * as api from '@api/accountManage'
import { getJdDetailPage, editBillPage, getJdBillLog } from '@api/accountManage'
import { payTypeList } from "@/common/constants"
import { receiveTableColumns, payTableColumns } from "../constant/receivePayData"
import AddDetailDialog from './AddDetailDialog.vue'
export default {
name: 'ReceivePayEditDialog',
props: {
billVisible: {
type: Boolean,
default: false
},
jdBillInfo: {
type: Object,
default: () => ({})
}
},
components: {
AddDetailDialog
},
data() {
return {
loading: false,
// 页面类型;edit: 编辑页面,edetail: 查看
pageType: 'edit',
billTypeStr: 'receive',
addVisible: false,
info: {},
linkAttrList: ['customerName', 'supplierIdName', 'materialCodeName'],
// 列表数据
tableList: [],
tableParams: {
btnId: new Date().getTime() + parseInt(Math.random() * 1000),
listName: "list",
tableOption: false,
tableColumns: []
},
// 分页
page: {
pageNum: 1,
pageSize: 10,
total: 0
},
// 用户自行添加的对账信息
userTableList: [],
userTableParams: {
btnId: new Date().getTime() + parseInt(Math.random() * 2000),
listName: "list",
tableOption: true,
tableColumns: []
},
// 操作日志
logTableList: [],
logTableParams: {
btnId: new Date().getTime() + parseInt(Math.random() * 3000),
listName: "list",
tableOption: false,
tableColumns: [
{
label: '操作项',
prop: 'operationType',
formatter: (cellValue) => {
return this.baseData.operationTypeOpt.find(item => item.confId == cellValue.operationType)?.confValue
}
},
{ label: '操作时间', prop: 'createdDate' },
{ label: '操作结果', prop: 'oprResult' },
{ label: '操作人', prop: 'createdBy' }
]
},
headObj: {},
batchForm: {},
batchField: '',
batchCurrentPage: 1,
batchName: '',
batchIsEnd: false,
batchVisible: false,
dialogErrors: {},
baseData: {
customerOpt: [],
settlementOrgOpt: [],
rcvOrgOpt: [],
operationTypeOpt: [{
confId: '0',
confValue: '生成账单'
}, {
confId: '1',
confValue: '编辑明细'
}, {
confId: '2',
confValue: '新增明细'
}, {
confId: '3',
confValue: '删除明细'
}, {
confId: '4',
confValue: '推送金蝶'
}]
},
defaultWidth: '180px'
}
},
mounted() {
this.initComponent()
},
directives: {
"el-select-loadmore": {
bind(el, binding) {
const SELECTWRAP_DOM = el.querySelector(
".el-select-dropdown .el-select-dropdown__wrap"
)
SELECTWRAP_DOM.addEventListener("scroll", function () {
const condition =
this.scrollHeight - this.scrollTop <= this.clientHeight
if (condition) {
binding.value()
}
})
}
}
},
methods: {
initComponent() {
this.billTypeStr = this.jdBillInfo.billType == '3' ? 'receive' : 'pay'
console.log(this.jdBillInfo, 'this.jdBillInfo---')
this.pageType = this.jdBillInfo.pushStatus == '1' ? 'detail' : 'edit'
this.tableParams.tableColumns = this.jdBillInfo.billType == '3' ? deepClone(receiveTableColumns) : deepClone(payTableColumns)
this.userTableParams.tableColumns = this.jdBillInfo.billType == '3' ? deepClone(receiveTableColumns) : deepClone(payTableColumns)
this.getBillList()
this.getUserTableList()
this.getJdBillLog()
},
getJdBillLog() {
const params = {
id: this.jdBillInfo.id,
currentPage: 1,
pageSize: 999
}
getJdBillLog(params).then(res => {
this.logTableList = res || []
})
},
pageChange(page) {
this.page.pageNum = page.currentPage
this.page.pageSize = page.pageSize
this.getBillList()
},
getUserTableList() {
const params = {
billId: this.jdBillInfo.id,
manual: true,
currentPage: 1,
pageSize: 999
}
this.loading = true
getJdDetailPage(params).then(res => {
this.userTableList = res.list || []
}).finally(() => {
this.loading = false
})
},
getBillList() {
this.tableList = []
const params = {
billId: this.jdBillInfo.id,
manual: false,
currentPage: this.page.pageNum,
pageSize: this.page.pageSize
}
this.loading = true
getJdDetailPage(params).then(res => {
console.log(res, 'getJdDetailPage res---')
this.tableList = res.list || []
this.page.pageNum = res.pageNum || 1
this.page.pageSize = res.pageSize || 10
this.page.total = res.total || 0
}).finally(() => {
this.loading = false
})
},
handleAdd() {
console.log(this.jdBillInfo, 'this.jdBillInfo---')
this.info = {
billTypeStr: this.billTypeStr,
billId: this.tableList[0].billId
}
this.handleAddVisible()
},
handleAddVisible() {
this.addVisible = !this.addVisible
},
handleAddConfirm() {
this.handleAddVisible()
this.getBillList()
this.getUserTableList()
this.getJdBillLog()
},
handlePushToJd() {
this.$confirm('请确认是否要执行当前操作?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
const params = {
id: this.jdBillInfo.id
}
this.loading = true
api.push2Jd(params).then(res => {
console.log(res, 'push2Jd res---')
res ? this.$message.success("推送金蝶成功") : this.$message.error("推送金蝶失败")
this.getJdBillLog()
if (res) {
this.pageType = 'detail'
}
}).finally(() => {
this.loading = false
})
}).catch(() => { })
},
findIdx(field) {
return this.tableParams.tableColumns.findIndex(item => item.prop === field)
},
hasError(row, field) {
const idx = this.findIdx(field)
const isMarkRed = this.tableParams.tableColumns[idx].isMarkRed
const labelName = this.tableParams.tableColumns[idx].labelName
if (!isMarkRed) {
return false
}
return row[labelName] === undefined || row[labelName] === null || row[labelName] === ''
},
handleEditTableItem(rowIndex, row, field) {
// 必须选了结算组织之后,才能编辑的字段(客户,供应商,物料)
if (this.linkAttrList.includes(field)) {
const settlementOrgIdx = this.findIdx('settlementOrg')
if (settlementOrgIdx != -1 && (!row[this.tableParams.tableColumns[settlementOrgIdx].labelName] || row[this.tableParams.tableColumns[settlementOrgIdx].labelName] == '')) {
this.$message.error("请先选择结算组织")
return
}
}
const idx = this.findIdx(field)
const obj = this.tableParams.tableColumns[idx]
this.batchCurrentPage = 1
this.batchName = ''
this.batchIsEnd = false
this.batchField = field
this.headObj = {
rowIndex: rowIndex,
fieldName: obj.label,
editType: obj.editType,
fieldCode: obj.editType == 'select' ? obj.labelName : obj.prop,
editObj: {}
}
this.$set(this.batchForm, this.headObj.fieldCode, row[this.headObj.fieldCode])
if (this.headObj.editType == 'select') {
this.headObj.editObj.optionId = obj.optionId
this.headObj.editObj.optionLabel = obj.optionLabel
this.headObj.editObj.optionsName = obj.optionsName
this.headObj.labelName = obj.prop
this.$set(this.batchForm, obj.prop, row[obj.prop])
this.$set(this.baseData, this.headObj.editObj.optionsName, [])
}
console.log(this.batchForm, 'this.batchForm---')
if (this.headObj.editType == 'select') {
this.getOpt(obj.apiName, field)
} else {
this.handleBatchVisible()
}
},
getOpt(apiName, field) {
console.log(apiName, 'apiName---')
if (apiName) {
const params = {
currentPage: this.batchCurrentPage || 1,
pageSize: 999,
name: this.batchName || ''
}
// 客户,供应商,物料,请求需加结算组织字段
if (this.linkAttrList.includes(field)) {
params.useOrgNumber = this.tableList[0].settlementOrgCode
}
api[apiName](params).then(res => {
if (this.baseData[this.headObj.editObj.optionsName] && this.baseData[this.headObj.editObj.optionsName].length > 0) {
// 合并数据
this.$set(this.baseData, this.headObj.editObj.optionsName, this.baseData[this.headObj.editObj.optionsName].concat(res.list || []))
} else {
this.$set(this.baseData, this.headObj.editObj.optionsName, res.list || [])
}
if (res.list.length < 999) {
this.batchIsEnd = true
}
if (!this.batchVisible) {
this.handleBatchVisible()
}
})
}
},
handleDelete(row) {
console.log(row, 'row---')
const params = {
id: row.id
}
this.loading = true
api.deleteJdDetail(params).then(() => {
this.$message.success("删除成功")
this.getUserTableList()
this.getJdBillLog()
}).finally(() => {
this.loading = false
})
},
uniqueByProperty(arr, prop) {
return arr.filter((obj, index, self) =>
index === self.findIndex((o) => o[prop] === obj[prop])
)
},
// 获取数据
remoteMethod(query) {
this.batchName = query
this.batchCurrentPage = 1
this.batchIsEnd = false
this.$set(this.baseData, this.headObj.editObj.optionsName, [])
const idx = this.findIdx(this.batchField)
const obj = this.tableParams.tableColumns[idx]
this.getOpt(obj.apiName, this.batchField)
},
// 获取更多数据
interestsLoadmoreMerchant() {
setTimeout(() => {
if (this.batchIsEnd) {
return
}
this.batchCurrentPage = this.batchCurrentPage + 1
const idx = this.findIdx(this.batchField)
const obj = this.tableParams.tableColumns[idx]
this.getOpt(obj.apiName, this.batchField)
}, 10)
},
handleConfirm() {
this.$emit('handleClose')
},
handleClose() {
this.$emit('handleClose')
},
// 批量修改弹窗 - 验证表单
batchValidateForm() {
const value = this.batchForm[this.headObj.fieldCode]
this.dialogErrors = {}
let isValid = true
if (value === undefined || value === null || value === '') {
this.dialogErrors[this.headObj.fieldCode] = this.headObj.editType === 'select' ? '请选择' : '请输入'
isValid = false
}
if (this.headObj?.editObj?.rule) {
let errorTxt = this.headObj.editObj.rule(value, '', '', this.headObj.editType == 'selectInput' ? this.headObj : this.headObj.fieldCode, true)
if (errorTxt) {
isValid = false
if (this.headObj.editType === 'selectInput') {
this.dialogErrors[this.headObj.editObj.inputField] = errorTxt;
} else {
this.dialogErrors[this.headObj.fieldCode] = errorTxt;
}
return false
}
}
return isValid
},
handleSelectChange(val) {
this.batchForm[this.headObj.labelName] = this.baseData[this.headObj.editObj.optionsName].find(k => k[this.headObj.editObj.optionId] == val)?.[this.headObj.editObj.optionLabel] || ''
},
handleBatchVisible() {
this.batchVisible = !this.batchVisible
},
handleBatchClose() {
this.dialogErrors = {}
this.handleBatchVisible()
this.headObj = {}
},
handleBatchConfirm() {
console.log(this.headObj, 'this.headObj---')
this.updateJdDetail()
this.handleBatchVisible()
},
updateJdDetail() {
var params = deepClone(this.tableList[this.headObj.rowIndex])
if (this.headObj.editType == 'select') {
params[this.headObj.fieldCode] = this.batchForm[this.headObj.fieldCode]
params[this.headObj.labelName] = this.batchForm[this.headObj.labelName]
} else {
params[this.headObj.fieldCode] = this.batchForm[this.headObj.fieldCode]
}
console.log(params, 'params---')
this.loading = true
api.updateJdDetail(params).then(res => {
console.log(res, 'updateJdDetail res---')
this.getBillList()
this.getUserTableList()
this.getJdBillLog()
// this.$message.success("操作成功")
}).finally(() => {
this.loading = false
})
}
}
}
</script>
<style lang="scss" scoped>
.flex {
display: flex;
justify-content: space-between;
}
.el-form-item__error {
color: #f56c6c;
font-size: 12px;
line-height: 1;
padding-top: 4px;
position: relative;
top: 0;
left: 0;
}
.flex-center {
display: flex;
justify-content: center;
align-items: center;
}
.red-txt {
color: #f56c6c;
}
.is-error {
.el-input__inner {
border-color: #f56c6c;
}
}
.select-input-container {
position: relative;
.el-form-item__error {
position: static;
margin-top: 2px;
}
.input-with-select {
.el-select {
&.is-error {
.el-input__inner {
border-color: #f56c6c;
}
}
}
&.is-error {
.el-input-group__prepend {
.el-input__inner {
border-right-color: #f56c6c;
}
}
.el-input__inner {
border-left-color: #dcdfe6;
}
}
}
}
::v-deep .el-input__suffix .inputSuffix {
position: absolute;
left: -14px;
top: 8px;
// transition: all 0.3s;
}
.tb-header-cell {
box-sizing: border-box;
text-align: center;
white-space: nowrap;
display: inline-block; /* 或者 inline */
}
.tb-cell {
padding: 14px;
text-align: center;
}
::v-deep .el-table .cell {
text-align: center;
}
::v-deep .el-table__footer-wrapper tbody td {
padding: 14px;
text-align: center;
}
.total-box {
display: flex;
div {
flex: 1;
}
}
.batch-box {
margin: 10px 36px;
}
.red-txt {
color: #eb4e4e;
font-size: 14px;
margin: 8px 0;
}
</style>