gaoluyang
14 小时以前 cca940a6460bc4ec4266df4e413b05921d1f2e1d
src/views/productionManagement/processRoute/New.vue
@@ -75,7 +75,7 @@
<script setup>
import { computed, getCurrentInstance, ref } from "vue";
import { add } from "@/api/productionManagement/processRoute.js";
import { getByModel } from "@/api/productionManagement/productBom.js";
import { getByModelList } from "@/api/productionManagement/productBom.js";
import ProductSelectDialog from "@/views/basicData/product/ProductSelectDialog.vue";
const props = defineProps({
@@ -131,14 +131,14 @@
  isShow.value = false;
};
const loadBomList = async (productModelId) => {
  if (!productModelId) {
const loadBomList = async (productModelIds) => {
  if (!productModelIds?.length) {
    bomOptions.value = [];
    return;
  }
  try {
    const res = await getByModel(productModelId);
    const res = await getByModelList(productModelIds);
    if (Array.isArray(res)) {
      bomOptions.value = res;
      return;
@@ -151,38 +151,6 @@
  } catch (error) {
    bomOptions.value = [];
  }
};
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) => {
@@ -200,13 +168,13 @@
    formState.value.productModelId = product.id;
    formState.value.productName = product.productName;
    formState.value.productModelName = product.model;
    await loadBomList(product.id);
    await loadBomList([product.id]);
  } else {
    formState.value.productId = undefined;
    formState.value.productModelId = undefined;
    formState.value.productName = "";
    formState.value.productModelName = "";
    await loadBomOptionsByProducts(products);
    await loadBomList(products.map((product) => product.id));
  }
  showProductSelectDialog.value = false;