From e91c43e4b4c61173d9a2790b255c7122a8bb3098 Mon Sep 17 00:00:00 2001
From: 张含笑 <zhx18749296735@163.com>
Date: Tue, 29 Jul 2025 13:58:57 +0800
Subject: [PATCH] feat:工单类型联动,Bug修复

---
 src/views/tickets/ticket.vue |   68 ++++++++++++++++++++++++++-------
 1 files changed, 53 insertions(+), 15 deletions(-)

diff --git a/src/views/tickets/ticket.vue b/src/views/tickets/ticket.vue
index ce4b381..5c7220b 100644
--- a/src/views/tickets/ticket.vue
+++ b/src/views/tickets/ticket.vue
@@ -210,7 +210,8 @@
             </el-col>
             <el-col :span="12">
               <el-form-item label="工单类型" prop="type">
-                <el-select v-model="form.type" placeholder="请选择工单类型" class="full-width">
+
+                <el-select  @change="handleTypeChange" v-model="form.type" placeholder="请选择工单类型" class="full-width" >
                   <el-option
                     v-for="item in types"
                     :key="item.value"
@@ -267,6 +268,7 @@
                   multiple
                   placeholder="请选择关联算法"
                   class="full-width"
+                  :disabled="!form.type"
                 >
                   <el-option
                     v-for="item in algorithms"
@@ -365,7 +367,9 @@
           <el-button type="infoprimary" plain :loading="draftLoading" @click="saveDraft"
             >存草稿</el-button
           >
-          <el-button @click="dialogVisible = false">取 消</el-button>
+
+
+          <el-button  @click="handleCancel">取 消</el-button>
         </div>
       </template>
     </el-dialog>
@@ -911,6 +915,7 @@
       },
       departments: [],
       types: [],
+      allAlgorithms: [],
       handlers: [
         { label: '处理人A', value: 'handlerA' },
         { label: '处理人B', value: 'handlerB' },
@@ -1393,7 +1398,7 @@
         const subAreaCode = areaCode ? areaCode.substring(0, 6) : '';
         const adcodeObj = getAdcodeObj(geoJson, 'adcode', subAreaCode);
 
-        console.log('区域代码:', subAreaCode);
+       // console.log('区域代码:', subAreaCode);
 
         // 直接从返回对象中获取正确的路径
         const center = adcodeObj?.payload?.objects?.collection?.geometries?.[0]?.properties?.center;
@@ -1479,7 +1484,8 @@
     async fetchDropdownData() {
       try {
         const response = await getTicketInfo();
-        const { dept_data, event_type, ai_type } = response.data.data;
+
+        const { dept_data, event_type, ai_type,info } = response.data.data;
 
         this.departments = dept_data.map(item => ({
           label: item.dept_name,
@@ -1498,16 +1504,19 @@
 
         const columnType = this.findObject(this.option.column, 'type');
         columnType.dicData = this.types;
+        this.allAlgorithms  = info
 
+        // console.log('工单类型',this.types);
+        // console.log('关联算法',this.allAlgorithms );
         // 确保算法数据的映射一致
-        this.algorithms =
-          ai_type?.map(item => ({
-            dict_key: item.dict_key,
-            dict_value: item.dict_value,
-            // 同时添加 label 和 value 以兼容两处使用
-            label: item.dict_value,
-            value: item.dict_key,
-          })) || [];
+        // this.algorithms =
+        //   ai_type?.map(item => ({
+        //     dict_key: item.dict_key,
+        //     dict_value: item.dict_value,
+        //     // 同时添加 label 和 value 以兼容两处使用
+        //     label: item.dict_value,
+        //     value: item.dict_key,
+        //   })) || [];
 
         // 构建用户ID和名称的映射关系
         this.userNameToIdMap = {};
@@ -1519,6 +1528,33 @@
       } catch (error) {
         this.$message.error('加载下拉框数据失败');
       }
+    },
+    // 工单类型变化时触发
+    handleTypeChange(typeValue) {
+      if (!typeValue) {
+        // 未选择类型时清空算法列表
+        this.algorithms = [];
+        return;
+      }
+
+      const matchedCategory = this.allAlgorithms.find(
+        category => category.dict_key === typeValue 
+      );
+
+      if (!matchedCategory || !matchedCategory.algorithms || matchedCategory.algorithms.length === 0) {
+        // 无匹配的算法时清空
+        this.algorithms = [];
+        this.$message.info('该工单类型暂无关联算法');
+        return;
+      }
+
+      this.algorithms = matchedCategory.algorithms.map(algo => ({
+        label: algo.dict_value, 
+        value: algo.dict_key,
+        dict_key: algo.dict_key,
+        dict_value: algo.dict_value
+      }));
+
     },
 
     async fetchTableData() {
@@ -1773,7 +1809,10 @@
         this.draftLoading = false;
       }
     },
-
+    handleCancel (){
+      this.resetForm();
+       this.dialogVisible = false;
+},
     handleLocationChange(val) {
       let locationValue = val.value;
       if (locationValue && locationValue.length >= 2) {
@@ -2434,8 +2473,7 @@
 
       // 获取工单类型值 - 从types中找到匹配的值
       const typeValue =
-        this.types.find(t => t.label === row.type)?.value || row.work_order_type_dict_key;
-
+        this.types.find(t => t.value === row.type)?.value || row.work_order_type_dict_key;
       // 获取处理人ID - 使用userNameToIdMap映射
       const handlerId = this.userNameToIdMap[row.handler] || row.handler;
 

--
Gitblit v1.9.3