修复判断是否有可用优惠券

This commit is contained in:
2025-10-10 11:30:29 +08:00
parent f0fee9085d
commit 87babdda60
3 changed files with 37 additions and 30 deletions

View File

@@ -258,7 +258,8 @@
watchEffect,
defineExpose,
toRaw,
onMounted
onMounted,
nextTick
} from 'vue'
import {
@@ -420,9 +421,9 @@
// 跳转
const goUrl = (item) => {
const canDikouGoodsArr = props.nowCarts
const goodsOrderPrice = props.listinfo.totalPrices
// const goodsOrderPrice = props.listinfo.totalPrices
// const user=uni.cache.get('shopUserInfo')
uni.setStorageSync('goodsOrderPrice', goodsOrderPrice)
uni.setStorageSync('goodsOrderPrice', cartStore.orderCostSummary.goodsRealAmount)
if (props.isBwc) {
uni.showToast({
@@ -474,14 +475,14 @@
})
Object.assign(pointsRes, res)
maxPointDiscount.value = res.maxDeductionAmount
if(usePoints.value){
if (usePoints.value) {
cartStore.setUserPoints(res.maxUsablePoints || 0)
}
console.log('getMaxPointsDiscount:cartStore.orderCostSummary.pointUsed', cartStore.orderCostSummary.pointUsed);
}
watch(() => maxMoney.value, (newval) => {
console.log('maxMoney.value', newval);
getMaxPointsDiscount()
getMaxPointsDiscount()
})
watch(() => usePoints.value, (newval) => {
if (newval) {
@@ -548,9 +549,9 @@
const consumeDiscountRes = await consumeDiscount({
shopId: uni.cache.get('shopId'),
})
if(!consumeDiscountRes){
if (!consumeDiscountRes) {
favorablelist.value = back_favorablelist.filter(v => v.name != '新客立减')
return
return
}
if (!consumeDiscountRes.isUse) {
favorablelist.value = back_favorablelist.filter(v => v.name != '新客立减')
@@ -562,28 +563,34 @@
cartStore.consumeDiscount = consumeDiscountRes
}
}
// 初始化订单计算可能为计算完毕,所以判断监听价格变化后再获取优惠券
let loadFinish = false
watch(() => cartStore.orderCostSummary.goodsRealAmount,async (newval) => {
if (newval && !loadFinish) {
const goodsOrderPrice = cartStore.orderCostSummary.goodsRealAmount
const dinnerType = cartStore.dinnerType
const shopInfo = cartStore.shopInfo
const shopId = cartStore.shopInfo.shopId
const user = uni.cache.get('shopUserInfo')
const shopUserId = user.id
const allGoods = cartStore.allGoods
onMounted(async () => {
hasCouponCanUse.value = await returnHasCouponCanUse({
goodsOrderPrice,
dinnerType,
shopId,
shopInfo,
shopUserId,
allGoods,
user
})
console.log('hasCouponCanUse', hasCouponCanUse.value);
}
})
onMounted(() => {
getConsumeDiscount()
//积分可抵扣最大金额
const goodsOrderPrice = cartStore.orderCostSummary.goodsRealAmount - cartStore.orderCostSummary
const dinnerType = cartStore.dinnerType
const shopInfo = cartStore.shopInfo
const shopId = cartStore.shopInfo.shopId
const user = uni.cache.get('shopUserInfo')
const shopUserId = user.id
const allGoods = cartStore.allGoods
hasCouponCanUse.value = await returnHasCouponCanUse({
goodsOrderPrice,
dinnerType,
shopId,
shopInfo,
shopUserId,
allGoods,
user
})
console.log('hasCouponCanUse', hasCouponCanUse.value);
})
</script>