|
@@ -2375,7 +2375,7 @@ onMounted(async () => {
|
|
|
: '';
|
|
|
|
|
|
// 处理物料数据映射
|
|
|
- if (item.deviceBomMaterials && item.deviceBomMaterials.length > 0) {
|
|
|
+ /* if (item.deviceBomMaterials && item.deviceBomMaterials.length > 0) {
|
|
|
// 生成唯一键
|
|
|
const uniqueKey = `${item.bomNodeId}`;
|
|
|
|
|
@@ -2390,7 +2390,7 @@ onMounted(async () => {
|
|
|
}));
|
|
|
// 存储到映射表中
|
|
|
bomMaterialsMap.value[uniqueKey] = mappedMaterials;
|
|
|
- }
|
|
|
+ } */
|
|
|
|
|
|
if (item.mileageRule === 0) {
|
|
|
item.nextMaintenanceKm = calculateNextMaintenanceKm(item);
|
|
@@ -2426,43 +2426,25 @@ onMounted(async () => {
|
|
|
}
|
|
|
// 查询当前保养工单已经关联的所有物料
|
|
|
const materials = await IotMainWorkOrderBomMaterialApi.getWorkOrderBomMaterials(queryParams);
|
|
|
- // 修复:重新初始化物料映射,确保接口数据完全覆盖
|
|
|
+ // 重新初始化物料映射,确保接口数据完全覆盖
|
|
|
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 = []
|
|
|
- // 修改:如果有已关联的物料,使用接口返回的数据覆盖默认数据
|
|
|
+ // 首先,用 getWorkOrderBomMaterials 返回的数据初始化映射(主数据源)
|
|
|
if (Array.isArray(materials) && materials.length > 0) {
|
|
|
- // 同时更新 bomMaterialsMap
|
|
|
materials.forEach(material => {
|
|
|
- // 通过 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 到物料数据
|
|
|
+
|
|
|
+ // 通过 bomNodeId 在 list 中查找对应的保养项,获取 deviceId
|
|
|
+ const correspondingItem = list.value.find(item => item.bomNodeId === material.bomNodeId);
|
|
|
+ const deviceId = correspondingItem ? correspondingItem.deviceId : null;
|
|
|
+
|
|
|
const materialWithDeviceId = {
|
|
|
...material,
|
|
|
deviceId: deviceId
|
|
|
};
|
|
|
+
|
|
|
// 避免重复添加
|
|
|
const existingIndex = tempBomMaterialsMap[uniqueKey].findIndex(item =>
|
|
|
item.materialCode === material.materialCode &&
|
|
@@ -2470,14 +2452,36 @@ onMounted(async () => {
|
|
|
item.costCenterId === material.costCenterId &&
|
|
|
item.storageLocationId === material.storageLocationId
|
|
|
);
|
|
|
+
|
|
|
if (existingIndex === -1) {
|
|
|
tempBomMaterialsMap[uniqueKey].push(materialWithDeviceId);
|
|
|
} else {
|
|
|
- // 覆盖更新,优先使用 getWorkOrderBomMaterials 的数据
|
|
|
tempBomMaterialsMap[uniqueKey][existingIndex] = materialWithDeviceId;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+ // 其次,对于 getWorkOrderBOMs 接口返回的 deviceBomMaterials,
|
|
|
+ // 只有当 getWorkOrderBomMaterials 中没有对应保养项的物料时,才使用 deviceBomMaterials 作为备用
|
|
|
+ list.value.forEach(item => {
|
|
|
+ const uniqueKey = `${item.bomNodeId}`;
|
|
|
+
|
|
|
+ // 如果 getWorkOrderBomMaterials 中没有这个保养项的物料,且 deviceBomMaterials 有值,则使用备用数据
|
|
|
+ if ((!tempBomMaterialsMap[uniqueKey] || tempBomMaterialsMap[uniqueKey].length === 0) &&
|
|
|
+ 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
|
|
|
+ }));
|
|
|
+ } else if (!tempBomMaterialsMap[uniqueKey]) {
|
|
|
+ // 确保每个保养项在映射中都有对应的数组(即使是空的)
|
|
|
+ tempBomMaterialsMap[uniqueKey] = [];
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
// 更新响应式映射
|
|
|
bomMaterialsMap.value = tempBomMaterialsMap;
|