Browse Source

企业科目设置科目名称拼接父类名称

ljb 10 months ago
parent
commit
3129e57cb5
1 changed files with 34 additions and 0 deletions
  1. 34 0
      src/views/basic-resource/basic-database/comp-subject-setting.vue

+ 34 - 0
src/views/basic-resource/basic-database/comp-subject-setting.vue

@@ -69,6 +69,8 @@ export default window.$crudCommon({
   },
   },
   data() {
   data() {
     return {
     return {
+      treeData: [],
+
       wideTableColumns: [],
       wideTableColumns: [],
       printTitle: "",
       printTitle: "",
     };
     };
@@ -97,6 +99,8 @@ export default window.$crudCommon({
 
 
           const column = this.findObject(this.option.column, "subjectId");
           const column = this.findObject(this.option.column, "subjectId");
           column.dicData = this.loopData(JSON.parse(JSON.stringify(res.data.data)), 0);
           column.dicData = this.loopData(JSON.parse(JSON.stringify(res.data.data)), 0);
+
+          this.treeData = column.dicData;
         }
         }
       })
       })
     },
     },
@@ -123,6 +127,36 @@ export default window.$crudCommon({
         this.$refs.printWideTable.printTable(isLandscape);
         this.$refs.printWideTable.printTable(isLandscape);
       })
       })
     },
     },
+    findParentNames(categories, childId, parentNames = []) {
+      const child = categories.find(cat => cat.id === childId);
+      
+      if (!child || !child.parentId) {
+        return parentNames;
+      }
+      
+      const parent = categories.find(cat => cat.id === child.parentId);
+      if (parent) {
+        parentNames.unshift(parent.name); // 添加到数组开头保持顺序
+        return this.findParentNames(categories, parent.id, parentNames);
+      }
+      
+      return parentNames;
+    },
+    getFormData() {
+      let newList = [];
+      const getAllList = data => {
+        data.forEach(element => {
+          newList.push(element);
+          if (element.children && element.children.length) {
+            getAllList(element.children)
+          }
+        });
+      }
+      getAllList(this.treeData);
+      let parentNames = this.findParentNames(newList, this.form.subjectId);
+      
+      return { ...this.form, subjectName: `${parentNames.join('\\')}\\${this.form.$subjectId}` };
+    },
   },
   },
 }, {
 }, {
   // 模块路径
   // 模块路径