|
@@ -1348,7 +1348,7 @@ const handleAddMaterial = () => {
|
|
|
|
|
|
// 临时标识(用于区分新记录)
|
|
|
isNew: true,
|
|
|
- tempId: Date.now() // 临时ID用于唯一标识
|
|
|
+ tempId: Date.now() + Math.random() // 临时ID用于唯一标识
|
|
|
};
|
|
|
|
|
|
// 生成唯一键
|
|
@@ -1412,7 +1412,7 @@ const refreshCurrentBomItemMaterials = () => {
|
|
|
currentBomItem: currentBomItem.value.name,
|
|
|
materialCount: materialList.value.length,
|
|
|
uniqueKey: uniqueKey,
|
|
|
- materials: materialList.value
|
|
|
+ showAllMaterials: showAllMaterials.value
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -1662,36 +1662,63 @@ const getInvalidMaterialsInfo = (bomNodeId: number): string[] => {
|
|
|
return invalidMaterials;
|
|
|
};
|
|
|
|
|
|
-// 删除物料(在表格中)
|
|
|
const handleDeleteMaterialInTable = (material) => {
|
|
|
// 确认删除对话框
|
|
|
message.confirm('确认删除该物料吗?', { title: '提示' }).then(() => {
|
|
|
const targetBomNodeId = material.bomNodeId;
|
|
|
- const targetDeviceId = material.deviceId;
|
|
|
- const uniqueKey = `${targetDeviceId}${targetBomNodeId}`;
|
|
|
+
|
|
|
+ // 修复:统一使用 bomNodeId 作为键(与新增物料保持一致)
|
|
|
+ const uniqueKey = `${targetBomNodeId}`;
|
|
|
+
|
|
|
+ console.log('删除物料调试信息:', {
|
|
|
+ material,
|
|
|
+ uniqueKey,
|
|
|
+ bomMaterialsMapKeys: Object.keys(bomMaterialsMap.value),
|
|
|
+ currentMaterials: bomMaterialsMap.value[uniqueKey] || []
|
|
|
+ });
|
|
|
|
|
|
// 从 bomMaterialsMap 中删除
|
|
|
if (bomMaterialsMap.value[uniqueKey]) {
|
|
|
- const mapIndex = bomMaterialsMap.value[uniqueKey].findIndex(item =>
|
|
|
- (item.isNew && item.tempId === material.tempId) ||
|
|
|
- (!item.isNew &&
|
|
|
+ let mapIndex = -1;
|
|
|
+
|
|
|
+ // 简化查找逻辑
|
|
|
+ if (material.isNew && material.tempId) {
|
|
|
+ // 新增物料:通过 tempId 查找
|
|
|
+ mapIndex = bomMaterialsMap.value[uniqueKey].findIndex(item =>
|
|
|
+ item.isNew && item.tempId === material.tempId
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ // 已有物料:通过关键字段查找
|
|
|
+ mapIndex = bomMaterialsMap.value[uniqueKey].findIndex(item =>
|
|
|
+ !item.isNew &&
|
|
|
item.factoryId === material.factoryId &&
|
|
|
item.costCenterId === material.costCenterId &&
|
|
|
item.storageLocationId === material.storageLocationId &&
|
|
|
- item.materialCode === material.materialCode)
|
|
|
- );
|
|
|
+ item.materialCode === material.materialCode
|
|
|
+ );
|
|
|
+ }
|
|
|
|
|
|
if (mapIndex !== -1) {
|
|
|
+ // 执行删除
|
|
|
bomMaterialsMap.value[uniqueKey].splice(mapIndex, 1);
|
|
|
+ message.success('物料删除成功');
|
|
|
+
|
|
|
+ console.log('删除成功后的物料列表:', bomMaterialsMap.value[uniqueKey]);
|
|
|
+
|
|
|
+ // 关键修复:立即更新当前显示的物料列表
|
|
|
+ refreshCurrentBomItemMaterials();
|
|
|
+
|
|
|
+ // 删除物料后重新计算费用
|
|
|
+ nextTick(() => {
|
|
|
+ calculateTotalCost();
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ message.warning('未找到要删除的物料记录');
|
|
|
+ console.error('未找到匹配的物料记录:', material);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ message.warning('未找到对应的物料列表');
|
|
|
}
|
|
|
-
|
|
|
- // 使用新的刷新方法更新显示
|
|
|
- refreshCurrentBomItemMaterials();
|
|
|
- // 删除物料后重新计算费用
|
|
|
- nextTick(() => {
|
|
|
- calculateTotalCost();
|
|
|
- });
|
|
|
}).catch(() => {
|
|
|
// 用户取消删除
|
|
|
});
|