PartBomList.vue
16.2 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
<template>
<a-modal
title="部件BOM"
:width="1600"
:visible="visible"
:confirmLoading="confirmLoading"
@ok="handleOk"
@cancel="handleCancel"
cancelText="关闭"
wrapClassName="ant-modal-cust-warp"
style="top:5%;height: 85%;overflow-y: hidden">
<a-card :bordered="false">
<!-- 查询区域 -->
<a-input v-model="parCno" style="width: 200px" placeholder="请输入部件编码"></a-input>
<a-button style="margin-left: 10px" @click="getCnoData()">查询</a-button>
<p3>项目名称:{{projectName}}</p3>
<a-table
:scroll="{x: scrollXWidth, y: 720}"
ref="table"
size="middle"
rowKey="id"
:columns="planColumns"
:dataSource="bomSource"
:pagination="false"
:loading="loading2"
:expandedRowKeys="expandedRowKeys"
:rowSelection="{selectedRowKeys: selectedRowKeys,onChange: selectChanges}"
@change="handleTableChange"
@expand="handleExpand"
v-bind="tableProps" >
</a-table>
<!-- table区域-end -->
<pbom-form ref="pbomForm"></pbom-form>
<materia-item-list ref="materiaFrom"></materia-item-list>
</a-card>
</a-modal>
</template>
<script>
import { JeecgListMixin } from '../../../mixins/JeecgListMixin'
import moment from 'moment'
import {ajaxGetDictItems, partList} from "../../../api/api";
import { getAction } from '@/api/manage'
import '@/assets/less/TableExpand.less'
export default {
name: 'PartBomList',
components: {},
mixins: [JeecgListMixin],
data() {
return {
allSoure:'',
parCno:'',
visible: false,
confirmLoading: false,
selectIndex: null,
queryParam: {},
description: '项目C表信息',
loading2:false,
scrollXWidth: 1800,
headerId:'',
// 表头
url: {
list:'1',
childList: "/working/working/childList",
},
// 展开的行,受控属性
expandedRowKeys: [],
dataSource: [],
bomSource: [],
pnoArray:[],
scolor:'',
pno:'',
pbom_status:'',
projectName:'',
/* 分页参数 */
ipagination:{
current: 1,
pageSize: 5,
pageSizeOptions: ['5', '10', '50'],
showTotal: (total, range) => {
return range[0] + "-" + range[1] + " 共" + total + "条"
},
showQuickJumper: true,
showSizeChanger: true,
total: 0
},
hasChildrenField:"hasChild",
pidField:"pno",
workNo:'',
field0057:'',
projectNo:'',
pno_arr:'',
uuid:'',
dictOptions:{
},
subExpandedKeys:[],
planColumns: [
{
title: '部件名称',
dataIndex: 'partName',
width: 100,
key: 'partName'
},
{
title: '部件编码',
dataIndex: 'cno',
width: 130,
key: 'cno'
},
{
title: '报工人数',
dataIndex: 'nums',
align: 'center',
width: 100,
key: 'nums'
}, {
title: '合格数量',
dataIndex: 'qty',
key: 'qty',
align: 'center',
width: 80
},
{
title: '总工时(小时)',
align: 'center',
dataIndex: 'hours',
scopedSlots:{
customRender:'departWorking'
}
},
{
title: '总工时(分钟)',
align: 'center',
dataIndex: 'time',
scopedSlots:{
customRender:'processWorking'
}
},
{
title: '重量(kg)',
align: 'center',
dataIndex: 'weight',
key: 'weight'
}
],
}
},
created() {
this.getOutSourceStatus()
this.getdata()
},
computed:{
tableProps() {
let _this = this
return {
// 列表项是否可选择
rowSelection: {
selectedRowKeys: _this.selectedRowKeys,
onChange: (selectedRowKeys) => _this.selectedRowKeys = selectedRowKeys
}
}
},
},
methods: {
edit (record) {
this.projectName=record.projectName
this.visible = true;
this.parCno=""
this.onSelectChangeByBoom(record)
this.allSoure=record
},
handleCancel () {
this.visible = false;
},
handleOk () {
this.visible = false;
},
getdata(){
let currColumns = this.planColumns
// res.result.columns表示接口获取的columns值,具体根据接口返回值修改
for(let a=0;a<currColumns.length;a++){
// 设置除最后一列的宽度,需要空一列自适应
if(a < currColumns.length-1) {
currColumns[a].width = 150;
}
}
console.log("-------------------",currColumns)
// 横向滚动长度大于所有宽度,才能实现固定表头
this.scrollXWidth = (currColumns.length) * 150 + 180;
this.planColumns = [...currColumns]
},
searchQuery() {
this.loadData(1);
this.bomSource=[];
},
rowClassName(record, index) {
return index === this.selectIndex ? 'Rowactive' : ''
},
getCnoData(){
this.onSelectChangeByBoom(this.allSoure)
},
onSelectChangeByBoom(data) {
this.headerId=data.headerId
this.loading2 = true
let params = {
'headerId':data.headerId,
'id':data.id,
'projectName': data.projectName,
'partName': data.partName,
'nums': data.nums,
'time': data.time,
'qty': data.qty,
'status1': data.status1,
'status2': data.status2,
'status3': data.status3,
'hours': data.hours,
'partNo': data.partNo,
'progress': data.progress,
'parCno':this.parCno
}
partList(params).then((res) => {
this.bomSource=[];
if (res.code==0||res.code==1) {
this.loading2 = false
this.bomSource=this.getDataByResult(res.result.records);
}else {
this.loading2 = false
this.bomSource=[];
this.$message.error(res.message)
}
})
},
timeFormat(val) {
return moment(val).format('YYYY-MM-DD')
},
handleExpandedRowsChange(expandedRows) {
this.expandedRowKeys = expandedRows
},
handleBomChange(value) {
this.initBomTree(value)
},
onSelectAll(selected) {
if (selected) {
const tabData = this.bomSource;
const arr = [];
setVal(tabData, arr);
this.selectedRowKeys = arr;
} else {
this.selectedRowKeys = [];
}
function setVal(list, arr) {
list.forEach(v => {
arr.push(v.key);
if (v.children) {
setVal(v.children, arr);
}
});
}
},
numFormat(qty){
if(qty==undefined){
return '';
}else{
return parseFloat(qty).toFixed(1);
}
},
onSelect(record, selected) {
const set = new Set(this.selectedRowKeys);
const tabData = this.bomSource;
const key = record.key;
if (selected) {
set.add(key);
record.children && setChildCheck(record.children);
// setParentCheck(key);
} else {
set.delete(key);
record.children && setChildUncheck(record.children);
setParentUncheck(key);
}
this.selectedRowKeys = Array.from(set);
// 设置父级选择
function setParentCheck(key) {
let parent = getParent(key);
if (parent) {
set.add(parent.key);
setParentCheck(parent.key);
}
}
// 设置父级取消,如果父级的子集有选择,则不取消
function setParentUncheck(key) {
let childHasCheck = false,
parent = getParent(key);
if (parent) {
let childlist = parent.children;
childlist.forEach(function(v) {
if (set.has(v.key)) {
childHasCheck = true;
}
});
if (!childHasCheck) {
set.delete(parent.key);
setParentUncheck(parent.key);
}
}
}
// 获取当前对象的父级
function getParent(key) {
for (let i = 0; i < tabData.length; i++) {
if (tabData[i].key === key) {
return null;
}
}
return _getParent(tabData);
function _getParent(list) {
let childlist,
isExist = false;
for (let i = 0; i < list.length; i++) {
if ((childlist = list[i].children)) {
childlist.forEach(function(v) {
if (v.key === key) {
isExist = true;
}
});
if (isExist) {
return list[i];
}
if (_getParent(childlist)) {
return _getParent(childlist);
}
}
}
}
}
// 设置child全选
function setChildCheck(list) {
list.forEach(function(v) {
set.add(v.key);
v.children && setChildCheck(v.children);
});
}
// 设置child取消
function setChildUncheck(list) {
list.forEach(function(v) {
set.delete(v.key);
v.children && setChildUncheck(v.children);
});
}
},
confirmHandle(record) {
var llqty=record.llqty;
if (llqty==undefined){
llqty='0';
}
var qty=record.qty;
if (qty==undefined){
qty='0';
}
var bnum=record.bnum;
if (bnum==undefined){
bnum='0';
}
var xnqty=parseInt(bnum)-parseInt(llqty)
var status='';
if (parseInt(llqty) >= parseInt(bnum)) {
status= '2';
} else {
if (parseInt(xnqty) <= parseInt(qty)) {
status= '1';
} else {
status= '0';
}
}
if(record.qty==undefined){
status='';
}
var actions = []
Object.keys(this.outsourcingInStatusList).some((key) => {
if (this.outsourcingInStatusList[key].value == ('' + status)) {
actions.push(this.outsourcingInStatusList[key].text)
return true
}
})
return actions.join('')
},
solutionColor(record) {
var llqty=record.llqty;
if (llqty==undefined){
llqty='0';
}
var qty=record.qty;
if (qty==undefined){
qty='0';
}
var bnum=record.bnum;
if (bnum==undefined){
bnum='0';
}
var xnqty=parseInt(bnum)-parseInt(llqty)
var status='';
if (parseInt(llqty) >= parseInt(bnum)) {
status= '2';
} else {
if (parseInt(xnqty) <= parseInt(qty)) {
status= '1';
} else {
status= '0';
}
}
var actions = ''
Object.keys(this.outsourcingInStatusList).some((key) => {
if (this.outsourcingInStatusList[key].value == ('' + status)) {
actions = this.outsourcingInStatusList[key].color
}
})
return actions
},
getOutSourceStatus() {
ajaxGetDictItems('bom_inv_status').then((res) => {
if (res.success) {
this.outsourcingInStatusList = res.result
}
})
},
getDataByResult(result){
return result.map(item=>{
//判断是否标记了带有子节点
if(item[this.hasChildrenField]=='1'){
let loadChild = { cno: item.cno+'_loadChild', name: 'loading...', isLoading: true }
item.children = [loadChild]
}
return item
})
},
handleExpand(expanded, record){
// 判断是否是展开状态id
if (expanded) {
this.expandedRowKeys.push(record.id)
if (record.children.length>0 && record.children[0].isLoading === true) {
// let params = this.getQueryParams();//查询条件
let params = {
"headerId":this.headerId,
"partNo":record.partNo,
"cno":record.cno,
"pno":record.cno,
// "parCno":this.parCno
};//查询条件
// params[this.pidField] = record.cno
// params['headerId'] = record.headerId
// params['partNo'] = record.partNo
// params['cno'] = record.cno
// params['cno'] = record.cno
getAction(this.url.childList,params).then((res)=>{
if(res.success){
if(res.result && res.result.length>0){
record.children = this.getDataByResult(res.result)
this.bomSource = [...this.bomSource]
}else{
record.children=''
record.hasChildrenField='0'
}
}else{
this.$message.warning(res.message)
}
})
}
}else{
let keyIndex = this.expandedRowKeys.indexOf(record.id)
if(keyIndex>=0){
this.expandedRowKeys.splice(keyIndex, 1);
}
}
},
// 添加子分类时获取所有父级id
getExpandKeysByPid(pid,arr,all){
if(pid && arr && arr.length>0){
for(let i=0;i<arr.length;i++){
if(arr[i].cno==pid){
this.subExpandedKeys.push(arr[i].cno)
this.getExpandKeysByPid(arr[i]['pid'],all,all)
}else{
this.getExpandKeysByPid(pid,arr[i].children,all)
}
}
}
},
getFormDataById(cno,arr){
if(arr && arr.length>0){
for(let i=0;i<arr.length;i++){
if(arr[i].cno==cno){
this.parentFormData = arr[i]
}else{
this.getFormDataById(cno,arr[i].children)
}
}
}
},
expandTreeNode(nodeId){
return new Promise((resolve,reject)=>{
this.getFormDataById(nodeId,this.bomSource)
let row = this.parentFormData
this.expandedRowKeys.push(nodeId)
let params = this.getQueryParams();//查询条件
params[this.pidField] = nodeId
getAction(this.url.childList,params).then((res)=>{
if(res.success){
if(res.result && res.result.length>0){
row.children = this.getDataByResult(res.result)
this.bomSource = [...this.bomSource]
resolve()
}else{
row.children=''
row.hasChildrenField='0'
reject()
}
}else{
reject()
}
})
})
},
// 根据已展开的行查询数据(用于保存后刷新时异步加载子级的数据)
loadDataByExpandedRows(dataList) {
if (this.expandedRowKeys.length > 0) {
return getAction(this.url.getChildListBatch,{ parentIds: this.expandedRowKeys.join(',') }).then(res=>{
if (res.success && res.result.records.length>0) {
//已展开的数据批量子节点
let records = res.result.records
const listMap = new Map();
for (let item of records) {
let pid = item[this.pidField];
if (this.expandedRowKeys.join(',').includes(pid)) {
let mapList = listMap.get(pid);
if (mapList == null) {
mapList = [];
}
mapList.push(item);
listMap.set(pid, mapList);
}
}
let childrenMap = listMap;
let fn = (list) => {
if(list) {
list.forEach(data => {
if (this.expandedRowKeys.includes(data.cno)) {
data.children = this.getDataByResult(childrenMap.get(data.cno))
fn(data.children)
}
})
}
}
fn(dataList)
}
})
} else {
return Promise.resolve()
}
},
selectChanges(selectedRowKeys, selectionRows) {
this.selectedRowKeys = selectedRowKeys;
this.selectionRows = selectionRows;
var array='';
var uid='';
this.selectionRows.forEach(function (row) {
array += row.cno + ",";
});
this.pno_arr=array
},
/** 点击a-table中的行后,展开或关闭其子行 */
tableClick(record, index){
return {
style:{
cursor:'pointer',
},
on: {
click: () => {
this.expandRowByClick = !this.expandRowByClick;
}
}
}
},
}
}
</script>
<style scoped>
</style>