Просмотр исходного кода

feat(分类评估): 添加一级分类信息支持

在分类评估功能中,新增对一级分类信息的支持。修改了表单字段和数据处理逻辑,现在可以同时获取和显示二级分类对应的一级分类编码和名称。重构了原有的 getCategoryNameByCode 方法为 getCategoryInfoByCode,使其返回包含一级分类信息的完整对象。
huoyi 1 месяц назад
Родитель
Сommit
4c62d3f0f1
1 измененных файлов с 22 добавлено и 9 удалено
  1. 22 9
      src/views/system/classificationAssess/index.vue

+ 22 - 9
src/views/system/classificationAssess/index.vue

@@ -259,11 +259,13 @@ function reset() {
259
     id: null,
259
     id: null,
260
     name: null,
260
     name: null,
261
     categoryCode: null,
261
     categoryCode: null,
262
+    categoryCodeOne: null,
262
     checkStandard: null,
263
     checkStandard: null,
263
     checkMethod: null,
264
     checkMethod: null,
264
     importance: null,
265
     importance: null,
265
     status: null,
266
     status: null,
266
     categoryName: null,
267
     categoryName: null,
268
+    categoryNameOne: null,
267
     remark: null,
269
     remark: null,
268
     code: null,
270
     code: null,
269
     importanceDesc: null
271
     importanceDesc: null
@@ -315,9 +317,12 @@ function handleUpdate(row) {
315
 function submitForm() {
317
 function submitForm() {
316
   proxy.$refs["projectRef"].validate(valid => {
318
   proxy.$refs["projectRef"].validate(valid => {
317
     if (valid) {
319
     if (valid) {
318
-      // 根据categoryCode获取categoryName
320
+      // 根据categoryCode获取categoryName和一级分类信息
319
       if (form.value.categoryCode) {
321
       if (form.value.categoryCode) {
320
-        form.value.categoryName = getCategoryNameByCode(form.value.categoryCode)
322
+        const categoryInfo = getCategoryInfoByCode(form.value.categoryCode)
323
+        form.value.categoryName = categoryInfo.categoryName
324
+        form.value.categoryCodeOne = categoryInfo.categoryCodeOne
325
+        form.value.categoryNameOne = categoryInfo.categoryNameOne
321
       }
326
       }
322
       
327
       
323
       // 名称转换
328
       // 名称转换
@@ -380,23 +385,31 @@ function getCategoryTree() {
380
 
385
 
381
 function handleNodeClick(data) {
386
 function handleNodeClick(data) {
382
   form.value.categoryName = data.name;
387
   form.value.categoryName = data.name;
388
+  // 根据选中的二级分类获取一级分类信息
389
+  const categoryInfo = getCategoryInfoByCode(data.code)
390
+  form.value.categoryCodeOne = categoryInfo.categoryCodeOne
391
+  form.value.categoryNameOne = categoryInfo.categoryNameOne
383
 }
392
 }
384
 
393
 
385
-/** 根据categoryCode获取categoryName */
386
-function getCategoryNameByCode(categoryCode) {
387
-  if (!categoryCode || !enableCategoryOptions.value) return ''
394
+/** 根据categoryCode获取categoryName和categoryCodeOne, categoryNameOne */
395
+function getCategoryInfoByCode(categoryCode) {
396
+  if (!categoryCode || !enableCategoryOptions.value) return { categoryName: '', categoryCodeOne: '', categoryNameOne: '' }
388
   
397
   
389
-  const findCategory = (categories) => {
398
+  const findCategory = (categories, parent = null) => {
390
     for (const category of categories) {
399
     for (const category of categories) {
391
       if (category.code === categoryCode) {
400
       if (category.code === categoryCode) {
392
-        return category.name
401
+        return {
402
+          categoryName: category.name,
403
+          categoryCodeOne: parent ? parent.code : '',
404
+          categoryNameOne: parent ? parent.name : ''
405
+        }
393
       }
406
       }
394
       if (category.children && category.children.length > 0) {
407
       if (category.children && category.children.length > 0) {
395
-        const result = findCategory(category.children)
408
+        const result = findCategory(category.children, category)
396
         if (result) return result
409
         if (result) return result
397
       }
410
       }
398
     }
411
     }
399
-    return ''
412
+    return { categoryName: '', categoryCodeOne: '', categoryNameOne: '' }
400
   }
413
   }
401
   
414
   
402
   return findCategory(enableCategoryOptions.value)
415
   return findCategory(enableCategoryOptions.value)