Parcourir la source

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

在分类评估功能中,新增对一级分类信息的支持。修改了表单字段和数据处理逻辑,现在可以同时获取和显示二级分类对应的一级分类编码和名称。重构了原有的 getCategoryNameByCode 方法为 getCategoryInfoByCode,使其返回包含一级分类信息的完整对象。
huoyi il y a 1 mois
Parent
commit
4c62d3f0f1
1 fichiers modifiés avec 22 ajouts et 9 suppressions
  1. 22 9
      src/views/system/classificationAssess/index.vue

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

@@ -259,11 +259,13 @@ function reset() {
259 259
     id: null,
260 260
     name: null,
261 261
     categoryCode: null,
262
+    categoryCodeOne: null,
262 263
     checkStandard: null,
263 264
     checkMethod: null,
264 265
     importance: null,
265 266
     status: null,
266 267
     categoryName: null,
268
+    categoryNameOne: null,
267 269
     remark: null,
268 270
     code: null,
269 271
     importanceDesc: null
@@ -315,9 +317,12 @@ function handleUpdate(row) {
315 317
 function submitForm() {
316 318
   proxy.$refs["projectRef"].validate(valid => {
317 319
     if (valid) {
318
-      // 根据categoryCode获取categoryName
320
+      // 根据categoryCode获取categoryName和一级分类信息
319 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 386
 function handleNodeClick(data) {
382 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 399
     for (const category of categories) {
391 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 407
       if (category.children && category.children.length > 0) {
395
-        const result = findCategory(category.children)
408
+        const result = findCategory(category.children, category)
396 409
         if (result) return result
397 410
       }
398 411
     }
399
-    return ''
412
+    return { categoryName: '', categoryCodeOne: '', categoryNameOne: '' }
400 413
   }
401 414
   
402 415
   return findCategory(enableCategoryOptions.value)