优化服务列表下单按钮

This commit is contained in:
TOP糯米 2023-04-07 14:54:21 +08:00
parent 6b0bfcc41d
commit 59df75db03
1 changed files with 32 additions and 18 deletions

View File

@ -19,7 +19,7 @@
<text class="text">{{ cartCount }}</text> <text class="text">{{ cartCount }}</text>
</view> </view>
</view> </view>
<view class="order-btn" @click="toCart"> <view class="order-btn" :class="{ active: canUse }" @click="toCart">
<text class="text">去下单</text> <text class="text">去下单</text>
</view> </view>
</view> </view>
@ -37,7 +37,7 @@ export default {
utils: this.$utils, utils: this.$utils,
pageConfig: {}, pageConfig: {},
data: [], data: [],
canUse: false,
currentId: 0, currentId: 0,
}; };
}, },
@ -54,18 +54,7 @@ export default {
}), }),
}, },
onLoad(e) { onLoad(e) {
this.pageConfig = getApp().globalData.pageConfig; this.initPage(e);
if (this.isLogin) {
this.$store.dispatch("cart/updateCount");
this.$store.dispatch("cart/briefCart");
}
if (!e.id) {
this.$utils.toast("参数错误");
return;
}
this.currentId = e.id;
this.loadList(this.currentId);
}, },
onShow() {}, onShow() {},
onReady() {}, onReady() {},
@ -73,7 +62,30 @@ export default {
onPullDownRefresh() {}, onPullDownRefresh() {},
onShareTimeline() {}, onShareTimeline() {},
onShareAppMessage() {}, onShareAppMessage() {},
watch: {
cartCount(count) {
this.canUse = count > 0;
},
},
methods: { methods: {
/**
* 初始化页面
*/
initPage(e) {
this.pageConfig = getApp().globalData.pageConfig;
if (this.isLogin) {
this.$store.dispatch("cart/updateCount");
this.$store.dispatch("cart/briefCart");
}
this.canUse = this.cartCount > 0;
if (!e.id) {
return this.$utils.toast("参数错误");
}
this.currentId = e.id;
//
this.data = [];
this.loadList(this.currentId);
},
/** /**
* 加载列表 * 加载列表
*/ */
@ -134,10 +146,8 @@ export default {
* 去下单 * 去下单
*/ */
toCart() { toCart() {
if (this.cartCount > 0) { if (this.canUse) {
this.$utils.toPage("/pages/service/cart"); this.$utils.toPage("/pages/service/cart");
} else {
this.$utils.toast("请添加服务到购物车");
} }
}, },
}, },
@ -188,13 +198,17 @@ export default {
width: 300rpx; width: 300rpx;
height: 75rpx; height: 75rpx;
text-align: center; text-align: center;
background: linear-gradient(-90deg, #8194f2, #4c60c1);
border-radius: 38rpx; border-radius: 38rpx;
background: #e0e0e0;
transition: all 0.35s;
.text { .text {
font-size: 30rpx; font-size: 30rpx;
color: #ffffff; color: #ffffff;
line-height: 75rpx; line-height: 75rpx;
} }
} }
.order-btn.active {
background: linear-gradient(-90deg, #8194f2, #4c60c1);
}
} }
</style> </style>