From a14c5ce07d20e9f28058f6942dbc00197fac47f1 Mon Sep 17 00:00:00 2001
From: yuan <123@>
Date: 星期四, 13 八月 2026 10:19:19 +0800
Subject: [PATCH] fix: 领料功能修改,移除订单领料,添加工序领料功能,支持按工序查询物料与已领料记录
---
src/views/productionManagement/productStructure/Detail/index.vue | 514 ++++++++++++---------------------------------------------
1 files changed, 108 insertions(+), 406 deletions(-)
diff --git a/src/views/productionManagement/productStructure/Detail/index.vue b/src/views/productionManagement/productStructure/Detail/index.vue
index ec18ddf..f8c359f 100644
--- a/src/views/productionManagement/productStructure/Detail/index.vue
+++ b/src/views/productionManagement/productStructure/Detail/index.vue
@@ -27,23 +27,27 @@
<template #default="props">
<el-form ref="form"
:model="dataValue">
+ <div v-if="dataValue.isEdit && !isOrderPage"
+ class="mb10"
+ style="text-align: right;">
+ <el-button type="primary"
+ @click="addItem">娣诲姞鐗╂枡</el-button>
+ </div>
<el-table :data="dataValue.dataList"
row-key="tempId"
- default-expand-all
- :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
style="width: 100%">
<el-table-column prop="productName"
- label="浜у搧" />
+ label="鐗╂枡鍚嶇О" />
<el-table-column prop="model"
- label="瑙勬牸">
- <template #default="{ row, $index }">
+ label="鐗╂枡瑙勬牸">
+ <template #default="{ row }">
<el-form-item v-if="dataValue.isEdit"
- :rules="[{ required: true, message: '璇烽�夋嫨瑙勬牸', trigger: ['blur','change'] }]"
+ :rules="[{ required: true, message: '璇烽�夋嫨鐗╂枡瑙勬牸', trigger: ['blur','change'] }]"
style="margin: 0">
<el-select v-model="row.model"
- placeholder="璇烽�夋嫨瑙勬牸"
+ placeholder="璇烽�夋嫨鐗╂枡瑙勬牸"
clearable
- :disabled="!dataValue.isEdit || dataValue.dataList.some(item => (item as any).tempId === row.tempId)"
+ :disabled="!dataValue.isEdit"
style="width: 100%"
@visible-change="(v) => { if (v) openDialog(row.tempId) }">
<el-option v-if="row.model"
@@ -51,13 +55,14 @@
:value="row.model" />
</el-select>
</el-form-item>
+ <span v-else>{{ row.model }}</span>
</template>
</el-table-column>
<el-table-column prop="processName"
label="娑堣�楀伐搴�">
- <template #default="{ row, $index }">
+ <template #default="{ row }">
<el-form-item v-if="dataValue.isEdit"
- :rules="dataValue.dataList.some(item => (item as any).tempId === row.tempId) ? [] : [{ required: true, message: '璇烽�夋嫨娑堣�楀伐搴�', trigger: 'change' }]"
+ :rules="[{ required: true, message: '璇烽�夋嫨娑堣�楀伐搴�', trigger: 'change' }]"
style="margin: 0">
<el-select v-model="row.processId"
placeholder="璇烽�夋嫨"
@@ -65,73 +70,24 @@
clearable
style="width: 100%"
@change="value => handleProcessChange(row, value)"
- :disabled="!dataValue.isEdit || dataValue.dataList.some(item => (item as any).tempId === row.tempId)">
+ :disabled="!dataValue.isEdit">
<el-option v-for="item in dataValue.processOptions"
:key="item.id"
:label="item.name"
:value="item.id" />
</el-select>
</el-form-item>
+ <span v-else>{{ row.processName }}</span>
</template>
</el-table-column>
- <el-table-column prop="unitQuantity"
- label="鍗曚綅浜у嚭鎵�闇�鏁伴噺">
- <template #default="{ row, $index }">
- <el-form-item v-if="dataValue.isEdit"
- :rules="[{ required: true, message: '璇疯緭鍏ュ崟浣嶄骇鍑烘墍闇�鏁伴噺', trigger: ['blur','change'] }]"
- style="margin: 0">
- <el-input-number v-model="row.unitQuantity"
- :min="0"
- :step="1"
- controls-position="right"
- style="width: 100%"
- @change="handleUnitQuantityChange"
- :disabled="!dataValue.isEdit || dataValue.dataList.some(item => (item as any).tempId === row.tempId)" />
- </el-form-item>
- </template>
- </el-table-column>
- <el-table-column v-if="isOrderPage"
- prop="demandedQuantity"
- label="闇�姹傛�婚噺">
- <template #default="{ row, $index }">
- <el-form-item v-if="dataValue.isEdit"
- :rules="[{ required: true, message: '璇疯緭鍏ラ渶姹傛�婚噺', trigger: ['blur','change'] }]"
- style="margin: 0">
- <el-input-number v-model="row.demandedQuantity"
- :min="0"
- :step="1"
- controls-position="right"
- style="width: 100%"
- :disabled="true" />
- </el-form-item>
- </template>
- </el-table-column>
- <el-table-column prop="unit"
- label="鍗曚綅">
- <template #default="{ row, $index }">
- <el-form-item v-if="dataValue.isEdit"
- :rules="[{ required: true, message: '璇疯緭鍏ュ崟浣�', trigger: ['blur','change'] }]"
- style="margin: 0">
- <el-input v-model="row.unit"
- placeholder="璇疯緭鍏ュ崟浣�"
- clearable
- :disabled="!dataValue.isEdit || dataValue.dataList.some(item => (item as any).tempId === row.tempId)" />
- </el-form-item>
- </template>
- </el-table-column>
- <el-table-column label="鎿嶄綔"
+ <el-table-column v-if="dataValue.isEdit && !isOrderPage"
+ label="鎿嶄綔"
fixed="right"
- width="200">
- <template #default="{ row, $index }">
- <el-button v-if="dataValue.isEdit && !dataValue.dataList.some(item => (item as any).tempId === row.tempId)"
- type="danger"
+ width="120">
+ <template #default="{ row }">
+ <el-button type="danger"
text
@click="removeItem(row.tempId)">鍒犻櫎
- </el-button>
- <el-button v-if="dataValue.isEdit"
- type="primary"
- text
- @click="addItem2(row.tempId)">娣诲姞
</el-button>
</template>
</el-table-column>
@@ -238,7 +194,7 @@
};
const syncProcessOperationFields = (item: any) => {
- const processId = item.processId ?? item.operationId ?? "";
+ const processId = item.processId ?? item.operationId ?? item.technologyOperationId ?? "";
if (!processId) {
item.processId = "";
item.operationId = "";
@@ -257,97 +213,27 @@
item.operationName = processName;
};
- const normalizeTreeData = (items: any[]) => {
- items.forEach((item: any) => {
- item.tempId = item.tempId || item.id || `${Date.now()}_${Math.random()}`;
- syncProcessOperationFields(item);
- if (Array.isArray(item.children) && item.children.length > 0) {
- normalizeTreeData(item.children);
- }
- });
+ const createTempId = () => `${Date.now()}_${Math.random()}`;
+
+ // BOM 鍙淮鎶も�滅墿鏂欒鏍� + 娑堣�楀伐搴忊�濓紝tempId 浠呬綔涓鸿〃鏍兼湰鍦拌閿紝涓嶈〃杈句换浣曞眰绾у叧绯�
+ const normalizeMaterialItem = (item: any) => {
+ const material = {
+ id: item.id ?? null,
+ tempId: item.tempId || item.id || createTempId(),
+ productName: item.productName || item.materialName || "",
+ model: item.model || item.materialModel || undefined,
+ productModelId: item.productModelId || item.materialModelId || undefined,
+ processId: item.processId ?? item.operationId ?? item.technologyOperationId ?? "",
+ processName: item.processName || item.operationName || "",
+ operationId: item.operationId ?? item.processId ?? item.technologyOperationId ?? "",
+ operationName: item.operationName || item.processName || "",
+ };
+ syncProcessOperationFields(material);
+ return material;
};
- const toQuantityNumber = (value: any) => {
- const numberValue = Number(value);
- if (!Number.isFinite(numberValue)) {
- return 0;
- }
- return Number(numberValue.toFixed(4));
- };
-
- const syncDemandedQuantityTree = (
- items: any[],
- parentDemandedQuantity: number | null = null
- ) => {
- items.forEach((item: any) => {
- if (parentDemandedQuantity !== null) {
- item.demandedQuantity = toQuantityNumber(
- parentDemandedQuantity * toQuantityNumber(item.unitQuantity)
- );
- }
-
- if (Array.isArray(item.children) && item.children.length > 0) {
- syncDemandedQuantityTree(
- item.children,
- toQuantityNumber(item.demandedQuantity)
- );
- }
- });
- };
-
- const recalculateDemandedQuantities = () => {
- if (!isOrderPage.value) {
- return;
- }
-
- syncDemandedQuantityTree(dataValue.dataList);
- };
-
- const buildSubmitTree = (items: any[]) => {
- return items.map((item: any) => {
- const current = { ...item };
- syncProcessOperationFields(current);
- current.children = Array.isArray(current.children)
- ? buildSubmitTree(current.children)
- : [];
- return current;
- });
- };
-
- const findSiblings = (items: any[], tempId: string): any[] | null => {
- if (!items || items.length === 0) return null;
- // 妫�鏌ュ綋鍓嶅眰绾�
- if (items.some(item => item.tempId === tempId)) {
- return items;
- }
- // 閫掑綊鏌ユ壘瀛愮骇
- for (const item of items) {
- if (item.children && item.children.length > 0) {
- const result = findSiblings(item.children, tempId);
- if (result) return result;
- }
- }
- return null;
- };
-
- const handleProcessChange = (row: any, value: any) => {
- row.processId = value || "";
- syncProcessOperationFields(row);
-
- // 妫�鏌ュ悓涓�灞傜骇鏄惁宸茬粡鏈夊叾浠栦笉鍚岀殑宸ュ簭琚�変腑
- const siblings = findSiblings(dataValue.dataList, row.tempId);
- if (siblings && value) {
- const hasDifferentProcess = siblings.some(sibling => {
- return sibling.tempId !== row.tempId && sibling.processId && sibling.processId !== value;
- });
- if (hasDifferentProcess) {
- ElMessage.warning("鍚屼竴灞傜骇宸插瓨鍦ㄤ笉鍚岀殑宸ュ簭锛岃鍏堢粺涓�宸ュ簭鍚庡啀杩涜淇敼");
- }
- }
- };
-
- const handleUnitQuantityChange = () => {
- recalculateDemandedQuantities();
+ const normalizeMaterialList = (items: any[]) => {
+ return normalizeListData(items).map(item => normalizeMaterialItem(item));
};
const tableData = reactive([
@@ -359,7 +245,6 @@
]);
const openDialog = (tempId: any) => {
- console.log(tempId, "tempId");
dataValue.currentRowName = tempId;
dataValue.showProductDialog = true;
};
@@ -368,188 +253,94 @@
if (isOrderPage.value) {
// 璁㈠崟鎯呭喌锛氫娇鐢ㄨ鍗曠殑浜у搧缁撴瀯鎺ュ彛
const { data } = await listProcessBom({ orderId: routeOrderId.value });
- dataValue.dataList = (data as any) || [];
- normalizeTreeData(dataValue.dataList);
- recalculateDemandedQuantities();
+ dataValue.dataList = normalizeMaterialList((data as any) || []);
} else {
// 闈炶鍗曟儏鍐碉細浣跨敤鍘熸潵鐨勬帴鍙�
const { data } = await queryList(routeId.value);
- dataValue.dataList = (data as any) || [];
- console.log(dataValue);
- normalizeTreeData(dataValue.dataList);
- console.log(dataValue.dataList, "dataValue.dataList");
+ dataValue.dataList = normalizeMaterialList((data as any) || []);
}
};
const fetchProcessOptions = async () => {
const { data } = await list({});
- console.log(data, "dataValue.dataList");
dataValue.processOptions = normalizeListData(data);
};
const handleProduct = (row: any) => {
if (!Array.isArray(row) || row.length === 0) {
- ElMessage.warning("璇烽�夋嫨涓�涓骇鍝�");
+ ElMessage.warning("璇烽�夋嫨涓�涓墿鏂�");
return;
}
// 鍙厑璁镐竴涓細濡傛灉涓婃父杩斿洖浜嗗涓紝榛樿浣跨敤鏈�鍚庝竴娆¢�夋嫨骞惰鐩栧綋鍓嶅��
const productData = row[row.length - 1];
- // 鏈�澶栧眰缁勪欢涓紝涓庡綋鍓嶄骇鍝佺浉鍚岀殑浜у搧鍙兘鏈変竴涓�
- const isTopLevel = dataValue.dataList.some(
- item => (item as any).tempId === dataValue.currentRowName
+ const current = dataValue.dataList.find(
+ item => item.tempId === dataValue.currentRowName
);
- if (isTopLevel) {
- if (
- productData.productName === tableData[0].productName &&
- productData.model === tableData[0].model
- ) {
- // 鏌ユ壘鏄惁宸茬粡鏈夊叾浠栭《灞傝宸茬粡鏄繖涓骇鍝�
- const hasOther = dataValue.dataList.some(
- item =>
- (item as any).tempId !== dataValue.currentRowName &&
- (item as any).productName === tableData[0].productName &&
- (item as any).model === tableData[0].model
- );
- if (hasOther) {
- ElMessage.warning("鏈�澶栧眰鍜屽綋鍓嶄骇鍝佷竴鏍风殑涓�绾у彧鑳芥湁涓�涓�");
- return;
- }
- }
+ if (current) {
+ current.productName = productData.productName;
+ current.model = productData.model;
+ current.productModelId = productData.id;
}
- // dataValue.dataList[dataValue.currentRowIndex].productName =
- // row[0].productName;
- // dataValue.dataList[dataValue.currentRowIndex].model = row[0].model;
- // dataValue.dataList[dataValue.currentRowIndex].productModelId = row[0].id;
- // dataValue.dataList[dataValue.currentRowIndex].unit = row[0].unit || "";
- dataValue.dataList.map(item => {
- if (item.tempId === dataValue.currentRowName) {
- item.productName = productData.productName;
- item.model = productData.model;
- item.productModelId = productData.id;
- item.unit = productData.unit || "";
- return;
- }
- childItem(item, dataValue.currentRowName, productData);
- });
dataValue.showProductDialog = false;
};
- const childItem = (item: any, tempId: any, productData: any) => {
- if (item.tempId === tempId) {
- item.productName = productData.productName;
- item.model = productData.model;
- item.productModelId = productData.id;
- item.unit = productData.unit || "";
- return true;
+
+ const validateAll = () => {
+ if (dataValue.dataList.length === 0) {
+ ElMessage.error("璇锋坊鍔犵墿鏂�");
+ return false;
}
- if (item.children && item.children.length > 0) {
- for (let child of item.children) {
- if (childItem(child, tempId, productData)) {
- return true;
- }
+
+ const invalidItem = dataValue.dataList.find(
+ item => !item.model || !item.productModelId || !item.processId
+ );
+ if (invalidItem) {
+ ElMessage.error("璇烽�夋嫨鐗╂枡瑙勬牸鍜屾秷鑰楀伐搴�");
+ return false;
+ }
+
+ const relationKeys = new Set();
+ const duplicated = dataValue.dataList.some(item => {
+ const key = `${item.productModelId}#${item.processId}`;
+ if (relationKeys.has(key)) {
+ return true;
}
+ relationKeys.add(key);
+ return false;
+ });
+ if (duplicated) {
+ ElMessage.error("鍚屼竴鐗╂枡瑙勬牸鍦ㄥ悓涓�宸ュ簭涓嬩笉鑳介噸澶嶉厤缃�");
+ return false;
}
- return false;
+
+ return true;
};
- // 閫掑綊鏍¢獙鎵�鏈夊眰绾х殑琛ㄥ崟鏁版嵁
- const validateAll = () => {
- let isValid = true;
-
- // 鏍¢獙涓�缁勫厔寮熻妭鐐圭殑宸ュ簭鏄惁閮界浉鍚�
- const checkProcessUniqueness = (items: any[]) => {
- if (!items || items.length === 0 || !isValid) return;
-
- // 鑾峰彇绗竴涓潪绌虹殑宸ュ簭ID浣滀负鍙傝��
- const firstProcessId = items.find(item => item.processId)?.processId;
-
- // 濡傛灉鏈夊伐搴廔D锛屾鏌ユ墍鏈夐」鏄惁閮戒娇鐢ㄧ浉鍚岀殑宸ュ簭
- if (firstProcessId) {
- for (const item of items) {
- if (item.processId && item.processId !== firstProcessId) {
- const option1 = getProcessOptionById(firstProcessId);
- const option2 = getProcessOptionById(item.processId);
- const processName1 = option1?.name || "鏈煡宸ュ簭";
- const processName2 = option2?.name || "鏈煡宸ュ簭";
- ElMessage.error(
- `褰撳墠灞傜骇涓嬪伐搴忎笉涓�鑷达紝璇蜂娇鐢ㄧ浉鍚岀殑宸ュ簭銆傚瓨鍦ㄣ��${processName1}銆嶅拰銆�${processName2}銆峘
- );
- isValid = false;
- return;
- }
- }
- }
-
- // 閫掑綊鏍¢獙瀛愮骇鐨勫厔寮熻妭鐐�
- for (const item of items) {
- if (item.children && item.children.length > 0) {
- checkProcessUniqueness(item.children);
- }
- }
- };
-
- // 鏍¢獙鍑芥暟
- const validateItem = (item: any, isTopLevel = false) => {
- if (!isValid) return;
- // 鏍¢獙褰撳墠椤圭殑蹇呭~瀛楁
- if (!item.model) {
- ElMessage.error("璇烽�夋嫨瑙勬牸");
- isValid = false;
- return;
- }
- if (!isTopLevel && !item.processId) {
- ElMessage.error("璇烽�夋嫨娑堣�楀伐搴�");
- isValid = false;
- return;
- }
- if (!item.unitQuantity) {
- ElMessage.error("璇疯緭鍏ュ崟浣嶄骇鍑烘墍闇�鏁伴噺");
- isValid = false;
- return;
- }
- if (isOrderPage.value && !item.demandedQuantity) {
- ElMessage.error("璇疯緭鍏ラ渶姹傛�婚噺");
- isValid = false;
- return;
- }
- // if (!item.unit) {
- // ElMessage.error("璇疯緭鍏ュ崟浣�");
- // isValid = false;
- // return;
- // }
-
- // 閫掑綊鏍¢獙瀛愰」瀛楁
- if (item.children && item.children.length > 0) {
- item.children.forEach(child => {
- validateItem(child, false);
- });
- }
- };
-
- // 1. 棣栧厛鏍¢獙鍚屼竴鐖剁骇涓嬬殑鍚屽眰娑堣�楀伐搴忔槸鍚﹀敮涓�
- checkProcessUniqueness(dataValue.dataList);
- if (!isValid) return false;
-
- // 2. 鐒跺悗閬嶅巻鏍¢獙鎵�鏈夐《灞傞」鐨勫瓧娈靛繀濉儏鍐�
- dataValue.dataList.forEach(item => {
- validateItem(item, true);
+ // 鎻愪氦缁欏悗绔殑鍙湁鐗╂枡瑙勬牸鍜屾秷鑰楀伐搴忥紝涓嶅惈鏁伴噺銆佸崟浣嶅拰灞傜骇瀛楁
+ const buildSubmitList = (items: any[]) => {
+ return items.map((item: any) => {
+ const current = normalizeMaterialItem(item);
+ return {
+ id: current.id || undefined,
+ productModelId: current.productModelId,
+ operationId: current.operationId,
+ };
});
+ };
- return isValid;
+ const handleProcessChange = (row: any, value: any) => {
+ row.processId = value || "";
+ syncProcessOperationFields(row);
};
const submit = () => {
dataValue.loading = true;
- normalizeTreeData(dataValue.dataList);
- recalculateDemandedQuantities();
- // 鍏堣繘琛岃〃鍗曟牎楠�
const valid = validateAll();
- console.log(dataValue.dataList, "dataValue.dataList");
if (valid) {
addBomDetail({
bomId: routeId.value,
- children: buildSubmitTree(dataValue.dataList || []),
+ detailList: buildSubmitList(dataValue.dataList || []),
})
.then(res => {
router.go(-1);
@@ -565,117 +356,28 @@
};
const removeItem = (tempId: string) => {
- // 鍏堝皾璇曚粠椤跺眰鍒犻櫎
- const topIndex = dataValue.dataList.findIndex(item => item.tempId === tempId);
- if (topIndex !== -1) {
- dataValue.dataList.splice(topIndex, 1);
- return;
+ const index = dataValue.dataList.findIndex(item => item.tempId === tempId);
+ if (index !== -1) {
+ dataValue.dataList.splice(index, 1);
}
+ };
- // 閫掑綊鍒犻櫎瀛愰」
- const delchildItem = (items: any[], tempId: any) => {
- for (let i = 0; i < items.length; i++) {
- const item = items[i];
- if (item.tempId === tempId) {
- items.splice(i, 1);
- return true;
- }
- if (item.children && item.children.length > 0) {
- if (delchildItem(item.children, tempId)) {
- return true;
- }
- }
- }
- return false;
- };
-
- dataValue.dataList.forEach(item => {
- if (item.children && item.children.length > 0) {
- delchildItem(item.children, tempId);
- }
+ const addItem = () => {
+ dataValue.dataList.push({
+ id: null,
+ productName: "",
+ model: undefined,
+ productModelId: undefined,
+ processId: "",
+ processName: "",
+ operationId: "",
+ operationName: "",
+ tempId: createTempId(),
});
- };
- 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 || "",
- productName: "",
- productId: "",
- model: undefined,
- productModelId: undefined,
- processId: "",
- processName: "",
- operationId: "",
- operationName: "",
- unitQuantity: 1,
- demandedQuantity: 0,
- unit: "",
- children: [],
-
- tempId: new Date().getTime(),
- });
- recalculateDemandedQuantities();
- return;
- }
- addchildItem(item, tempId);
- });
- };
- const addchildItem = (item: any, tempId: any) => {
- if (item.tempId === tempId) {
- console.log(item, "item");
- if (!item.children) {
- item.children = [];
- }
- item.children.push({
- parentId: item.id || "",
- parentTempId: item.tempId || "",
- productName: "",
- productId: "",
- model: undefined,
- productModelId: undefined,
- processId: "",
- processName: "",
- operationId: "",
- operationName: "",
- unitQuantity: 1,
- demandedQuantity: 0,
- children: [],
- unit: "",
- tempId: new Date().getTime(),
- });
- recalculateDemandedQuantities();
- return true;
- }
- if (item.children && item.children.length > 0) {
- for (let child of item.children) {
- if (addchildItem(child, tempId)) {
- return true;
- }
- }
- }
- return false;
- };
-
- const getPropPath = (row, field) => {
- // 涓烘瘡涓猺ow鐢熸垚鍞竴鐨勮矾寰�
- // 浣跨敤row.id鎴栫储寮曚綔涓哄敮涓�鏍囪瘑
- let path = "dataList";
-
- // 绠�鍗曞疄鐜帮細浣跨敤row鐨刬d鎴栦竴涓敮涓�鏍囪瘑
- const uniqueId = row.id || Math.floor(Math.random() * 10000);
- path += `.${uniqueId}`;
-
- return path + `.${field}`;
};
const cancelEdit = () => {
dataValue.isEdit = false;
- // dataValue.dataList = dataValue.dataList.filter(item => item.id !== undefined);
fetchData();
};
@@ -694,4 +396,4 @@
await fetchProcessOptions();
await fetchData();
});
-</script>
\ No newline at end of file
+</script>
--
Gitblit v1.9.3