From ab58d64f07cbeacaa9a171119d575a6fe70048ff Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期四, 23 四月 2026 13:02:42 +0800
Subject: [PATCH] fix: bom复制

---
 src/api/productionManagement/productBom.js                |    9 ++++
 src/views/productionManagement/productStructure/index.vue |   61 +++++++++++++++++++++++++++---
 2 files changed, 63 insertions(+), 7 deletions(-)

diff --git a/src/api/productionManagement/productBom.js b/src/api/productionManagement/productBom.js
index 2badea8..2d5508e 100644
--- a/src/api/productionManagement/productBom.js
+++ b/src/api/productionManagement/productBom.js
@@ -28,6 +28,15 @@
   });
 }
 
+// 澶嶅埗
+export function copyBom(data) {
+  return request({
+    url: "/productBom/copy",
+    method: "post",
+    data: data,
+  });
+}
+
 // 鎵归噺鍒犻櫎
 export function batchDelete(ids) {
   return request({
diff --git a/src/views/productionManagement/productStructure/index.vue b/src/views/productionManagement/productStructure/index.vue
index 230f90e..2e61e63 100644
--- a/src/views/productionManagement/productStructure/index.vue
+++ b/src/views/productionManagement/productStructure/index.vue
@@ -18,12 +18,12 @@
     <StructureEdit v-if="showEdit" v-model:show-model="showEdit" :record="currentRow" />
 
     <!-- 鏂板/缂栬緫寮圭獥 -->
-    <el-dialog v-model="dialogVisible" :title="operationType === 'add' ? '鏂板BOM' : '缂栬緫BOM'" width="600px"
+    <el-dialog v-model="dialogVisible" :title="dialogTitle" width="600px"
       @close="closeDialog">
       <el-form ref="formRef" :model="form" :rules="rules" label-width="120px">
         <el-form-item label="浜у搧鍚嶇О" prop="productModelId">
           <el-button type="primary" @click="showProductSelectDialog = true">
-            {{ form.productName || '閫夋嫨浜у搧' }}
+            {{ form.productName || form.productModelName || '閫夋嫨浜у搧' }}
           </el-button>
         </el-form-item>
         <el-form-item label="鐗堟湰鍙�" prop="version">
@@ -51,9 +51,9 @@
 </template>
 
 <script setup>
-import { ref, reactive, toRefs, onMounted, getCurrentInstance, defineAsyncComponent } from "vue";
+import { ref, reactive, toRefs, computed, onMounted, getCurrentInstance, defineAsyncComponent } from "vue";
 import { getToken } from "@/utils/auth";
-import { listPage, add, update, batchDelete, exportBom, downloadTemplate } from "@/api/productionManagement/productBom.js";
+import { listPage, add, update, copyBom, batchDelete, exportBom, downloadTemplate } from "@/api/productionManagement/productBom.js";
 import { useRouter } from 'vue-router'
 import { ElMessageBox } from 'element-plus'
 import ProductSelectDialog from "@/views/basicData/product/ProductSelectDialog.vue";
@@ -102,13 +102,20 @@
     label: "鎿嶄綔",
     align: "center",
     fixed: "right",
-    width: 150,
+    width: 220,
     operation: [
       {
         name: "缂栬緫",
         type: "text",
         clickFun: (row) => {
           handleEdit(row)
+        }
+      },
+      {
+        name: "澶嶅埗",
+        type: "text",
+        clickFun: (row) => {
+          handleCopy(row)
         }
       },
       {
@@ -129,9 +136,18 @@
 const selectedRows = ref([]);
 const currentRow = ref({});
 const dialogVisible = ref(false);
-const operationType = ref('add'); // add | edit
+const operationType = ref('add'); // add | edit | copy
+const copySourceId = ref(undefined);
 const formRef = ref(null);
 const showProductSelectDialog = ref(false);
+const dialogTitle = computed(() => {
+  const titleMap = {
+    add: "鏂板BOM",
+    edit: "缂栬緫BOM",
+    copy: "澶嶅埗BOM"
+  };
+  return titleMap[operationType.value] || "BOM";
+});
 
 //  BOM瀵煎叆鍙傛暟
 const upload = reactive({
@@ -205,6 +221,7 @@
 // 鏂板
 const handleAdd = () => {
   operationType.value = 'add';
+  copySourceId.value = undefined;
   Object.assign(form.value, {
     id: undefined,
     productName: "",
@@ -219,6 +236,7 @@
 // 缂栬緫
 const handleEdit = (row) => {
   operationType.value = 'edit';
+  copySourceId.value = undefined;
   Object.assign(form.value, {
     id: row.id,
     productName: row.productName || "",
@@ -226,6 +244,21 @@
     productModelId: row.productModelId || "",
     remark: row.remark || "",
     version: row.version || ""
+  });
+  dialogVisible.value = true;
+};
+
+// 澶嶅埗
+const handleCopy = (row) => {
+  operationType.value = 'copy';
+  copySourceId.value = row.id;
+  Object.assign(form.value, {
+    id: undefined,
+    productName: "",
+    productModelName: "",
+    productModelId: "",
+    remark: "",
+    version: ""
   });
   dialogVisible.value = true;
 };
@@ -301,7 +334,7 @@
           .catch(() => {
             proxy.$modal.msgError('鏂板澶辫触');
           });
-      } else {
+      } else if (operationType.value === 'edit') {
         update(payload)
           .then(() => {
             proxy.$modal.msgSuccess('淇敼鎴愬姛');
@@ -311,6 +344,19 @@
           .catch(() => {
             proxy.$modal.msgError('淇敼澶辫触');
           });
+      } else {
+        copyBom({
+          ...payload,
+          copyId: copySourceId.value
+        })
+          .then(() => {
+            proxy.$modal.msgSuccess('澶嶅埗鎴愬姛');
+            closeDialog();
+            getList();
+          })
+          .catch(() => {
+            proxy.$modal.msgError('澶嶅埗澶辫触');
+          });
       }
     }
   });
@@ -319,6 +365,7 @@
 // 鍏抽棴寮圭獥
 const closeDialog = () => {
   dialogVisible.value = false;
+  copySourceId.value = undefined;
   formRef.value?.resetFields();
 };
 

--
Gitblit v1.9.3