yyb
9 小时以前 dc128ec95cab469003693b74d95c86447c4d7b6f
src/views/productionManagement/productionProcess/Edit.vue
@@ -186,7 +186,7 @@
      id: newRecord.id,
      name: newRecord.name || '',
      productId: newRecord.productId,
      productModelId: newRecord.productModelId,
      productModelId: getRecordProductModelId(newRecord),
      no: newRecord.no || '',
      type: newRecord.type,
      remark: newRecord.remark || '',
@@ -205,7 +205,7 @@
      id: props.record.id,
      name: props.record.name || '',
      productId: props.record.productId,
      productModelId: props.record.productModelId,
      productModelId: getRecordProductModelId(props.record),
      no: props.record.no || '',
      type: props.record.type,
      remark: props.record.remark || '',
@@ -214,6 +214,7 @@
      plannerName: props.record.plannerName || '',
      isQuality: props.record.isQuality,
    };
    getModelOptions(formState.value.productId);
  }
});
@@ -271,6 +272,32 @@
  return undefined;
};
function findModelIdByName(models, modelName) {
  if (!modelName) {
    return undefined;
  }
  const matched = (models || []).find(item => String(item.model) === String(modelName));
  return matched?.id;
}
function getRecordProductModelId(record) {
  if (!record) {
    return undefined;
  }
  return record.productModelId ?? record.modelId ?? record.specificationModelId ?? undefined;
}
function syncProductModelIdFromModelName() {
  if (formState.value.productModelId || modelOptions.value.length === 0) {
    return;
  }
  const modelName = props.record?.productModel || props.record?.model || props.record?.specificationModel || "";
  const matchedId = findModelIdByName(modelOptions.value, modelName);
  if (matchedId !== undefined) {
    formState.value.productModelId = matchedId;
  }
}
const getProductCategoryOptions = async () => {
  try {
    const res = await productTreeList();
@@ -280,6 +307,7 @@
      formState.value.productId = findNodeIdByLabel(productCategoryOptions.value, formState.value.name);
    }
    await getModelOptions(formState.value.productId);
    syncProductModelIdFromModelName();
  } catch (e) {
    productCategoryOptions.value = [];
  }
@@ -298,6 +326,7 @@
    });
    const records = res?.records || res?.data?.records || [];
    modelOptions.value = records;
    syncProductModelIdFromModelName();
  } catch (e) {
    modelOptions.value = [];
  }