diff --git a/pages/order/components/orderInfo.vue b/pages/order/components/orderInfo.vue index 4114984..721aacc 100644 --- a/pages/order/components/orderInfo.vue +++ b/pages/order/components/orderInfo.vue @@ -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); + }) diff --git a/utils/coupon.js b/utils/coupon.js index e99ec8b..6a47aea 100644 --- a/utils/coupon.js +++ b/utils/coupon.js @@ -18,7 +18,8 @@ export async function returnHasCouponCanUse(args) { if(!res||res.length<=0){ return false } - + console.log('returnHasCouponCanUse:goodsOrderPrice',goodsOrderPrice); + console.log('returnHasCouponCanUse:allGoods',allGoods); const canDikouGoodsArr = UTILS.returnCanDikouGoods(allGoods, [], user); for (let i = 0; i < res.length; i++) { const coupon = res[i] diff --git a/utils/goods-utils.js b/utils/goods-utils.js index 41b8638..bcad2d8 100644 --- a/utils/goods-utils.js +++ b/utils/goods-utils.js @@ -126,12 +126,11 @@ export function returnCouponCanUse(args) { selCoupon, shopInfo } = args; - // 优惠券未启用 if (!coupon.use) { return { canUse: false, - reason: "优惠券未启用" + reason:coupon.noUseRestrictions|| "不在可用时间段内" }; }