fix: 🐛 优化管理端商品分类添加/修改/删除 之后原有的 层级关闭问题
parent
b3cac070df
commit
01beac9265
|
@ -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;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue