From d1d3ea967d916d798dbb1979130137bdd5b6152c Mon Sep 17 00:00:00 2001
From: yuan <123@>
Date: 星期一, 18 五月 2026 10:22:37 +0800
Subject: [PATCH] feat(search): 基础产品维护子节点模糊查询

---
 src/views/basicData/product/index.vue |   53 ++++++++++++++++++++++-------------------------------
 1 files changed, 22 insertions(+), 31 deletions(-)

diff --git a/src/views/basicData/product/index.vue b/src/views/basicData/product/index.vue
index 07da49b..b05b215 100644
--- a/src/views/basicData/product/index.vue
+++ b/src/views/basicData/product/index.vue
@@ -5,7 +5,7 @@
         <el-input v-model="search"
                   style="width: 210px"
                   placeholder="杈撳叆鍏抽敭瀛楄繘琛屾悳绱�"
-                  @change="searchFilter"
+                  @input="debouncedSearch"
                   @clear="searchFilter"
                   clearable
                   prefix-icon="Search" />
@@ -565,40 +565,31 @@
         proxy.$modal.msg("宸插彇娑�");
       });
   };
-  // 璋冪敤tree杩囨护鏂规硶 涓枃鑻辫繃婊�
-  const filterNode = (value, data, node) => {
-    if (!value) {
-      //濡傛灉鏁版嵁涓虹┖锛屽垯杩斿洖true,鏄剧ず鎵�鏈夌殑鏁版嵁椤�
-      return true;
-    }
-    // 鏌ヨ鍒楄〃鏄惁鏈夊尮閰嶆暟鎹紝灏嗗�煎皬鍐欙紝鍖归厤鑻辨枃鏁版嵁
-    let val = value.toLowerCase();
-    return chooseNode(val, data, node); // 璋冪敤杩囨护浜屽眰鏂规硶
+  const debounce = (fn, delay = 300) => {
+    let timer;
+    return (...args) => {
+      clearTimeout(timer);
+      timer = setTimeout(() => fn(...args), delay);
+    };
   };
-  // 杩囨护鐖惰妭鐐� / 瀛愯妭鐐� (濡傛灉杈撳叆鐨勫弬鏁版槸鐖惰妭鐐逛笖鑳藉尮閰嶏紝鍒欒繑鍥炶鑺傜偣浠ュ強鍏朵笅鐨勬墍鏈夊瓙鑺傜偣锛涘鏋滃弬鏁版槸瀛愯妭鐐癸紝鍒欒繑鍥炶鑺傜偣鐨勭埗鑺傜偣銆俷ame鏄腑鏂囧瓧绗︼紝enName鏄嫳鏂囧瓧绗�.
-  const chooseNode = (value, data, node) => {
-    if (data.label.indexOf(value) !== -1) {
+
+  const debouncedSearch = debounce(() => {
+    searchFilter();
+  }, 300);
+
+  const filterNode = (value, data) => {
+    if (!value) return true;
+    return chooseNode(value.toLowerCase(), data);
+  };
+
+  const chooseNode = (value, data) => {
+    const label = (data.label || '').toLowerCase();
+    if (label.indexOf(value) !== -1) {
       return true;
     }
-    const level = node.level;
-    // 濡傛灉浼犲叆鐨勮妭鐐规湰韬氨鏄竴绾ц妭鐐瑰氨涓嶇敤鏍¢獙浜�
-    if (level === 1) {
-      return false;
+    if (data.children && data.children.length > 0) {
+      return data.children.some(child => chooseNode(value, child));
     }
-    // 鍏堝彇褰撳墠鑺傜偣鐨勭埗鑺傜偣
-    let parentData = node.parent;
-    // 閬嶅巻褰撳墠鑺傜偣鐨勭埗鑺傜偣
-    let index = 0;
-    while (index < level - 1) {
-      // 濡傛灉鍖归厤鍒扮洿鎺ヨ繑鍥烇紝姝ゅname鍊兼槸涓枃瀛楃锛宔nName鏄嫳鏂囧瓧绗︺�傚垽鏂尮閰嶄腑鑻辨枃杩囨护
-      if (parentData.data.label.indexOf(value) !== -1) {
-        return true;
-      }
-      // 鍚﹀垯鐨勮瘽鍐嶅線涓婁竴灞傚仛鍖归厤
-      parentData = parentData.parent;
-      index++;
-    }
-    // 娌″尮閰嶅埌杩斿洖false
     return false;
   };
   getProductTreeList();

--
Gitblit v1.9.3