|
@@ -937,9 +937,6 @@ const toggleShowAllMaterials = () => {
|
|
|
|
|
|
// 切换显示模式时,需要同步更新 materialList
|
|
|
if (!showAllMaterials.value && currentBomItem.value) {
|
|
|
- // 切换到显示当前保养项物料
|
|
|
- // const uniqueKey = `${currentBomItem.value.deviceId}${currentBomItem.value.bomNodeId}`;
|
|
|
- // materialList.value = bomMaterialsMap.value[uniqueKey] || [];
|
|
|
// 切换到显示当前保养项物料时,使用新的刷新方法
|
|
|
refreshCurrentBomItemMaterials();
|
|
|
} else if (showAllMaterials.value) {
|
|
@@ -950,6 +947,10 @@ const toggleShowAllMaterials = () => {
|
|
|
}
|
|
|
materialList.value = allMaterials;
|
|
|
}
|
|
|
+ console.log('切换显示模式:', {
|
|
|
+ showAllMaterials: showAllMaterials.value,
|
|
|
+ materialCount: materialList.value.length
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
// 为表格行添加类名,实现高亮效果
|
|
@@ -1350,18 +1351,24 @@ const openDeviceBomMaterials = (row: any) => {
|
|
|
|
|
|
// 刷新当前保养项的物料列表显示
|
|
|
const refreshCurrentBomItemMaterials = () => {
|
|
|
- if (!currentBomItem.value) return;
|
|
|
+ if (!currentBomItem.value) {
|
|
|
+ materialList.value = [];
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- const uniqueKey = `${currentBomItem.value.deviceId}${currentBomItem.value.bomNodeId}`;
|
|
|
+ const uniqueKey = `${currentBomItem.value.bomNodeId}`;
|
|
|
+
|
|
|
+ // 确保从映射中获取最新数据
|
|
|
+ const currentMaterials = bomMaterialsMap.value[uniqueKey] || [];
|
|
|
|
|
|
// 强制更新 materialList 的引用,确保响应式更新
|
|
|
- materialList.value = bomMaterialsMap.value[uniqueKey] ?
|
|
|
- [...bomMaterialsMap.value[uniqueKey]] : [];
|
|
|
+ materialList.value = [...currentMaterials];
|
|
|
|
|
|
console.log('刷新物料列表:', {
|
|
|
currentBomItem: currentBomItem.value.name,
|
|
|
materialCount: materialList.value.length,
|
|
|
- uniqueKey: uniqueKey
|
|
|
+ uniqueKey: uniqueKey,
|
|
|
+ materials: materialList.value
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -1384,7 +1391,7 @@ const selectChoose = (selectedMaterial) => {
|
|
|
}));
|
|
|
|
|
|
// 生成唯一键
|
|
|
- const uniqueKey = `${targetDeviceId}${targetBomNodeId}`;
|
|
|
+ const uniqueKey = `${targetBomNodeId}`;
|
|
|
// 初始化物料映射(如果不存在)
|
|
|
if (!bomMaterialsMap.value[uniqueKey]) {
|
|
|
bomMaterialsMap.value[uniqueKey] = [];
|
|
@@ -1392,10 +1399,6 @@ const selectChoose = (selectedMaterial) => {
|
|
|
|
|
|
// 避免重复添加
|
|
|
processedMaterials.forEach(newMaterial => {
|
|
|
- // const uniqueKey = `${newMaterial.deviceId}${bomNodeId.value}`;
|
|
|
- /* if (!bomMaterialsMap.value[uniqueKey]) {
|
|
|
- bomMaterialsMap.value[uniqueKey] = [];
|
|
|
- } */
|
|
|
// 检查是否已存在相同 工厂+成本中心+库存地点+bomNodeId + materialCode 的条目
|
|
|
const isExist = bomMaterialsMap.value[uniqueKey].some(item =>
|
|
|
item.bomNodeId === bomNodeId.value &&
|
|
@@ -1410,11 +1413,6 @@ const selectChoose = (selectedMaterial) => {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- // 同步到当前显示的 materialList(如果当前选中了该保养项)
|
|
|
- /* if (currentBomItem.value && currentBomItem.value.bomNodeId === bomNodeId.value) {
|
|
|
- materialList.value = bomMaterialsMap.value[`${currentBomItem.value.deviceId}${bomNodeId.value}`] || [];
|
|
|
- } */
|
|
|
-
|
|
|
// 关键修复:立即更新当前显示的物料列表
|
|
|
refreshCurrentBomItemMaterials();
|
|
|
|
|
@@ -2237,7 +2235,7 @@ onMounted(async () => {
|
|
|
// 处理物料数据映射
|
|
|
if (item.deviceBomMaterials && item.deviceBomMaterials.length > 0) {
|
|
|
// 生成唯一键
|
|
|
- const uniqueKey = `${item.deviceId}${item.bomNodeId}`;
|
|
|
+ const uniqueKey = `${item.bomNodeId}`;
|
|
|
|
|
|
// 转换物料字段映射
|
|
|
const mappedMaterials = item.deviceBomMaterials.map(material => ({
|
|
@@ -2245,7 +2243,8 @@ onMounted(async () => {
|
|
|
materialName: material.name, // name -> materialName
|
|
|
materialCode: material.code, // code -> materialCode
|
|
|
projectDepartment: material.storageLocation, // storageLocation -> projectDepartment
|
|
|
- totalInventoryQuantity: material.stockQuantity // stockQuantity -> totalInventoryQuantity
|
|
|
+ totalInventoryQuantity: material.stockQuantity, // stockQuantity -> totalInventoryQuantity
|
|
|
+ deviceId: item.deviceId // 添加 deviceId,从保养项中获取
|
|
|
}));
|
|
|
// 存储到映射表中
|
|
|
bomMaterialsMap.value[uniqueKey] = mappedMaterials;
|
|
@@ -2285,34 +2284,70 @@ onMounted(async () => {
|
|
|
}
|
|
|
// 查询当前保养工单已经关联的所有物料
|
|
|
const materials = await IotMainWorkOrderBomMaterialApi.getWorkOrderBomMaterials(queryParams);
|
|
|
- materialList.value = []
|
|
|
+ // 修复:重新初始化物料映射,确保接口数据完全覆盖
|
|
|
+ const tempBomMaterialsMap = {};
|
|
|
+ // 首先,用 getWorkOrderBOMs 返回的 deviceBomMaterials 初始化映射
|
|
|
+ list.value.forEach(item => {
|
|
|
+ const uniqueKey = `${item.bomNodeId}`;
|
|
|
+
|
|
|
+ if (item.deviceBomMaterials && item.deviceBomMaterials.length > 0) {
|
|
|
+ tempBomMaterialsMap[uniqueKey] = item.deviceBomMaterials.map(material => ({
|
|
|
+ ...material,
|
|
|
+ materialName: material.name,
|
|
|
+ materialCode: material.code,
|
|
|
+ projectDepartment: material.storageLocation,
|
|
|
+ totalInventoryQuantity: material.stockQuantity,
|
|
|
+ deviceId: item.deviceId // 添加 deviceId
|
|
|
+ }));
|
|
|
+ } else {
|
|
|
+ tempBomMaterialsMap[uniqueKey] = [];
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // materialList.value = []
|
|
|
// 修改:如果有已关联的物料,使用接口返回的数据覆盖默认数据
|
|
|
if (Array.isArray(materials) && materials.length > 0) {
|
|
|
- // materialList.value = materials;
|
|
|
-
|
|
|
// 同时更新 bomMaterialsMap
|
|
|
materials.forEach(material => {
|
|
|
- const uniqueKey = `${material.deviceId}${material.bomNodeId}`;
|
|
|
- if (!bomMaterialsMap.value[uniqueKey]) {
|
|
|
- bomMaterialsMap.value[uniqueKey] = [];
|
|
|
+ // 通过 bomNodeId 在 list 中查找对应的保养项,获取 deviceId
|
|
|
+ const correspondingItem = list.value.find(item => item.bomNodeId === material.bomNodeId);
|
|
|
+ const deviceId = correspondingItem ? correspondingItem.deviceId : null;
|
|
|
+
|
|
|
+ const uniqueKey = `${material.bomNodeId}`;
|
|
|
+ if (!tempBomMaterialsMap[uniqueKey]) {
|
|
|
+ tempBomMaterialsMap[uniqueKey] = [];
|
|
|
}
|
|
|
+ // 添加 deviceId 到物料数据
|
|
|
+ const materialWithDeviceId = {
|
|
|
+ ...material,
|
|
|
+ deviceId: deviceId
|
|
|
+ };
|
|
|
// 避免重复添加
|
|
|
- const existingIndex = bomMaterialsMap.value[uniqueKey].findIndex(item =>
|
|
|
+ const existingIndex = tempBomMaterialsMap[uniqueKey].findIndex(item =>
|
|
|
item.materialCode === material.materialCode &&
|
|
|
item.factoryId === material.factoryId &&
|
|
|
item.costCenterId === material.costCenterId &&
|
|
|
item.storageLocationId === material.storageLocationId
|
|
|
);
|
|
|
if (existingIndex === -1) {
|
|
|
- bomMaterialsMap.value[uniqueKey].push(material);
|
|
|
+ tempBomMaterialsMap[uniqueKey].push(materialWithDeviceId);
|
|
|
} else {
|
|
|
- // 如果已存在,更新数据(使用接口返回的最新数据)
|
|
|
- bomMaterialsMap.value[uniqueKey][existingIndex] = material;
|
|
|
+ // 覆盖更新,优先使用 getWorkOrderBomMaterials 的数据
|
|
|
+ tempBomMaterialsMap[uniqueKey][existingIndex] = materialWithDeviceId;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ // 更新响应式映射
|
|
|
+ bomMaterialsMap.value = tempBomMaterialsMap;
|
|
|
+
|
|
|
+ // 如果有数据,选中第一个保养项并显示其物料
|
|
|
if (list.value.length > 0) {
|
|
|
- handleBomItemClick(list.value[0]);
|
|
|
+ // 确保第一个保养项的物料正确显示
|
|
|
+ const firstItem = list.value[0];
|
|
|
+ const uniqueKey = `${firstItem.bomNodeId}`;
|
|
|
+ materialList.value = bomMaterialsMap.value[uniqueKey] || [];
|
|
|
+
|
|
|
+ handleBomItemClick(firstItem);
|
|
|
}
|
|
|
// 页面初始化完成后立即计算费用
|
|
|
nextTick(() => {
|
|
@@ -2347,11 +2382,6 @@ const handleBomItemClick = (item) => {
|
|
|
currentBomItem.value = item;
|
|
|
// 切换到当前保养项物料视图
|
|
|
showAllMaterials.value = false;
|
|
|
- // 生成唯一键
|
|
|
- // const uniqueKey = `${item.deviceId}${item.bomNodeId}`;
|
|
|
-
|
|
|
- // 更新物料列表
|
|
|
- // materialList.value = bomMaterialsMap.value[uniqueKey] || [];
|
|
|
|
|
|
// 使用新的刷新方法
|
|
|
refreshCurrentBomItemMaterials();
|