fix: 🐛 优化管理端商品分类添加/修改/删除 之后原有的 层级关闭问题
parent
b3cac070df
commit
01beac9265
|
@ -184,17 +184,17 @@
|
|||
</template>
|
||||
<script>
|
||||
import {
|
||||
insertCategory,
|
||||
updateCategory,
|
||||
getBrandListData,
|
||||
delCategory,
|
||||
getCategoryBrandListData,
|
||||
saveCategoryBrand,
|
||||
getSpecificationList,
|
||||
getCategorySpecListData,
|
||||
disableCategory,
|
||||
saveCategorySpec,
|
||||
getCategoryTree,
|
||||
delCategory,
|
||||
disableCategory,
|
||||
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) {
|
||||
item.children = [];
|
||||
item._loading = false;
|
||||
}
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue