| | |
| | | <template> |
| | | <div class="app-container"> |
| | | <PageHeader content="产品结构详情"> |
| | | <div :class="embedded ? 'embedded-container' : 'app-container'"> |
| | | <PageHeader v-if="!embedded" content="产品结构详情"> |
| | | <template #right-button> |
| | | <el-button v-if="!dataValue.isEdit && !isOrderPage" |
| | | type="primary" |
| | |
| | | </el-form-item> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="操作" |
| | | <el-table-column v-if="!embedded" label="操作" |
| | | fixed="right" |
| | | width="200"> |
| | | <template #default="{ row, $index }"> |
| | |
| | | const ProductSelectDialog = defineAsyncComponent( |
| | | () => import("@/views/basicData/product/ProductSelectDialog.vue") |
| | | ); |
| | | const props = defineProps({ |
| | | embedded: { |
| | | type: Boolean, |
| | | default: false, |
| | | }, |
| | | // 显式指定BOM主键(用于嵌入到“工艺路线项目”等页面时,路由 query.id 不是 bomId 的情况) |
| | | bomId: { |
| | | type: [String, Number], |
| | | default: undefined, |
| | | }, |
| | | }); |
| | | const embedded = computed(() => props.embedded); |
| | | const emit = defineEmits(["update:router"]); |
| | | const form = ref(); |
| | | |
| | |
| | | const router = useRouter(); |
| | | const routeId = computed({ |
| | | get() { |
| | | return route.query.id; |
| | | // 优先使用外部传入的 bomId,其次使用路由的 bomId,最后回退到路由的 id(兼容原页面) |
| | | return props.bomId ?? route.query.bomId ?? route.query.id; |
| | | }, |
| | | |
| | | set(val) { |
| | |
| | | }; |
| | | |
| | | const fetchData = async () => { |
| | | if (isOrderPage.value) { |
| | | // 订单情况:使用订单的产品结构接口 |
| | | const { data } = await listProcessBom({ orderId: routeOrderId.value }); |
| | | dataValue.dataList = (data as any) || []; |
| | | } else { |
| | | // 非订单情况:使用原来的接口 |
| | | const { data } = await queryList(routeId.value); |
| | | dataValue.dataList = (data as any) || []; |
| | | // 为所有项及其子项设置name属性 |
| | | const setNameRecursively = (items: any[]) => { |
| | | items.forEach((item: any) => { |
| | | item.tempId = item.id; |
| | | item.processName = |
| | | dataValue.processOptions.find(option => option.id === item.processId) |
| | | ?.name || ""; |
| | | if (item.children && item.children.length > 0) { |
| | | setNameRecursively(item.children); |
| | | } |
| | | }); |
| | | }; |
| | | setNameRecursively(dataValue.dataList); |
| | | console.log(dataValue.dataList, "dataValue.dataList"); |
| | | const setNameRecursively = (items: any[]) => { |
| | | items.forEach((item: any) => { |
| | | item.tempId = item.tempId || item.id || new Date().getTime() + Math.random(); |
| | | item.processName = |
| | | dataValue.processOptions.find(option => option.id === item.processId)?.name || item.processName || ""; |
| | | if (item.children && item.children.length > 0) { |
| | | setNameRecursively(item.children); |
| | | } |
| | | }); |
| | | }; |
| | | |
| | | // 统一使用 BOM 查询产品结构:/productStructure/listBybomId/{bomId} |
| | | // 说明:订单页也会从路由/父组件带入 bomId(route.query.bomId 或 props.bomId) |
| | | const bomId = routeId.value; |
| | | if (!bomId) { |
| | | dataValue.dataList = []; |
| | | return; |
| | | } |
| | | const { data } = await queryList(bomId); |
| | | dataValue.dataList = (data as any) || []; |
| | | setNameRecursively(dataValue.dataList); |
| | | }; |
| | | |
| | | const fetchProcessOptions = async () => { |
| | |
| | | await fetchProcessOptions(); |
| | | await fetchData(); |
| | | }); |
| | | </script> |
| | | </script> |
| | | |
| | | <style scoped> |
| | | .embedded-container { |
| | | padding: 0; |
| | | margin: 0; |
| | | } |
| | | </style> |