gaoluyang
13 小时以前 7a77afaedc239551008b8fba42f02f85065fbe4b
src/views/productionManagement/processRoute/New.vue
@@ -41,7 +41,7 @@
            v-model="formState.bomId"
            placeholder="请选择BOM"
            clearable
            :disabled="formState.selectedProducts.length !== 1 || bomOptions.length === 0"
            :disabled="bomOptions.length === 0"
            style="width: 100%"
          >
            <el-option
@@ -153,6 +153,38 @@
  }
};
const loadBomOptionsByProducts = async (products) => {
  if (!products?.length) {
    bomOptions.value = [];
    return;
  }
  const bomGroups = await Promise.all(
    products.map(async (product) => {
      try {
        const res = await getByModel(product.id);
        if (Array.isArray(res)) {
          return res;
        }
        if (res && res.data) {
          return Array.isArray(res.data) ? res.data : [res.data];
        }
        return res && typeof res === "object" ? [res] : [];
      } catch (error) {
        return [];
      }
    })
  );
  const bomMap = new Map();
  bomGroups.flat().forEach((item) => {
    if (item?.id && !bomMap.has(item.id)) {
      bomMap.set(item.id, item);
    }
  });
  bomOptions.value = Array.from(bomMap.values());
};
const handleProductSelect = async (products) => {
  if (!products?.length) {
    return;
@@ -174,7 +206,7 @@
    formState.value.productModelId = undefined;
    formState.value.productName = "";
    formState.value.productModelName = "";
    bomOptions.value = [];
    await loadBomOptionsByProducts(products);
  }
  showProductSelectDialog.value = false;
@@ -205,7 +237,7 @@
      productModelName: formState.value.selectedProducts.length === 1
        ? formState.value.selectedProducts[0].model
        : undefined,
      bomId: formState.value.selectedProducts.length === 1 ? formState.value.bomId : undefined,
      bomId: formState.value.bomId,
      description: formState.value.description,
    })
      .then(() => {