进一步优化购物车页面
This commit is contained in:
parent
a87f0480c4
commit
85284d0b1c
|
@ -87,11 +87,24 @@ export default {
|
||||||
isLogin: "user/isLogin",
|
isLogin: "user/isLogin",
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
async onLoad() {
|
onLoad() {
|
||||||
if (!this.isLogin) {
|
if (!this.isLogin) {
|
||||||
this.$store.commit("user/showLoginModal", true);
|
this.$store.commit("user/showLoginModal", true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.initPage();
|
||||||
|
},
|
||||||
|
onShow() {},
|
||||||
|
onReady() {},
|
||||||
|
onReachBottom() {},
|
||||||
|
onPullDownRefresh() {},
|
||||||
|
onShareTimeline() {},
|
||||||
|
onShareAppMessage() {},
|
||||||
|
methods: {
|
||||||
|
/**
|
||||||
|
* 初始化页面
|
||||||
|
*/
|
||||||
|
async initPage(e) {
|
||||||
await this.$store.dispatch("cart/update");
|
await this.$store.dispatch("cart/update");
|
||||||
this.list = [];
|
this.list = [];
|
||||||
this.cart.list.forEach((item) => {
|
this.cart.list.forEach((item) => {
|
||||||
|
@ -116,13 +129,9 @@ export default {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onShow() {},
|
/**
|
||||||
onReady() {},
|
* 选中组
|
||||||
onReachBottom() {},
|
*/
|
||||||
onPullDownRefresh() {},
|
|
||||||
onShareTimeline() {},
|
|
||||||
onShareAppMessage() {},
|
|
||||||
methods: {
|
|
||||||
checkGroup(parentIndex) {
|
checkGroup(parentIndex) {
|
||||||
let currentItem = this.list[parentIndex];
|
let currentItem = this.list[parentIndex];
|
||||||
let currentState = !currentItem.checked;
|
let currentState = !currentItem.checked;
|
||||||
|
@ -130,7 +139,9 @@ export default {
|
||||||
this.checkItem(parentIndex, itemIndex, currentState);
|
this.checkItem(parentIndex, itemIndex, currentState);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
// 选中单项
|
/**
|
||||||
|
* 选中单项
|
||||||
|
*/
|
||||||
checkItem(parentIndex, itemIndex, state) {
|
checkItem(parentIndex, itemIndex, state) {
|
||||||
let currentItem = this.list[parentIndex].list[itemIndex];
|
let currentItem = this.list[parentIndex].list[itemIndex];
|
||||||
let currentState = typeof state === "undefined" ? !currentItem.checked : state;
|
let currentState = typeof state === "undefined" ? !currentItem.checked : state;
|
||||||
|
@ -198,7 +209,6 @@ export default {
|
||||||
for (let i = 0; i < itemIndexes.length; i++) {
|
for (let i = 0; i < itemIndexes.length; i++) {
|
||||||
let currentItem = parentItem.list[itemIndexes[i]];
|
let currentItem = parentItem.list[itemIndexes[i]];
|
||||||
await that.$models.cart.delete(currentItem.id).then(() => {
|
await that.$models.cart.delete(currentItem.id).then(() => {
|
||||||
that.$store.dispatch("cart/update", true);
|
|
||||||
parentItem.list.splice(itemIndexes[i], 1);
|
parentItem.list.splice(itemIndexes[i], 1);
|
||||||
if (parentItem.list.length > 0) {
|
if (parentItem.list.length > 0) {
|
||||||
that.updateTotal(parentIndex);
|
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);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue