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