fix: 🐛 优化管理端商品分类添加/修改/删除 之后原有的 层级关闭问题

master
Yer 2024-02-02 18:29:10 +08:00
parent b3cac070df
commit 01beac9265
1 changed files with 36 additions and 23 deletions

View File

@ -184,17 +184,17 @@
</template>
<script>
import {
insertCategory,
updateCategory,
getBrandListData,
delCategory,
getCategoryBrandListData,
saveCategoryBrand,
getSpecificationList,
getCategorySpecListData,
disableCategory,
saveCategorySpec,
getBrandListData,
getCategoryBrandListData,
getCategorySpecListData,
getCategoryTree,
getSpecificationList,
insertCategory,
saveCategoryBrand,
saveCategorySpec,
updateCategory,
} from "@/api/goods";
import uploadPicInput from "@/components/lili/upload-pic-input";
@ -206,6 +206,7 @@ export default {
},
data() {
return {
recordLevel:[], //
submitLoading: false, //
categoryList: [], //
loading: false, //
@ -267,7 +268,6 @@ export default {
},
],
tableData: [], //
categoryIndex: 0, // id
checkedCategoryChildren: "", //
};
},
@ -384,7 +384,7 @@ export default {
this.submitLoading = false;
if (res.success) {
this.$Message.success("添加成功");
this.getAllList(this.categoryIndex);
this.getAllList();
this.modalVisible = false;
this.$refs.form.resetFields();
}
@ -395,7 +395,7 @@ export default {
this.submitLoading = false;
if (res.success) {
this.$Message.success("修改成功");
this.getAllList(this.categoryIndex);
this.getAllList();
this.modalVisible = false;
this.$refs.form.resetFields();
}
@ -416,7 +416,7 @@ export default {
this.$Modal.remove();
if (res.success) {
this.$Message.success("操作成功");
this.getAllList(0);
this.getAllList();
}
});
},
@ -425,6 +425,7 @@ export default {
//
handleLoadData(item, callback) {
this.recordLevel[item.level] = item.id;
if (item.level == 0) {
let categoryList = JSON.parse(JSON.stringify(this.categoryList));
categoryList.forEach((val) => {
@ -436,14 +437,14 @@ export default {
//
setTimeout(() => {
callback(val.children);
}, 1000);
}, 100);
}
});
} else {
this.deepCategoryChildren(item.id, this.categoryList);
setTimeout(() => {
callback(this.checkedCategoryChildren);
}, 1000);
}, 100);
}
},
@ -462,18 +463,30 @@ export default {
}
},
//
getAllList(parent_id) {
getAllList() {
this.loading = true;
getCategoryTree(parent_id).then((res) => {
getCategoryTree().then((res) => {
this.loading = false;
if (res.success) {
localStorage.setItem("category", JSON.stringify(res.result));
this.categoryList = JSON.parse(JSON.stringify(res.result));
this.tableData = res.result.map((item) => {
if (item.children.length != 0) {
if(this.recordLevel[0] && item.id === this.recordLevel[0]) {
item._showChildren = true
//
if(this.recordLevel[1] && item.children){
item.children.map((child)=>{
if(this.recordLevel[1] && child.id === this.recordLevel[1]){
child._showChildren = true
}
})
}
}else{
if (item.children.length !== 0) {
item.children = [];
item._loading = false;
}
}
return item;
});
}