Browse Source

2024.12.11 产品文档收集-项目物料-量产BOM 优化

java8
yuejiayang 1 year ago
parent
commit
984209c3bd
  1. 29
      src/utils/arrayToTreeByLevelCode.js
  2. 119
      src/views/modules/eam/eamProjectPartInfo.vue

29
src/utils/arrayToTreeByLevelCode.js

@ -0,0 +1,29 @@
export function arrayToTreeByLevelCode(data, levelField, childrenField) {
if (!Array.isArray(data)) {
console.error("Invalid data: data is not an array", data);
return [];
}
const tree = [];
const map = new Map();
// 初始化 Map,每个 levelCode 对应一个节点对象
data.forEach(item => {
map.set(item[levelField], { ...item, [childrenField]: [] });
});
data.forEach(item => {
const node = map.get(item[levelField]);
const parentKey = item[levelField].split('.').slice(0, -1).join('.'); // 获取父节点的 levelCode
if (parentKey && map.has(parentKey)) {
// 如果有父节点,添加到父节点的 children 数组中
map.get(parentKey)[childrenField].push(node);
} else {
// 没有父节点,说明是根节点
tree.push(node);
}
});
return tree;
}

119
src/views/modules/eam/eamProjectPartInfo.vue

@ -478,13 +478,22 @@
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="量产BOM" name="massProductionBOM"> <el-tab-pane label="量产BOM" name="massProductionBOM">
<el-table <el-table
:data="flattenedData"
:data="projectPartBomList"
row-key="levelCode"
border border
style="width: 100%; margin-top: 5px;" style="width: 100%; margin-top: 5px;"
:height="this.height + 50" :height="this.height + 50"
ref="projectBomTable" ref="projectBomTable"
v-loading="dataListLoading">
v-loading="dataListLoading"
:tree-props="{ children: 'children' }">
<!-- 数据列 --> <!-- 数据列 -->
<el-table-column
label=""
prop=""
header-align="center"
align="right"
width="50">
</el-table-column>
<el-table-column <el-table-column
v-for="(item, index) in columnProjectBomList" v-for="(item, index) in columnProjectBomList"
:key="index" :key="index"
@ -497,26 +506,8 @@
:min-width="item.columnWidth" :min-width="item.columnWidth"
:label="item.columnLabel"> :label="item.columnLabel">
<template slot-scope="scope"> <template slot-scope="scope">
<div v-if="item.columnProp === 'levelCode'">
<span v-if="scope.row.levelCode === '1'">{{ '主BOM' }}</span>
<span v-else>{{ scope.row.levelCode }}</span>
</div>
<div v-else>
<span v-if="!item.columnHidden">{{scope.row[item.columnProp]}}</span> <span v-if="!item.columnHidden">{{scope.row[item.columnProp]}}</span>
<span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span> <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
</div>
</template>
</el-table-column>
<!-- 展开/折叠按钮 -->
<el-table-column label="操作" align="center" width="80" fixed="right">
<template #default="scope">
<a
type="text"
@click="toggleRow(scope.row)"
v-if="hasChildren(scope.row)">
{{ scope.row.expanded ? '查看子物料' : '查看子物料' }}
</a>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@ -1173,6 +1164,7 @@ import moment from 'moment';
import 'moment/locale/zh-cn'; import 'moment/locale/zh-cn';
import {downLoadObjectFile2} from "../../../api/eam/eam_object_list"; import {downLoadObjectFile2} from "../../../api/eam/eam_object_list";
import {EventBus} from "../../../main"; import {EventBus} from "../../../main";
import {arrayToTreeByLevelCode} from "../../../utils/arrayToTreeByLevelCode";
/*打样记录組件*/ /*打样记录組件*/
export default { export default {
@ -1326,13 +1318,12 @@ import {EventBus} from "../../../main";
confirmatoryList: [], confirmatoryList: [],
projectAllDocumentConfirmatorList: [], projectAllDocumentConfirmatorList: [],
projectANotDocumentConfirmatorList: [], projectANotDocumentConfirmatorList: [],
projectPartBomList: [],
projectPartBomList: [],// BOM
confirmatorySelection1: [], confirmatorySelection1: [],
confirmatorySelection2: [], confirmatorySelection2: [],
proofDocumentListDefinition: [], proofDocumentListDefinition: [],
confirmProgressPusherList: [], confirmProgressPusherList: [],
confirmProgressDocumentList: [], // BOM
flattenedData: [], // BOM
confirmProgressDocumentList: [],
projectConfirmatorFileList: [], projectConfirmatorFileList: [],
viewDocumentFileVisible: false, viewDocumentFileVisible: false,
viewMassDocumentFileVisible: false, viewMassDocumentFileVisible: false,
@ -2487,6 +2478,24 @@ import {EventBus} from "../../../main";
} }
], ],
columnProjectBomList: [ columnProjectBomList: [
{
userId: this.$store.state.user.name,
functionId: 401005,
serialNumber: '401005Table1LevelCode',
tableId: "401005Table1",
tableName: "项目物料表",
columnProp: 'levelCode',
headerAlign: "center",
align: "center",
columnLabel: 'BOM层级',
columnHidden: false,
columnImage: false,
columnSortable: false,
sortLv: 0,
status: true,
fixed: '',
columnWidth: 100,
},
{ {
userId: this.$store.state.user.name, userId: this.$store.state.user.name,
functionId: 401005, functionId: 401005,
@ -2559,24 +2568,6 @@ import {EventBus} from "../../../main";
fixed: '', fixed: '',
columnWidth: 150, columnWidth: 150,
}, },
{
userId: this.$store.state.user.name,
functionId: 401005,
serialNumber: '401005Table1LevelCode',
tableId: "401005Table1",
tableName: "项目物料表",
columnProp: 'levelCode',
headerAlign: "center",
align: "center",
columnLabel: 'BOM层级',
columnHidden: false,
columnImage: false,
columnSortable: false,
sortLv: 0,
status: true,
fixed: '',
columnWidth: 100,
},
], ],
levelList: [], levelList: [],
rules:{ rules:{
@ -5175,7 +5166,7 @@ import {EventBus} from "../../../main";
} }
}) })
}, },
searchMassProductionBomList() {
async fetchBomList() {
let inData = { let inData = {
site: this.proofingCurrentRow.site, site: this.proofingCurrentRow.site,
buNo: this.proofingCurrentRow.buNo, buNo: this.proofingCurrentRow.buNo,
@ -5188,43 +5179,19 @@ import {EventBus} from "../../../main";
page: 1, page: 1,
limit: 1000 limit: 1000
} }
searchMassProductionBomList(inData).then(({data}) => {
return searchMassProductionBomList(inData).then(({data}) => {
if (data && data.code === 0){ if (data && data.code === 0){
this.projectPartBomList = data.list;
//
this.flattenedData = this.projectPartBomList.filter(item => item.levelCode.split('.').length === 1);
return data.list
} }
}) })
}, },
//
hasChildren(row) {
return this.projectPartBomList.some(item => item.levelCode.startsWith(`${row.levelCode}.`));
},
//
toggleRow(row) {
if (row.expanded) {
//
this.flattenedData = this.flattenedData.filter(item => !item.levelCode.startsWith(`${row.levelCode}.`));
row.expanded = false;
} else {
//
const children = this.projectPartBomList.filter(item =>
item.levelCode.startsWith(`${row.levelCode}.`) &&
item.levelCode.split('.').length === row.levelCode.split('.').length + 1
);
//
const rowIndex = this.flattenedData.indexOf(row);
this.flattenedData.splice(rowIndex + 1, 0, ...children);
row.expanded = true;
}
},
// //
tabClick (tab, event) { tabClick (tab, event) {
// //
this.refreshCurrentTabTable() this.refreshCurrentTabTable()
}, },
refreshCurrentTabTable () {
async refreshCurrentTabTable () {
if (this.activeName == 'proofRecord') { if (this.activeName == 'proofRecord') {
this.getRowProjectInfo(); this.getRowProjectInfo();
} }
@ -5240,9 +5207,19 @@ import {EventBus} from "../../../main";
this.getConfirmProgressPusherList() this.getConfirmProgressPusherList()
} }
if (this.activeName == 'massProductionBOM' && this.proofingCurrentRow.finalPartNo !== '' && this.proofingCurrentRow.finalPartNo !== null){ if (this.activeName == 'massProductionBOM' && this.proofingCurrentRow.finalPartNo !== '' && this.proofingCurrentRow.finalPartNo !== null){
this.searchMassProductionBomList()
this.dataListLoading = true;
try {
//
const flatData = await this.fetchBomList();
//
this.projectPartBomList = arrayToTreeByLevelCode(flatData, "levelCode", "children");
//
console.log(JSON.stringify(this.projectPartBomList, null, 2));
} finally {
this.dataListLoading = false;
}
} else { } else {
this.flattenedData = []
this.projectPartBomList = []
} }
}, },
// //

Loading…
Cancel
Save