From dd57e0e9a989e7ee8b3e3473a7ee6a1dff06a4ae Mon Sep 17 00:00:00 2001
From: 张含笑 <zhx18749296735@163.com>
Date: Tue, 27 Jan 2026 17:19:04 +0800
Subject: [PATCH] feat:调整加载

---
 applications/task-work-order/src/views/orderView/organizational/agenciesManagement/FormDiaLog.vue |  115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 110 insertions(+), 5 deletions(-)

diff --git a/applications/task-work-order/src/views/orderView/organizational/agenciesManagement/FormDiaLog.vue b/applications/task-work-order/src/views/orderView/organizational/agenciesManagement/FormDiaLog.vue
index d29556b..44f488c 100644
--- a/applications/task-work-order/src/views/orderView/organizational/agenciesManagement/FormDiaLog.vue
+++ b/applications/task-work-order/src/views/orderView/organizational/agenciesManagement/FormDiaLog.vue
@@ -43,15 +43,25 @@
         </el-col>
         <el-col :span="12">
           <el-form-item label="所属区划" prop="areaCode">
-            <el-select
+            <el-tree-select
               class="gd-select"
-              popper-class="gd-select-popper"
+              popper-class="gd-tree-select-popper"
               v-model="formData.areaCode"
+              node-key="id"
+              :default-expanded-keys="expandedKeys"
+              :props="{
+                value: 'id',
+                label: 'name',
+                children: 'children'
+              }"
               placeholder="请选择"
               clearable
-            >
-              <el-option v-for="item in regionOptions" :key="item.value" :label="item.title" :value="item.value" />
-            </el-select>
+              filterable
+              :check-strictly="true"
+              lazy
+              :load="loadRegionNode"
+              :render-after-expand="false"
+            />
           </el-form-item>
         </el-col>
         <el-col :span="12">
@@ -104,6 +114,7 @@
 import {
   agenciesSubmitApi,
   agenciesDetailApi,
+  regionLazyTreeApi
 } from './agenciesApi'
 
 // 初始化表单数据
@@ -126,6 +137,8 @@
 const submitting = ref(false) // 提交中
 const dialogReadonly = computed(() => dialogMode.value === 'view')
 const titleEnum = ref({ edit: '编辑', view: '查看', add: '新增' })
+const expandedKeys = ref([]) // 树形选择器展开的节点
+const regionNodeCache = ref(new Map()) // 缓存区域节点及其父节点关系
 
 const rules = {
   deptName: fieldRules(true),
@@ -163,6 +176,62 @@
     data.areaCode = String(data.areaCode)
   }
   formData.value = data
+  
+  // 如果是编辑模式,获取区域节点的路径以展开树形选择器
+  if (dialogMode.value === 'edit' && data.areaCode) {
+    await loadRegionPath(data.areaCode)
+  }
+}
+
+// 加载区域节点路径
+async function loadRegionPath(areaCode) {
+  try {
+    const path = []
+    const queue = [{ code: '360800000000', currentPath: ['360800000000'] }]
+    let found = false
+    
+    // 广度优先搜索,逐层加载节点直到找到目标节点
+    while (queue.length > 0 && !found) {
+      const { code, currentPath } = queue.shift()
+      
+      // 获取当前节点的子节点
+      const res = await regionLazyTreeApi({ parentCode: code })
+      const nodes = res?.data?.data || []
+      
+      for (const node of nodes) {
+        const nodeId = node.id || node.value
+        
+        // 缓存节点及其父节点关系
+        regionNodeCache.value.set(nodeId, {
+          id: nodeId,
+          name: node.name || node.title || node.label,
+          parentId: code,
+          hasChildren: node.hasChildren || false
+        })
+        
+        // 检查是否找到目标节点
+        if (nodeId === areaCode) {
+          path.push(...currentPath, nodeId)
+          found = true
+          break
+        }
+        
+        // 如果有子节点,加入队列继续搜索
+        if (node.hasChildren) {
+          queue.push({
+            code: nodeId,
+            currentPath: [...currentPath, nodeId]
+          })
+        }
+      }
+    }
+    
+    if (path.length > 0) {
+      expandedKeys.value = path
+    }
+  } catch (error) {
+    console.error('加载区域路径失败:', error)
+  }
 }
 
 // 打开弹框
@@ -173,8 +242,44 @@
     await loadDetail()
   }
 }
+// 懒加载获取区域节点数据
+async function loadRegionNode(node, resolve) {
+  try {
+    // 初始化加载时传递 code 参数,加载子节点时传递 parentCode 参数
+    const params = node.data?.id ? { parentCode: node.data.id } : { code: '360800000000' }
+    const parentCode = node.data?.id || '360800000000'
+    const res = await regionLazyTreeApi(params)
+    const nodes = res?.data?.data || []
+    
+    // 处理返回的节点数据
+    const processedNodes = nodes.map(item => {
+      const nodeId = item.id || item.value
+      // 缓存节点及其父节点关系
+      regionNodeCache.value.set(nodeId, {
+        id: nodeId,
+        name: item.name || item.title || item.label,
+        parentId: parentCode,
+        hasChildren: item.hasChildren || false
+      })
+      
+      return {
+        id: nodeId,
+        name: item.name || item.title || item.label,
+        hasChildren: item.hasChildren || false
+      }
+    })
+    
+    resolve(processedNodes)
+  } catch (error) {
+    console.error('获取区域数据失败:', error)
+    resolve([])
+  }
+}
 
 defineExpose({ open })
+
+onMounted(() => {
+})
 </script>
 
 <style scoped lang="scss">

--
Gitblit v1.9.3