From 3ab3df4feb3f0fa38154ce540038352ff7953d03 Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期五, 24 四月 2026 15:31:06 +0800
Subject: [PATCH] 产品管理: 将产品选择框从下拉选择改为树形选择

---
 src/views/basicData/product/index.vue |  141 ++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 128 insertions(+), 13 deletions(-)

diff --git a/src/views/basicData/product/index.vue b/src/views/basicData/product/index.vue
index b88d678..0deaa28 100644
--- a/src/views/basicData/product/index.vue
+++ b/src/views/basicData/product/index.vue
@@ -17,6 +17,9 @@
           style="margin-left: 10px"
           >鏂板浜у搧澶х被</el-button
         >
+        <el-button type="success" style="margin-left: 10px" @click="openExportDia">
+          瀵煎嚭
+        </el-button>
       </div>
       <div ref="containerRef">
         <el-tree
@@ -25,18 +28,13 @@
           :data="list"
           @node-click="handleNodeClick"
           :expand-on-click-node="false"
-          default-expand-all
           :default-expanded-keys="expandedKeys"
-          :draggable="true"
           :filter-node-method="filterNode"
           :props="{ children: 'children', label: 'label' }"
           highlight-current
           node-key="id"
-          style="
-            height: calc(100vh - 190px);
-            overflow-y: scroll;
-            scrollbar-width: none;
-          "
+          class="product-tree-scroll"
+          style="height: calc(100vh - 190px); overflow-y: auto"
         >
           <template #default="{ node, data }">
             <div class="custom-tree-node">
@@ -45,7 +43,7 @@
                   <component :is="data.children && data.children.length > 0
                   ? node.expanded ? 'FolderOpened' : 'Folder' : 'Tickets'" />
                 </el-icon>
-                {{ data.label }}
+                <span class="tree-node-label">{{ data.label }}</span>
               </span>
               <div>
                 <el-button
@@ -78,7 +76,7 @@
         <el-button type="primary" @click="openModelDia('add')">
           鏂板瑙勬牸鍨嬪彿
         </el-button>
-        <ImportExcel @uploadSuccess="getModelList" />
+        <ImportExcel :product-id="currentId" @uploadSuccess="getModelList" />
         <el-button
           type="danger"
           @click="handleDelete"
@@ -113,6 +111,8 @@
               <el-input
                 v-model="form.productName"
                 placeholder="璇疯緭鍏ヤ骇鍝佸悕绉�"
+                maxlength="20"
+                show-word-limit
                 clearable
                 @keydown.enter.prevent
               />
@@ -173,6 +173,39 @@
         </div>
       </template>
     </el-dialog>
+    <el-dialog
+      v-model="exportDia"
+      title="瀵煎嚭浜у搧鏁版嵁"
+      width="420px"
+      @keydown.enter.prevent
+    >
+      <el-form label-position="top">
+        <el-form-item label="閫夋嫨浜у搧澶х被锛堝彲涓嶉�夛級">
+          <el-tree-select
+            v-model="exportProductId"
+            :data="rootProductOptions"
+            :props="{ value: 'id', label: 'label', children: 'children' }"
+            clearable
+            filterable
+            check-strictly
+            default-expand-all
+            placeholder="璇烽�夋嫨浜у搧鍒嗙被锛堜笉閫夊垯瀵煎嚭鍏ㄩ儴锛�"
+            style="width: 100%"
+          />
+          <div class="export-tip">
+            宸查�夛細瀵煎嚭璇ュぇ绫诲強鍏跺瓙绫伙紱鏈�夛細瀵煎嚭鍏ㄩ儴
+          </div>
+        </el-form-item>
+      </el-form>
+      <template #footer>
+        <div class="dialog-footer">
+          <el-button type="primary" :loading="exportLoading" :disabled="exportLoading" @click="handleExport">
+            纭瀵煎嚭
+          </el-button>
+          <el-button @click="closeExportDia">鍙栨秷</el-button>
+        </div>
+      </template>
+    </el-dialog>
   </div>
 </template>
 
@@ -184,6 +217,7 @@
   addOrEditProductModel,
   delProduct,
   delProductModel,
+  exportProductData,
   modelListPage,
   productTreeList,
 } from "@/api/basicData/product.js";
@@ -195,14 +229,18 @@
 
 const productDia = ref(false);
 const modelDia = ref(false);
+const exportDia = ref(false);
+const exportLoading = ref(false);
 const modelOperationType = ref("");
 const search = ref("");
 const currentId = ref("");
 const currentParentId = ref("");
+const exportProductId = ref("");
 const operationType = ref("");
 const treeLoad = ref(false);
 const list = ref([]);
 const expandedKeys = ref([]);
+const rootProductOptions = ref([]);
 const tableColumn = ref([
   {
     label: "瑙勬牸鍨嬪彿",
@@ -241,7 +279,10 @@
     productName: "",
   },
   rules: {
-    productName: [{ required: true, message: "璇疯緭鍏�", trigger: "blur" }],
+    productName: [
+      { required: true, message: "璇疯緭鍏�", trigger: "blur" },
+      { max: 20, message: "浜у搧鍚嶇О涓嶈兘瓒呰繃20涓瓧绗�", trigger: "blur" },
+    ],
   },
   modelForm: {
     model: "",
@@ -259,6 +300,7 @@
   productTreeList()
     .then((res) => {
       list.value = res;
+      rootProductOptions.value = Array.isArray(res) ? res : [];
       list.value.forEach((a) => {
         expandedKeys.value.push(a.label);
       });
@@ -425,6 +467,42 @@
       proxy.$modal.msg("宸插彇娑�");
     });
 };
+const openExportDia = () => {
+  exportDia.value = true;
+};
+const closeExportDia = () => {
+  exportDia.value = false;
+};
+// 瀵煎嚭浜у搧锛堝彲鎸夊ぇ绫伙紝鍚瓙绫伙級
+const handleExport = () => {
+  if (exportLoading.value) return;
+  exportLoading.value = true;
+  const params = exportProductId.value ? { productId: exportProductId.value } : {};
+  exportProductData(params)
+    .then((blobData) => {
+      const blob =
+        blobData instanceof Blob
+          ? blobData
+          : new Blob([blobData], {
+              type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
+            });
+      const url = window.URL.createObjectURL(blob);
+      const link = document.createElement("a");
+      link.href = url;
+      link.download = "浜у搧鏁版嵁.xlsx";
+      document.body.appendChild(link);
+      link.click();
+      document.body.removeChild(link);
+      window.URL.revokeObjectURL(url);
+      closeExportDia();
+    })
+    .catch(() => {
+      proxy.$modal.msgError("瀵煎嚭澶辫触锛岃绋嶅悗閲嶈瘯");
+    })
+    .finally(() => {
+      exportLoading.value = false;
+    });
+};
 // 璋冪敤tree杩囨护鏂规硶 涓枃鑻辫繃婊�
 const filterNode = (value, data, node) => {
   if (!value) {
@@ -469,18 +547,21 @@
   display: flex;
 }
 .left {
-  width: 380px;
+  width: 450px;
+  min-width: 450px;
   padding: 16px;
   background: #ffffff;
 }
 .right {
-  width: calc(100% - 380px);
+  flex: 1;
+  min-width: 0;
   padding: 16px;
   margin-left: 20px;
   background: #ffffff;
 }
 .custom-tree-node {
   flex: 1;
+  min-width: 0;
   display: flex;
   align-items: center;
   justify-content: space-between;
@@ -488,13 +569,47 @@
   padding-right: 8px;
 }
 .tree-node-content {
+  flex: 1;
+  min-width: 0;
   display: flex;
-  align-items: center; /* 鍨傜洿灞呬腑 */
+  align-items: center;
   height: 100%;
+  overflow: hidden;
+}
+.tree-node-content .orange-icon {
+  flex-shrink: 0;
+}
+.tree-node-label {
+  overflow: hidden;
+  text-overflow: ellipsis;
+  white-space: nowrap;
 }
 .orange-icon {
   color: orange;
   font-size: 18px;
   margin-right: 8px; /* 鍥炬爣涓庢枃瀛椾箣闂村姞鐐归棿璺� */
 }
+.product-tree-scroll {
+  scrollbar-width: thin;
+  scrollbar-color: #c0c4cc #f5f7fa;
+}
+.product-tree-scroll::-webkit-scrollbar {
+  width: 8px;
+}
+.product-tree-scroll::-webkit-scrollbar-track {
+  background: #f5f7fa;
+  border-radius: 4px;
+}
+.product-tree-scroll::-webkit-scrollbar-thumb {
+  background: #c0c4cc;
+  border-radius: 4px;
+}
+.product-tree-scroll::-webkit-scrollbar-thumb:hover {
+  background: #909399;
+}
+.export-tip {
+  margin-top: 8px;
+  font-size: 12px;
+  color: #909399;
+}
 </style>

--
Gitblit v1.9.3