优化购物车

This commit is contained in:
TOP糯米 2023-04-09 12:46:27 +08:00
parent 0607292316
commit 778faddcd4
4 changed files with 47 additions and 73 deletions

View File

@ -83,28 +83,9 @@ export default {
...mapState({ ...mapState({
cart: (state) => state.cart.cart, cart: (state) => state.cart.cart,
}), }),
...mapGetters({
isLogin: "user/isLogin",
}),
}, },
onLoad() { onLoad() {},
if (!this.isLogin) { async onShow() {
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"); await this.$store.dispatch("cart/update");
this.list = []; this.list = [];
this.cart.list.forEach((item) => { this.cart.list.forEach((item) => {
@ -129,6 +110,12 @@ export default {
}); });
}); });
}, },
onReady() {},
onReachBottom() {},
onPullDownRefresh() {},
onShareTimeline() {},
onShareAppMessage() {},
methods: {
/** /**
* 选中组 * 选中组
*/ */

View File

@ -25,7 +25,7 @@
:animation="false" :animation="false"
:x="position.x" :x="position.x"
:y="position.y" :y="position.y"
@click="toCartPage" @click="utils.toPage('/pages/service/cart')"
> >
<view class="cart-icon"> <view class="cart-icon">
<text class="iconfont icon-gouwuche"></text> <text class="iconfont icon-gouwuche"></text>
@ -47,6 +47,7 @@ export default {
name: "service-cate", name: "service-cate",
data() { data() {
return { return {
utils: this.$utils,
movableAreaStyle: { movableAreaStyle: {
height: 0, height: 0,
bottom: 0, bottom: 0,
@ -178,11 +179,6 @@ export default {
this.loadCate(); this.loadCate();
}, 1000); }, 1000);
}, },
toCartPage() {
if (this.briefCart.count > 0) {
this.$utils.toPage("/pages/service/cart");
}
},
}, },
}; };
</script> </script>

View File

@ -158,9 +158,12 @@ export default {
this.appraise.total = this.appraise.cate[0].count; this.appraise.total = this.appraise.cate[0].count;
this.changeAppraiseCate(this.appraise.cate[0], 0); this.changeAppraiseCate(this.appraise.cate[0], 0);
}); });
this.initPage();
}, },
onShow() {}, onShow() {
if (this.isLogin) {
this.$store.dispatch("cart/update");
}
},
onReady() {}, onReady() {},
onReachBottom() { onReachBottom() {
if (this.tabIndex == 0) return; if (this.tabIndex == 0) return;
@ -170,14 +173,6 @@ export default {
onShareTimeline() {}, onShareTimeline() {},
onShareAppMessage() {}, onShareAppMessage() {},
methods: { methods: {
/**
* 初始化页面
*/
initPage() {
if (this.isLogin) {
this.$store.dispatch("cart/update");
}
},
/** /**
* 分享 * 分享
*/ */

View File

@ -11,7 +11,7 @@
/> />
</view> </view>
<view class="common-bottom-components" :style="{ paddingBottom: pageConfig.safeAreaInsets.bottom + 'px' }"> <view class="common-bottom-components" :style="{ paddingBottom: pageConfig.safeAreaInsets.bottom + 'px' }">
<view class="cart" @click="toCartPage"> <view class="cart" @click="utils.toPage('/pages/service/cart')">
<view class="cart-icon"> <view class="cart-icon">
<text class="iconfont icon-gouwuche"></text> <text class="iconfont icon-gouwuche"></text>
</view> </view>
@ -34,6 +34,7 @@ export default {
name: "service-list", name: "service-list",
data() { data() {
return { return {
utils: this.$utils,
pageConfig: {}, pageConfig: {},
data: [], data: [],
currentId: 0, currentId: 0,
@ -50,23 +51,7 @@ export default {
}), }),
}, },
onLoad(e) { onLoad(e) {
this.initPage(e);
},
onShow() {},
onReady() {},
onReachBottom() {},
onPullDownRefresh() {},
onShareTimeline() {},
onShareAppMessage() {},
methods: {
/**
* 初始化页面
*/
initPage(e) {
this.pageConfig = getApp().globalData.pageConfig; this.pageConfig = getApp().globalData.pageConfig;
if (this.isLogin) {
this.$store.dispatch("cart/update");
}
if (!e.id) { if (!e.id) {
return this.$utils.toast("参数错误"); return this.$utils.toast("参数错误");
} }
@ -75,6 +60,17 @@ export default {
this.data = []; this.data = [];
this.loadList(this.currentId); this.loadList(this.currentId);
}, },
onShow() {
if (this.isLogin) {
this.$store.dispatch("cart/update");
}
},
onReady() {},
onReachBottom() {},
onPullDownRefresh() {},
onShareTimeline() {},
onShareAppMessage() {},
methods: {
/** /**
* 加载列表 * 加载列表
*/ */