优化购物车

This commit is contained in:
TOP糯米 2023-04-09 10:16:56 +08:00
parent b1cb87ac93
commit 9b67e9cc1b
2 changed files with 10 additions and 14 deletions

View File

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

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="toCart"> <view class="cart" @click="toCartPage">
<view class="cart-icon"> <view class="cart-icon">
<text class="iconfont icon-gouwuche"></text> <text class="iconfont icon-gouwuche"></text>
</view> </view>
@ -19,7 +19,7 @@
<text class="text">{{ briefCart.count }}</text> <text class="text">{{ briefCart.count }}</text>
</view> </view>
</view> </view>
<view class="order-btn" :class="{ active: canUseCartBtn }" @click="toCart"> <view class="order-btn" :class="{ active: briefCart.count > 0 }" @click="toCartPage">
<text class="text">去下单</text> <text class="text">去下单</text>
</view> </view>
</view> </view>
@ -34,10 +34,8 @@ export default {
name: "service-list", name: "service-list",
data() { data() {
return { return {
utils: this.$utils,
pageConfig: {}, pageConfig: {},
data: [], data: [],
canUseCartBtn: false,
currentId: 0, currentId: 0,
}; };
}, },
@ -60,11 +58,6 @@ export default {
onPullDownRefresh() {}, onPullDownRefresh() {},
onShareTimeline() {}, onShareTimeline() {},
onShareAppMessage() {}, onShareAppMessage() {},
watch: {
briefCart(cart) {
this.canUseCartBtn = cart.count > 0;
},
},
methods: { methods: {
/** /**
* 初始化页面 * 初始化页面
@ -74,7 +67,6 @@ export default {
if (this.isLogin) { if (this.isLogin) {
this.$store.dispatch("cart/update"); this.$store.dispatch("cart/update");
} }
this.canUseCartBtn = this.briefCart.count > 0;
if (!e.id) { if (!e.id) {
return this.$utils.toast("参数错误"); return this.$utils.toast("参数错误");
} }
@ -142,8 +134,8 @@ export default {
/** /**
* 去下单 * 去下单
*/ */
toCart() { toCartPage() {
if (this.canUseCartBtn) { if (this.briefCart.count > 0) {
this.$utils.toPage("/pages/service/cart"); this.$utils.toPage("/pages/service/cart");
} }
}, },