From 79fb20a2102f2d6a050b83f20477aa13b221f096 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期四, 26 三月 2026 09:16:29 +0800
Subject: [PATCH] 军泰伟业 1.bom添加可以按bom添加物料清单功能,并不用绑定工序

---
 src/views/productionManagement/productStructure/Detail/index.vue |  341 ++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 303 insertions(+), 38 deletions(-)

diff --git a/src/views/productionManagement/productStructure/Detail/index.vue b/src/views/productionManagement/productStructure/Detail/index.vue
index 6734830..7807a6d 100644
--- a/src/views/productionManagement/productStructure/Detail/index.vue
+++ b/src/views/productionManagement/productStructure/Detail/index.vue
@@ -2,16 +2,21 @@
   <div class="app-container">
     <PageHeader content="浜у搧缁撴瀯璇︽儏">
       <template #right-button>
+        <el-button v-if="dataValue.isEdit && !isOrderPage"
+                   @click="cancelEdit">鍙栨秷
+        </el-button>
         <el-button v-if="!dataValue.isEdit && !isOrderPage"
                    type="primary"
-                   @click="dataValue.isEdit = true">缂栬緫
-        </el-button>
-        <el-button v-if="dataValue.isEdit && !isOrderPage"
-                   type="primary"
-                   @click="cancelEdit">鍙栨秷
+                   @click="dataValue.isEdit = true">鐐瑰嚮杩涜淇敼
         </el-button>
         <el-button v-if="!isOrderPage"
                    type="primary"
+                   @click="openBomAddDialog"
+                   :disabled="!dataValue.isEdit">
+          <el-icon><Document /></el-icon> 鎸塀OM娣诲姞
+        </el-button>
+        <el-button v-if="!isOrderPage"
+                   type="success"
                    :loading="dataValue.loading"
                    @click="submit"
                    :disabled="!dataValue.isEdit">纭
@@ -34,30 +39,30 @@
                       style="width: 100%">
               <el-table-column prop="productName"
                                label="浜у搧" />
-              <el-table-column prop="model"
-                               label="瑙勬牸">
-                <template #default="{ row, $index }">
-                  <el-form-item v-if="dataValue.isEdit"
-                                :rules="[{ required: true, message: '璇烽�夋嫨瑙勬牸', trigger: ['blur','change'] }]"
-                                style="margin: 0">
-                    <el-select v-model="row.model"
-                               placeholder="璇烽�夋嫨瑙勬牸"
-                               clearable
-                               :disabled="!dataValue.isEdit || dataValue.dataList.some(item => (item as any).tempId === row.tempId)"
-                               style="width: 100%"
-                               @visible-change="(v) => { if (v) openDialog(row.tempId) }">
-                      <el-option v-if="row.model"
-                                 :label="row.model"
-                                 :value="row.model" />
-                    </el-select>
-                  </el-form-item>
-                </template>
-              </el-table-column>
+							<el-table-column prop="model"
+															 label="鍥剧焊缂栧彿">
+								<template #default="{ row, $index }">
+									<el-form-item v-if="dataValue.isEdit"
+															:rules="[{ required: true, message: '璇烽�夋嫨瑙勬牸', trigger: ['blur','change'] }]"
+															style="margin: 0">
+										<el-select v-model="row.model"
+															 placeholder="璇烽�夋嫨瑙勬牸"
+															 clearable
+															 :disabled="!dataValue.isEdit || dataValue.dataList.some(item => (item as any).tempId === row.tempId)"
+															 style="width: 100%"
+															 @visible-change="(v) => { if (v) openDialog(row.tempId) }">
+											<el-option v-if="row.model"
+																 :label="row.model"
+																 :value="row.model" />
+										</el-select>
+									</el-form-item>
+								</template>
+							</el-table-column>
               <el-table-column prop="processName"
-                               label="娑堣�楀伐搴�">
+                               label="宸ュ簭">
                 <template #default="{ row, $index }">
                   <el-form-item v-if="dataValue.isEdit"
-                                :rules="dataValue.dataList.some(item => (item as any).tempId === row.tempId) ? [] : [{ required: true, message: '璇烽�夋嫨娑堣�楀伐搴�', trigger: 'change' }]"
+                                :rules="dataValue.dataList.some(item => (item as any).tempId === row.tempId) ? [] : [{ required: true, message: '璇烽�夊伐搴�', trigger: 'change' }]"
                                 style="margin: 0">
                     <el-select v-model="row.processId"
                                placeholder="璇烽�夋嫨"
@@ -74,10 +79,10 @@
                 </template>
               </el-table-column>
               <el-table-column prop="unitQuantity"
-                               label="鍗曚綅浜у嚭鎵�闇�鏁伴噺">
+                               label="鍗曚綅鐢ㄩ噺">
                 <template #default="{ row, $index }">
                   <el-form-item v-if="dataValue.isEdit"
-                                :rules="[{ required: true, message: '璇疯緭鍏ュ崟浣嶄骇鍑烘墍闇�鏁伴噺', trigger: ['blur','change'] }]"
+                                :rules="[{ required: true, message: '璇疯緭鍏ュ崟浣嶇敤閲�', trigger: ['blur','change'] }]"
                                 style="margin: 0">
                     <el-input-number v-model="row.unitQuantity"
                                      :min="0"
@@ -143,12 +148,57 @@
                        prop="bomNo" />
       <el-table-column label="浜у搧鍚嶇О"
                        prop="productName" />
-      <el-table-column label="瑙勬牸鍨嬪彿"
-                       prop="model" />
+			<el-table-column label="鍥剧焊缂栧彿"
+														 prop="model" />
     </el-table>
     <product-select-dialog v-if="dataValue.showProductDialog"
                            v-model:model-value="dataValue.showProductDialog"
                            @confirm="handleProduct" />
+
+    <!-- 鎸塀OM娣诲姞寮圭獥 -->
+    <el-dialog v-model="bomAddDialogVisible" title="鎸塀OM娣诲姞" width="500px" @close="closeBomAddDialog">
+      <el-form ref="bomAddFormRef" :model="bomAddForm" :rules="bomAddRules" label-width="100px">
+        <el-form-item label="鐖堕」浜у搧" prop="parentProductId">
+          <el-select v-model="bomAddForm.parentProductId" placeholder="璇烽�夋嫨" clearable filterable
+            style="width: 100%" @change="handleBomParentProductChange">
+            <el-option v-for="item in parentProductOptions" :key="item.id"
+              :label="`${item.model || item.productCode || item.id} | ${item.productName}`"
+              :value="item.id" />
+          </el-select>
+        </el-form-item>
+        <!-- 閫変腑浜у搧鍚庡睍绀轰骇鍝佷俊鎭� -->
+        <div v-if="selectedBomProduct" class="selected-product-info">
+          <div class="product-info-row">
+            <span class="info-label">浜у搧缂栧彿</span>
+            <span class="info-value">{{ selectedBomProduct.model || selectedBomProduct.productCode || '-' }}</span>
+          </div>
+          <div class="product-info-row">
+            <span class="info-label">浜у搧鍚嶇О</span>
+            <span class="info-value">{{ selectedBomProduct.productName || '-' }}</span>
+          </div>
+          <div class="product-info-row">
+            <span class="info-label">浜у搧瑙勬牸</span>
+            <span class="info-value">{{ selectedBomProduct.spec || selectedBomProduct.drawingNumber || '-' }}</span>
+          </div>
+          <div class="stock-info-box">
+            <div class="stock-number">{{ selectedBomProduct.stockQuantity || 0 }}</div>
+            <div class="stock-label">搴撳瓨鏁伴噺(鍙�)</div>
+          </div>
+        </div>
+        <el-form-item label="鐢ㄩ噺绯绘暟" prop="coefficient" style="margin-top: 20px;">
+          <el-input-number v-model="bomAddForm.coefficient" :min="0.01" :precision="2" :step="1"
+            controls-position="right" style="width: 100%" />
+        </el-form-item>
+      </el-form>
+      <template #footer>
+        <el-button type="primary" @click="submitBomAdd">纭畾</el-button>
+        <el-button @click="closeBomAddDialog">鍙栨秷</el-button>
+      </template>
+    </el-dialog>
+
+    <!-- 楂樼骇閫夋嫨浜у搧寮圭獥 -->
+    <product-select-dialog v-if="showAdvancedProductDialog" v-model:model-value="showAdvancedProductDialog"
+      @confirm="handleAdvancedProductSelect" />
   </div>
 </template>
 
@@ -161,11 +211,14 @@
     reactive,
     ref,
   } from "vue";
-  import { queryList, add } from "@/api/productionManagement/productStructure.js";
+  import { queryList, add, listByBomIdIsParent } from "@/api/productionManagement/productStructure.js";
   import { listProcessBom } from "@/api/productionManagement/productionOrder.js";
   import { list } from "@/api/productionManagement/productionProcess";
+  import { productListPage } from "@/api/basicData/product.js";
+  import { listPage as listBomPage } from "@/api/productionManagement/productBom.js";
   import { ElMessage } from "element-plus";
   import { useRoute, useRouter } from "vue-router";
+  import { Search, Document } from '@element-plus/icons-vue'
 
   defineComponent({
     name: "StructureEdit",
@@ -192,6 +245,7 @@
   // 浠庤矾鐢卞弬鏁拌幏鍙栦骇鍝佷俊鎭�
   const routeBomNo = computed(() => route.query.bomNo || "");
   const routeProductName = computed(() => route.query.productName || "");
+  const routeDrawingNumber = computed(() => route.query.drawingNumber || "");
   const routeProductModelName = computed(
     () => route.query.productModelName || ""
   );
@@ -212,9 +266,25 @@
     isEdit: false,
   });
 
+  // 鎸塀OM娣诲姞鐩稿叧
+  const bomAddDialogVisible = ref(false);
+  const bomAddFormRef = ref();
+  const parentProductOptions = ref([]);
+  const selectedBomProduct = ref(null);
+  const selectedBomTreeData = ref([]); // 淇濆瓨閫変腑浜у搧鏃惰幏鍙栫殑BOM鏍戞暟鎹�
+  const bomAddForm = reactive({
+    parentProductId: undefined,
+    coefficient:1
+  });
+  const bomAddRules = {
+    parentProductId: [{ required: true, message: "璇烽�夋嫨鐖堕」浜у搧", trigger: "change" }],
+    coefficient: [{ required: true, message: "璇疯緭鍏ョ敤閲忕郴鏁�", trigger: "blur" }]
+  };
+
   const tableData = reactive([
     {
       productName: "",
+      drawingNumber: "",
       model: "",
       bomNo: "",
     },
@@ -293,6 +363,7 @@
     dataValue.dataList.map(item => {
       if (item.tempId === dataValue.currentRowName) {
         item.productName = productData.productName;
+        item.drawingNumber = productData.drawingNumber || "";
         item.model = productData.model;
         item.productModelId = productData.id;
         item.unit = productData.unit || "";
@@ -305,6 +376,7 @@
   const childItem = (item: any, tempId: any, productData: any) => {
     if (item.tempId === tempId) {
       item.productName = productData.productName;
+      item.drawingNumber = productData.drawingNumber || "";
       item.model = productData.model;
       item.productModelId = productData.id;
       item.unit = productData.unit || "";
@@ -332,13 +404,8 @@
         isValid = false;
         return;
       }
-      if (!isTopLevel && !item.processId) {
-        ElMessage.error("璇烽�夋嫨娑堣�楀伐搴�");
-        isValid = false;
-        return;
-      }
       if (!item.unitQuantity) {
-        ElMessage.error("璇疯緭鍏ュ崟浣嶄骇鍑烘墍闇�鏁伴噺");
+        ElMessage.error("璇疯緭鍏ュ崟浣嶇敤閲�");
         isValid = false;
         return;
       }
@@ -503,9 +570,155 @@
     fetchData();
   };
 
+  // 鑾峰彇鐖堕」浜у搧鍒楄〃
+  const getParentProductList = async () => {
+    try {
+      const { data } = await listBomPage({ current: 1, size: 1000 });
+      parentProductOptions.value = data?.records || [];
+    } catch (error) {
+      console.error("鑾峰彇鐖堕」浜у搧鍒楄〃澶辫触:", error);
+      parentProductOptions.value = [];
+    }
+  };
+
+  // 鎵撳紑鎸塀OM娣诲姞寮圭獥
+  const openBomAddDialog = () => {
+    bomAddDialogVisible.value = true;
+    bomAddForm.parentProductId = undefined;
+    bomAddForm.coefficient = 1;
+    selectedBomProduct.value = null;
+    getParentProductList();
+  };
+
+  // 鍏抽棴鎸塀OM娣诲姞寮圭獥
+  const closeBomAddDialog = () => {
+    bomAddDialogVisible.value = false;
+    bomAddFormRef.value?.resetFields();
+    selectedBomProduct.value = null;
+  };
+
+  // 鎵撳紑楂樼骇閫夋嫨
+  const openAdvancedSelect = () => {
+    showAdvancedProductDialog.value = true;
+  };
+
+  // 鐖堕」浜у搧鍙樻洿
+  const handleBomParentProductChange = async (val) => {
+    if (val) {
+      const product = parentProductOptions.value.find(item => item.id === val);
+      selectedBomProduct.value = product || null;
+      
+      // 鐩存帴鐢ㄩ�変腑鐨� BOM ID 璋冪敤 listByBomIdIsParent
+      const { data: treeData } = await listByBomIdIsParent(val);
+      selectedBomTreeData.value = treeData || [];
+      // 灏嗕簩绾ф爲涓殑浜у搧娣诲姞鍒扮埗椤逛骇鍝侀�夐」锛堜粠绗簩绾у紑濮嬶級
+      const addTreeToOptions = (items: any[]) => {
+        items.forEach((item: any) => {
+          // 璺宠繃绗竴绾э紝鍙坊鍔犵浜岀骇鍙婁互涓嬬殑浜у搧
+          if (item.children && item.children.length > 0) {
+            item.children.forEach((child: any) => {
+              const exists = parentProductOptions.value.some(opt => opt.id === child.id);
+              if (!exists) {
+                parentProductOptions.value.push({
+                  id: child.id,
+                  productName: child.productName,
+                  model: child.model,
+                  productCode: child.model,
+                  spec: child.drawingNumber,
+                  drawingNumber: child.drawingNumber,
+                  stockQuantity: child.stockQuantity || 0
+                });
+              }
+              // 閫掑綊娣诲姞瀛愰」
+              if (child.children && child.children.length > 0) {
+                addTreeToOptions([child]);
+              }
+            });
+          }
+        });
+      };
+      if (selectedBomTreeData.value.length > 0) {
+        addTreeToOptions(selectedBomTreeData.value);
+      }
+    } else {
+      selectedBomProduct.value = null;
+      selectedBomTreeData.value = [];
+    }
+  };
+
+  // 鎻愪氦鎸塀OM娣诲姞
+  const submitBomAdd = () => {
+    bomAddFormRef.value.validate(async (valid) => {
+      if (!valid) return;
+
+      const product = parentProductOptions.value.find(item => item.id === bomAddForm.parentProductId);
+      if (!product) {
+        ElMessage.error("鏈壘鍒伴�変腑鐨勪骇鍝�");
+        return;
+      }
+
+      try {
+        // 浣跨敤閫夋嫨浜у搧鏃朵繚瀛樼殑BOM鏍戞暟鎹�
+        const bomItems = selectedBomTreeData.value || [];
+
+        if (bomItems.length === 0) {
+          ElMessage.warning("璇ヤ骇鍝佹病鏈塀OM淇℃伅");
+          return;
+        }
+
+        // 鍒楄〃鐨勭涓�绾у凡缁忓瓨鍦紝鎶夿OM鏁版嵁浣滀负绗竴绾х殑瀛愰」锛堢浜岀骇锛夋坊鍔�
+        if (dataValue.dataList.length > 0) {
+          const firstLevelItem = dataValue.dataList[0];
+          
+          // 鎶夿OM鏁版嵁娣诲姞鍒扮涓�绾х殑children涓�
+          const addBomItemsRecursively = (items: any[], parentItem: any) => {
+            items.forEach((item: any) => {
+              const newItem: any = {
+                parentId: item.parentId || "",
+                parentTempId: parentItem.tempId || "",
+                productName: item.productName || "",
+                productId: item.productId || item.productModelId || "",
+                model: item.model || "",
+                productModelId: item.productModelId || "",
+                drawingNumber: item.drawingNumber || "",
+                processId: item.processId || "",
+                processName: item.processName || "",
+                unitQuantity: (item.unitQuantity || 0) * bomAddForm.coefficient,
+                demandedQuantity: (item.demandedQuantity || 0) * bomAddForm.coefficient,
+                unit: item.unit || "",
+                children: [],
+                tempId: new Date().getTime() + Math.random(),
+              };
+
+              // 娣诲姞鍒扮埗椤圭殑children
+              if (!parentItem.children) {
+                parentItem.children = [];
+              }
+              parentItem.children.push(newItem);
+
+              // 閫掑綊澶勭悊瀛愰」
+              if (item.children && item.children.length > 0) {
+                addBomItemsRecursively(item.children, newItem);
+              }
+            });
+          };
+
+          addBomItemsRecursively(bomItems, firstLevelItem);
+        }
+
+        ElMessage.success("娣诲姞鎴愬姛");
+        closeBomAddDialog();
+      } catch (error) {
+        console.error("鎸塀OM娣诲姞澶辫触:", error);
+        ElMessage.error("娣诲姞澶辫触");
+      }
+    });
+  };
+
   onMounted(async () => {
     // 浠庤矾鐢卞弬鏁板洖鏄炬暟鎹�
     tableData[0].productName = routeProductName.value as string;
+    tableData[0].drawingNumber = routeDrawingNumber.value as string;
     tableData[0].model = routeProductModelName.value as string;
     tableData[0].bomNo = routeBomNo.value as string;
 
@@ -518,4 +731,56 @@
     await fetchProcessOptions();
     await fetchData();
   });
-</script>
\ No newline at end of file
+</script>
+
+<style scoped>
+.selected-product-info {
+  background-color: #f5f7fa;
+  border-radius: 4px;
+  padding: 16px;
+  margin: 10px 0;
+  position: relative;
+}
+
+.product-info-row {
+  display: flex;
+  margin-bottom: 8px;
+  font-size: 14px;
+}
+
+.product-info-row:last-child {
+  margin-bottom: 0;
+}
+
+.info-label {
+  color: #909399;
+  width: 70px;
+  flex-shrink: 0;
+}
+
+.info-value {
+  color: #303133;
+  flex: 1;
+}
+
+.stock-info-box {
+  position: absolute;
+  right: 16px;
+  top: 50%;
+  transform: translateY(-50%);
+  text-align: center;
+}
+
+.stock-number {
+  font-size: 28px;
+  font-weight: bold;
+  color: #303133;
+  line-height: 1;
+  margin-bottom: 4px;
+}
+
+.stock-label {
+  font-size: 12px;
+  color: #909399;
+}
+</style>

--
Gitblit v1.9.3