spring
7 小时以前 b9c0cee25748ea2d5621a8ca56ceb855a9ce3700
src/views/productionManagement/productStructure/Detail/index.vue
@@ -1,6 +1,6 @@
<template>
  <div class="app-container">
    <PageHeader content="产品结构详情">
  <div :class="embedded ? 'embedded-container' : 'app-container'">
    <PageHeader v-if="!embedded" content="产品结构详情">
      <template #right-button>
        <el-button v-if="!dataValue.isEdit && !isOrderPage"
                   type="primary"
@@ -115,7 +115,7 @@
                    <el-input v-model="row.unit"
                              placeholder="请输入单位"
                              clearable
                               :disabled="!dataValue.isEdit || dataValue.dataList.some(item => (item as any).tempId === row.tempId)" />
                              :disabled="!dataValue.isEdit || dataValue.dataList.some(item => (item as any).tempId === row.tempId)" />
                  </el-form-item>
                </template>
              </el-table-column>
@@ -174,6 +174,18 @@
  const ProductSelectDialog = defineAsyncComponent(
    () => import("@/views/basicData/product/ProductSelectDialog.vue")
  );
  const props = defineProps({
    embedded: {
      type: Boolean,
      default: false,
    },
    // 显式指定BOM主键(用于嵌入到“工艺路线项目”等页面时,路由 query.id 不是 bomId 的情况)
    bomId: {
      type: [String, Number],
      default: undefined,
    },
  });
  const embedded = computed(() => props.embedded);
  const emit = defineEmits(["update:router"]);
  const form = ref();
@@ -181,7 +193,8 @@
  const router = useRouter();
  const routeId = computed({
    get() {
      return route.query.id;
      // 优先使用外部传入的 bomId,其次使用路由的 bomId,最后回退到路由的 id(兼容原页面)
      return props.bomId ?? route.query.bomId ?? route.query.id;
    },
    set(val) {
@@ -227,26 +240,28 @@
  };
  const fetchData = async () => {
    const setNameRecursively = (items: any[]) => {
      items.forEach((item: any) => {
        item.tempId = item.tempId || item.id || new Date().getTime() + Math.random();
        item.processName =
          dataValue.processOptions.find(option => option.id === item.processId)?.name || item.processName || "";
        if (item.children && item.children.length > 0) {
          setNameRecursively(item.children);
        }
      });
    };
    if (isOrderPage.value) {
      // 订单情况:使用订单的产品结构接口
      const { data } = await listProcessBom({ orderId: routeOrderId.value });
      dataValue.dataList = (data as any) || [];
      const list = Array.isArray(data) ? data : (data as any)?.records || [];
      dataValue.dataList = list;
      setNameRecursively(dataValue.dataList);
    } else {
      // 非订单情况:使用原来的接口
      const { data } = await queryList(routeId.value);
      dataValue.dataList = (data as any) || [];
      // 为所有项及其子项设置name属性
      const setNameRecursively = (items: any[]) => {
        items.forEach((item: any) => {
          item.tempId = item.id;
          item.processName =
            dataValue.processOptions.find(option => option.id === item.processId)
              ?.name || "";
          if (item.children && item.children.length > 0) {
            setNameRecursively(item.children);
          }
        });
      };
      setNameRecursively(dataValue.dataList);
      console.log(dataValue.dataList, "dataValue.dataList");
    }
@@ -264,15 +279,20 @@
    const productData = row[0];
    //  最外层组件中,与当前产品相同的产品只能有一个
    const isTopLevel = dataValue.dataList.some(item => (item as any).tempId === dataValue.currentRowName);
    const isTopLevel = dataValue.dataList.some(
      item => (item as any).tempId === dataValue.currentRowName
    );
    if (isTopLevel) {
      if (productData.productName === tableData[0].productName &&
        productData.model === tableData[0].model) {
      if (
        productData.productName === tableData[0].productName &&
        productData.model === tableData[0].model
      ) {
        //  查找是否已经有其他顶层行已经是这个产品
        const hasOther = dataValue.dataList.some(item =>
          (item as any).tempId !== dataValue.currentRowName &&
          (item as any).productName === tableData[0].productName &&
          (item as any).model === tableData[0].model
        const hasOther = dataValue.dataList.some(
          item =>
            (item as any).tempId !== dataValue.currentRowName &&
            (item as any).productName === tableData[0].productName &&
            (item as any).model === tableData[0].model
        );
        if (hasOther) {
          ElMessage.warning("最外层和当前产品一样的一级只能有一个");
@@ -390,7 +410,7 @@
    }
  };
  const removeItem = (tempId:string) => {
  const removeItem = (tempId: string) => {
    // 先尝试从顶层删除
    const topIndex = dataValue.dataList.findIndex(item => item.tempId === tempId);
    if (topIndex !== -1) {
@@ -513,4 +533,11 @@
    await fetchProcessOptions();
    await fetchData();
  });
</script>
</script>
<style scoped>
.embedded-container {
  padding: 0;
  margin: 0;
}
</style>