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

---
 src/views/data/ind/item/AtomIndDefineForm.vue |   85 +++++++++++++++++++++++++-----------------
 1 files changed, 50 insertions(+), 35 deletions(-)

diff --git a/src/views/data/ind/item/AtomIndDefineForm.vue b/src/views/data/ind/item/AtomIndDefineForm.vue
index f9eaa74..225d5c1 100644
--- a/src/views/data/ind/item/AtomIndDefineForm.vue
+++ b/src/views/data/ind/item/AtomIndDefineForm.vue
@@ -20,19 +20,19 @@
       <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">
           <el-form-item label="时间粒度" prop="timeGranularity">
-            <el-select v-model="formData.timeGranularity" placeholder="请选择">
+            <el-select v-model="formData.timeGranularity" clearable placeholder="请选择">
               <el-option
                 v-for="dict in getStrDictOptions(DICT_TYPE.TIME_GRANULARITY)"
                 :key="dict.value"
@@ -44,33 +44,27 @@
         </el-col>
       </el-row>
       <el-row>
-        <el-col :span="8">
+        <el-col :span="6">
           <el-form-item label="指标精度" prop="precision">
             <el-input v-model="formData.precision"/>
           </el-form-item>
         </el-col>
-        <el-col :span="8">
+        <el-col :span="6">
           <el-form-item label="转换系数" prop="coefficient">
             <el-input v-model="formData.coefficient"/>
           </el-form-item>
         </el-col>
-        <el-col :span="8">
+        <el-col :span="6">
           <el-form-item label="数量单位" prop="unit">
             <el-input v-model="formData.unit"/>
           </el-form-item>
         </el-col>
       </el-row>
       <el-row>
-        <el-col :span="24">
-          <el-form-item label="备注" prop="remark">
-            <el-input v-model="formData.remark" type="textarea" maxlength="100"/>
-          </el-form-item>
-        </el-col>
-      </el-row>
-      <el-row>
         <el-col :span="12">
           <el-form-item label="数据集" prop="atomItem.dataSet">
-            <el-select v-model="formData.atomItem.dataSet" clearable placeholder="请选择数据集" @change="handleDataSetChange($event)">
+            <el-select v-model="formData.atomItem.dataSet" filterable
+                       allow-create clearable placeholder="请选择数据集" @change="handleDataSetChange($event)">
               <el-option
                 v-for="item in dataSetList"
                 :key="item.id"
@@ -80,28 +74,37 @@
             </el-select>
           </el-form-item>
         </el-col>
-        <el-col :span="12">
+        <el-col :span="6">
           <el-form-item label="使用字段" prop="atomItem.usingField">
-            <el-select v-model="formData.atomItem.usingField" clearable placeholder="请选择字段">
+            <el-select v-model="formData.atomItem.usingField" filterable
+                       allow-create clearable placeholder="请选择字段">
               <el-option
                 v-for="item in dataSetFieldList"
                 :key="item.id"
                 :label="item.fieldCode"
-                :value="item.id + ''"
+                :value="item.fieldCode"
               />
             </el-select>
           </el-form-item>
         </el-col>
-        <el-col :span="12">
+        <el-col :span="6">
           <el-form-item label="统计方式" prop="statFunc">
-            <el-select v-model="formData.atomItem.statFunc" placeholder="请选择">
+            <el-select v-model="formData.atomItem.statFunc" filterable
+                       allow-create clearable placeholder="请选择">
               <el-option
-                v-for="dict in getStrDictOptions(DICT_TYPE.STAT_FUNC)"
+                v-for="dict in getStrDictOptions(DICT_TYPE.DATA_STAT_FUNC)"
                 :key="dict.value"
                 :label="dict.label"
                 :value="dict.value"
               />
             </el-select>
+          </el-form-item>
+        </el-col>
+      </el-row>
+      <el-row>
+        <el-col :span="24">
+          <el-form-item label="备注" prop="remark">
+            <el-input v-model="formData.remark" type="textarea" maxlength="100"/>
           </el-form-item>
         </el-col>
       </el-row>
@@ -118,7 +121,7 @@
   import * as DataSetApi from '@/api/data/ind/data/data.set'
   import * as DataSetFieldApi from '@/api/data/ind/data/data.field'
   import * as CategoryApi from '@/api/data/ind/category/index'
-
+  import {handleTree} from "@/utils/tree";
 
   defineOptions({name: 'IndDataSetForm'})
 
@@ -135,8 +138,8 @@
     itemName: '',
     itemType: '',
     itemCategory: '',
-    coefficient: '',
-    precision: '',
+    coefficient: 1,
+    precision: 0,
     businessType: '',
     timeRange: '',
     timeGranularity: '',
@@ -157,15 +160,26 @@
   const formRules = reactive({
     itemName: [{required: true, message: '指标名称不能为空', trigger: 'blur'}],
     itemCategory: [{required: true, message: '指标分类不能为空', trigger: 'blur'}],
-    precision: [{validator: validateAsNumber, trigger: 'blur' }],
+    /*precision: [{validator: validateAsNumber, trigger: 'blur' }],
     coefficient: [{validator: validateAsNumber, trigger: 'blur' }],
+    statFunc: [{required: true, message: '统计方式不能为空', trigger: 'blur'}],
+    timeGranularity: [{required: true, message: '时间粒度不能为空', trigger: 'blur'}],
     "atomItem.dataSet": [{required: true, message: '数据集不能为空', trigger: 'blur'}],
-    "atomItem.usingField":[{required: true, message: '使用字段不能为空', trigger: 'blur'}]
+    "atomItem.usingField":[{required: true, message: '使用字段不能为空', trigger: 'blur'}]*/
   })
   const formRef = ref() // 表单 Ref
   const dataSetList = ref([] as DataSetApi.DataSetVO[])
   const dataSetFieldList = ref([] as DataSetFieldApi.DataSetFieldVO[])
-  const dataCategoryList = ref([])
+
+  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
@@ -174,7 +188,7 @@
     resetForm()
     // 加载数据源列表
     dataSetList.value = await DataSetApi.getDataSetList()
-    dataCategoryList.value = await CategoryApi.getCategoryListAllSimple()
+    await getCategoryTree()
     // 修改时,设置数据
     if (id) {
       formLoading.value = true
@@ -197,6 +211,7 @@
   /** 提交表单 */
   const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
   const submitForm = async () => {
+    debugger
     // 校验表单
     if (!formRef) return
     const valid = await formRef.value.validate()
@@ -234,8 +249,8 @@
       itemName: '',
       itemType: '',
       itemCategory: '',
-      coefficient: '',
-      precision: '',
+      coefficient: 1,
+      precision: 0,
       businessType: '',
       timeRange: '',
       timeGranularity: '',

--
Gitblit v1.9.3