进一步优化购物车页面

This commit is contained in:
TOP糯米 2023-04-09 01:51:54 +08:00
parent a87f0480c4
commit 85284d0b1c
1 changed files with 44 additions and 26 deletions

View File

@ -87,11 +87,24 @@ export default {
isLogin: "user/isLogin",
}),
},
async onLoad() {
onLoad() {
if (!this.isLogin) {
this.$store.commit("user/showLoginModal", true);
return;
}
this.initPage();
},
onShow() {},
onReady() {},
onReachBottom() {},
onPullDownRefresh() {},
onShareTimeline() {},
onShareAppMessage() {},
methods: {
/**
* 初始化页面
*/
async initPage(e) {
await this.$store.dispatch("cart/update");
this.list = [];
this.cart.list.forEach((item) => {
@ -116,13 +129,9 @@ export default {
});
});
},
onShow() {},
onReady() {},
onReachBottom() {},
onPullDownRefresh() {},
onShareTimeline() {},
onShareAppMessage() {},
methods: {
/**
* 选中组
*/
checkGroup(parentIndex) {
let currentItem = this.list[parentIndex];
let currentState = !currentItem.checked;
@ -130,7 +139,9 @@ export default {
this.checkItem(parentIndex, itemIndex, currentState);
});
},
//
/**
* 选中单项
*/
checkItem(parentIndex, itemIndex, state) {
let currentItem = this.list[parentIndex].list[itemIndex];
let currentState = typeof state === "undefined" ? !currentItem.checked : state;
@ -198,7 +209,6 @@ export default {
for (let i = 0; i < itemIndexes.length; i++) {
let currentItem = parentItem.list[itemIndexes[i]];
await that.$models.cart.delete(currentItem.id).then(() => {
that.$store.dispatch("cart/update", true);
parentItem.list.splice(itemIndexes[i], 1);
if (parentItem.list.length > 0) {
that.updateTotal(parentIndex);
@ -207,6 +217,14 @@ export default {
}
});
}
let hasChecked = false;
parentItem.list.forEach((item) => {
if (item.checked) {
hasChecked = true;
}
});
parentItem.canUse = hasChecked;
that.$store.dispatch("cart/update", true);
},
});
},