|
@@ -251,8 +251,50 @@ export default {
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
|
|
+ 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(row) {
|
|
|
|
|
+ const params = { ...row };
|
|
|
|
|
+ let parentNames = [];
|
|
|
|
|
+ if (params.parentId) {
|
|
|
|
|
+ let newList = [];
|
|
|
|
|
+ const getAllList = data => {
|
|
|
|
|
+ data.forEach(element => {
|
|
|
|
|
+ newList.push(element);
|
|
|
|
|
+ if (element.children && element.children.length) {
|
|
|
|
|
+ getAllList(element.children)
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ getAllList(this.data);
|
|
|
|
|
+ parentNames = this.findParentNames(newList, params.parentId);
|
|
|
|
|
+ let currParent = newList.find(item => item.id == params.parentId);
|
|
|
|
|
+ if (!!currParent) {
|
|
|
|
|
+ parentNames.push(currParent.name);
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log(parentNames)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return { ...params, accSubject: parentNames.length ? `${parentNames.join('\\')}\\${params.name}` : params.name }
|
|
|
|
|
+ },
|
|
|
rowSave(row, done) {
|
|
rowSave(row, done) {
|
|
|
- add(row).then(({ data }) => {
|
|
|
|
|
|
|
+ const params = this.getFormData(row);
|
|
|
|
|
+ add(params).then(({ data }) => {
|
|
|
done();
|
|
done();
|
|
|
if (data.code == 200) {
|
|
if (data.code == 200) {
|
|
|
this.$message.success("新增成功!");
|
|
this.$message.success("新增成功!");
|
|
@@ -263,7 +305,8 @@ export default {
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
rowUpdate(row, index, done) {
|
|
rowUpdate(row, index, done) {
|
|
|
- update(row).then(({ data }) => {
|
|
|
|
|
|
|
+ const params = this.getFormData(row);
|
|
|
|
|
+ update(params).then(({ data }) => {
|
|
|
done();
|
|
done();
|
|
|
if (data.code == 200) {
|
|
if (data.code == 200) {
|
|
|
this.$message.success("修改成功!");
|
|
this.$message.success("修改成功!");
|