From 6a72da7900390c3048d7eb07a8e93ed776f5676b Mon Sep 17 00:00:00 2001
From: Jay <csj123456>
Date: 星期四, 16 一月 2025 13:28:22 +0800
Subject: [PATCH] 修改指标分类为选择tree,增加选择框可编辑

---
 src/views/data/ind/item/DerIndDefineForm.vue |   63 ++++++++++++++++++-------------
 1 files changed, 37 insertions(+), 26 deletions(-)

diff --git a/src/views/data/ind/item/DerIndDefineForm.vue b/src/views/data/ind/item/DerIndDefineForm.vue
index f5b4235..8579fc6 100644
--- a/src/views/data/ind/item/DerIndDefineForm.vue
+++ b/src/views/data/ind/item/DerIndDefineForm.vue
@@ -7,8 +7,21 @@
       :rules="formRules" label-width="100px">
       <el-row>
         <el-col :span="12">
+          <el-form-item label="指标编码" prop="itemNo">
+            <el-input v-model="formData.itemNo" disabled/>
+          </el-form-item>
+        </el-col>
+        <el-col :span="12">
+          <el-form-item label="指标名称" prop="itemName">
+            <el-input v-model="formData.itemName"/>
+          </el-form-item>
+        </el-col>
+      </el-row>
+      <el-row>
+        <el-col :span="12">
           <el-form-item label="原子指标" prop="atomItem.itemId">
-            <el-select v-model="formData.atomItem.itemId" clearable placeholder="请选择原子指标"
+            <el-select v-model="formData.atomItem.itemId" filterable
+                       allow-create clearable placeholder="请选择原子指标"
                        @change="handleChange($event)">
               <el-option
                 v-for="item in atomItemList"
@@ -27,27 +40,15 @@
       </el-row>
       <el-row>
         <el-col :span="12">
-          <el-form-item label="指标编码" prop="itemNo">
-            <el-input v-model="formData.itemNo" disabled/>
-          </el-form-item>
-        </el-col>
-        <el-col :span="12">
-          <el-form-item label="指标名称" prop="itemName">
-            <el-input v-model="formData.itemName"/>
-          </el-form-item>
-        </el-col>
-      </el-row>
-      <el-row>
-        <el-col :span="12">
           <el-form-item label="指标分类" prop="itemCategory">
-            <el-select v-model="formData.itemCategory" clearable placeholder="请选择指标分类">
-              <el-option
-                v-for="item in dataCategoryList"
-                :key="item.id"
-                :label="item.label"
-                :value="item.id + ''"
-              />
-            </el-select>
+            <el-tree-select
+              v-model="formData.itemCategory"
+              :data="dataCategoryList"
+              :default-expanded-keys="[0]"
+              :props="defaultProps"
+              check-strictly
+              node-key="id"
+            />
           </el-form-item>
         </el-col>
         <el-col :span="12">
@@ -88,7 +89,7 @@
                 v-for="item in dataSetFieldList"
                 :key="item.id"
                 :label="item.fieldCode"
-                :value="item.id + ''"
+                :value="item.fieldCode"
               />
             </el-select>
           </el-form-item>
@@ -130,12 +131,13 @@
       <el-row>
         <el-col :span="24">
           <el-form-item label="分析维度" prop="dimension">
-            <el-select v-model="formData.derItem.dimension" clearable placeholder="请选择分析维度" multiple>
+            <el-select v-model="formData.derItem.dimension" filterable
+                       allow-create clearable placeholder="请选择分析维度" multiple>
               <el-option
                 v-for="item in dataSetFieldList"
                 :key="item.id"
                 :label="item.fieldCode"
-                :value="item.id + ''"
+                :value="item.fieldCode"
               />
             </el-select>
           </el-form-item>
@@ -164,6 +166,7 @@
   import {PageParam} from "@/api/data/ind/item/item";
   import * as CategoryApi from "@/api/data/ind/category";
   import * as DataSetFieldApi from "@/api/data/ind/data/data.field";
+  import {handleTree} from "@/utils/tree";
 
   defineOptions({name: 'IndDataSetForm'})
 
@@ -218,9 +221,16 @@
   const formRef = ref() // 表单 Ref
   const atomItemList = ref([] as ItemApi.ItemVO[])
   const showTimeChange = ref(false)
-  const dataCategoryList = ref([] as CategoryApi.IndItemCategoryVO[])
   const dataSetFieldList = ref([] as DataSetFieldApi.DataSetFieldVO[])
+  const dataCategoryList = ref<Tree[]>([])
 
+  const getCategoryTree = async () => {
+    dataCategoryList.value = []
+    const res = await CategoryApi.getCategoryListAllSimple()
+    let category: Tree = {id: 0, label: '主类目', children: []}
+    category.children = handleTree(res, 'id', 'pid')
+    dataCategoryList.value.push(category)
+  }
   /** 打开弹窗 */
   const open = async (type: string, id?: string) => {
     dialogVisible.value = true
@@ -228,7 +238,7 @@
     formType.value = type
     resetForm()
     // 加载数据源列表
-    dataCategoryList.value = await CategoryApi.getCategoryListAllSimple()
+    await getCategoryTree()
     const queryParams = reactive({
       itemType: 'ATOM'
     })
@@ -243,6 +253,7 @@
         }else {
           formData.value.derItem.dimension = ""
         }
+        showTimeChange.value = formData.value.derItem.timeLimit === 'CUSTOM'
         await handleChange(formData.value.derItem.atomItemId)
       } finally {
         formLoading.value = false

--
Gitblit v1.9.3