| | |
| | | </el-form-item> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column prop="processId" |
| | | <el-table-column prop="processName" |
| | | label="消耗工序"> |
| | | <template #default="{ row, $index }"> |
| | | <el-form-item v-if="dataValue.isEdit" |
| | |
| | | const ProductSelectDialog = defineAsyncComponent( |
| | | () => import("@/views/basicData/product/ProductSelectDialog.vue") |
| | | ); |
| | | const emit = defineEmits(["update:router"]); |
| | | const form = ref(); |
| | | |
| | | const route = useRoute(); |
| | |
| | | if (isOrderPage.value) { |
| | | // 订单情况:使用订单的产品结构接口 |
| | | const { data } = await listProcessBom({ orderId: routeOrderId.value }); |
| | | dataValue.dataList = data || []; |
| | | dataValue.dataList = (data as any) || []; |
| | | } else { |
| | | // 非订单情况:使用原来的接口 |
| | | const { data } = await queryList(routeId.value); |
| | | dataValue.dataList = data || []; |
| | | dataValue.dataList = (data as any) || []; |
| | | // 为所有项及其子项设置name属性 |
| | | const setNameRecursively = items => { |
| | | items.forEach(item => { |
| | | 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"); |
| | | |
| | | // dataValue.dataList = [ |
| | | // { |
| | | // id: 30, |
| | | // productModelId: 220, |
| | | // processId: 42, |
| | | // unitQuantity: 0.0, |
| | | // demandedQuantity: 0.0, |
| | | // unit: "30", |
| | | // tenantId: 100, |
| | | // bomId: 5, |
| | | // processName: "测试1", |
| | | // productName: "1111", |
| | | // productId: 264, |
| | | // model: "1112233", |
| | | // productStructureList: null, |
| | | // children: [ |
| | | // { |
| | | // id: 300, |
| | | // productModelId: 220, |
| | | // processId: 42, |
| | | // unitQuantity: 0.0, |
| | | // demandedQuantity: 0.0, |
| | | // unit: "300", |
| | | // tenantId: 100, |
| | | // bomId: 5, |
| | | // processName: "测试1", |
| | | // productName: "1111", |
| | | // productId: 264, |
| | | // model: "1112233", |
| | | // productStructureList: null, |
| | | // children: [ |
| | | // { |
| | | // id: 3000, |
| | | // productModelId: 220, |
| | | // processId: 42, |
| | | // unitQuantity: 0.0, |
| | | // demandedQuantity: 0.0, |
| | | // unit: "3000", |
| | | // tenantId: 100, |
| | | // bomId: 5, |
| | | // processName: "测试1", |
| | | // productName: "1111", |
| | | // productId: 264, |
| | | // model: "1112233", |
| | | // productStructureList: null, |
| | | // }, |
| | | // { |
| | | // id: 3200, |
| | | // productModelId: 221, |
| | | // processId: 43, |
| | | // unitQuantity: 0.0, |
| | | // demandedQuantity: 0.0, |
| | | // unit: "3200", |
| | | // tenantId: 100, |
| | | // bomId: 5, |
| | | // processName: "测试2", |
| | | // productName: "xxx", |
| | | // productId: 266, |
| | | // model: "xxx", |
| | | // productStructureList: null, |
| | | // }, |
| | | // ], |
| | | // }, |
| | | // { |
| | | // id: 320, |
| | | // productModelId: 221, |
| | | // processId: 43, |
| | | // unitQuantity: 0.0, |
| | | // demandedQuantity: 0.0, |
| | | // unit: "320", |
| | | // tenantId: 100, |
| | | // bomId: 5, |
| | | // processName: "测试2", |
| | | // productName: "xxx", |
| | | // productId: 266, |
| | | // model: "xxx", |
| | | // productStructureList: null, |
| | | // }, |
| | | // ], |
| | | // }, |
| | | // { |
| | | // id: 32, |
| | | // productModelId: 221, |
| | | // processId: 43, |
| | | // unitQuantity: 0.0, |
| | | // demandedQuantity: 0.0, |
| | | // unit: "32", |
| | | // tenantId: 100, |
| | | // bomId: 5, |
| | | // processName: "测试2", |
| | | // productName: "xxx", |
| | | // productId: 266, |
| | | // model: "xxx", |
| | | // productStructureList: null, |
| | | // }, |
| | | // ]; |
| | | } |
| | | }; |
| | | |
| | | const fetchProcessOptions = async () => { |
| | | const { data } = await list(routeId.value); |
| | | dataValue.processOptions = data; |
| | | const { data } = await list(); |
| | | dataValue.processOptions = data as any; |
| | | }; |
| | | |
| | | const handleProduct = row => { |
| | |
| | | ElMessage.error("只能选择一个产品"); |
| | | } |
| | | const productData = row[0]; |
| | | |
| | | // 校验:不能在最外层选择跟当前产品一样的产品 |
| | | const isTopLevel = dataValue.dataList.some(item => item.tempId === dataValue.currentRowName); |
| | | if (isTopLevel) { |
| | | if (productData.productName === tableData[0].productName && |
| | | productData.model === tableData[0].model) { |
| | | ElMessage.warning("不能在最外层选择跟当前产品一样的产品"); |
| | | return; |
| | | } |
| | | } |
| | | // dataValue.dataList[dataValue.currentRowIndex].productName = |
| | | // row[0].productName; |
| | | // dataValue.dataList[dataValue.currentRowIndex].model = row[0].model; |
| | |
| | | model: undefined, |
| | | productModelId: undefined, |
| | | processId: "", |
| | | processName: "", |
| | | unitQuantity: 0, |
| | | demandedQuantity: 0, |
| | | unit: "", |
| | | children: [], |
| | | tempId: new Date().getTime(), |
| | | }); |
| | | }; |
| | |
| | | const addItem2 = tempId => { |
| | | dataValue.dataList.map(item => { |
| | | if (item.tempId === tempId) { |
| | | if (!item.children) { |
| | | item.children = []; |
| | | } |
| | | item.children.push({ |
| | | parentId: item.id || "", |
| | | parentTempId: item.tempId || "", |
| | |
| | | model: undefined, |
| | | productModelId: undefined, |
| | | processId: "", |
| | | processName: "", |
| | | unitQuantity: 0, |
| | | demandedQuantity: 0, |
| | | unit: "", |
| | |
| | | const addchildItem = (item, tempId) => { |
| | | if (item.tempId === tempId) { |
| | | console.log(item, "item"); |
| | | |
| | | if (!item.children) { |
| | | item.children = []; |
| | | } |
| | | item.children.push({ |
| | | parentId: item.id || "", |
| | | parentTempId: item.tempId || "", |
| | |
| | | |
| | | const cancelEdit = () => { |
| | | dataValue.isEdit = false; |
| | | dataValue.dataList = dataValue.dataList.filter(item => item.id !== undefined); |
| | | // dataValue.dataList = dataValue.dataList.filter(item => item.id !== undefined); |
| | | fetchData(); |
| | | }; |
| | | |
| | | onMounted(() => { |
| | | onMounted(async () => { |
| | | // 从路由参数回显数据 |
| | | tableData[0].productName = routeProductName.value; |
| | | tableData[0].model = routeProductModelName.value; |
| | | tableData[0].bomNo = routeBomNo.value; |
| | | tableData[0].productName = routeProductName.value as string; |
| | | tableData[0].model = routeProductModelName.value as string; |
| | | tableData[0].bomNo = routeBomNo.value as string; |
| | | |
| | | // 订单情况下禁用编辑 |
| | | if (isOrderPage.value) { |
| | | dataValue.isEdit = false; |
| | | } |
| | | |
| | | fetchData(); |
| | | fetchProcessOptions(); |
| | | // 先加载工序选项,再加载数据,确保el-select能够正确回显 |
| | | await fetchProcessOptions(); |
| | | await fetchData(); |
| | | }); |
| | | </script> |