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

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, watchEffect,
defineExpose, defineExpose,
toRaw, toRaw,
onMounted onMounted,
nextTick
} from 'vue' } from 'vue'
import { import {
@@ -420,9 +421,9 @@
// 跳转 // 跳转
const goUrl = (item) => { const goUrl = (item) => {
const canDikouGoodsArr = props.nowCarts const canDikouGoodsArr = props.nowCarts
const goodsOrderPrice = props.listinfo.totalPrices // const goodsOrderPrice = props.listinfo.totalPrices
// const user=uni.cache.get('shopUserInfo') // const user=uni.cache.get('shopUserInfo')
uni.setStorageSync('goodsOrderPrice', goodsOrderPrice) uni.setStorageSync('goodsOrderPrice', cartStore.orderCostSummary.goodsRealAmount)
if (props.isBwc) { if (props.isBwc) {
uni.showToast({ uni.showToast({
@@ -563,17 +564,18 @@
} }
} }
// 初始化订单计算可能为计算完毕,所以判断监听价格变化后再获取优惠券
onMounted(async () => { let loadFinish = false
getConsumeDiscount() watch(() => cartStore.orderCostSummary.goodsRealAmount,async (newval) => {
//积分可抵扣最大金额 if (newval && !loadFinish) {
const goodsOrderPrice = cartStore.orderCostSummary.goodsRealAmount - cartStore.orderCostSummary const goodsOrderPrice = cartStore.orderCostSummary.goodsRealAmount
const dinnerType = cartStore.dinnerType const dinnerType = cartStore.dinnerType
const shopInfo = cartStore.shopInfo const shopInfo = cartStore.shopInfo
const shopId = cartStore.shopInfo.shopId const shopId = cartStore.shopInfo.shopId
const user = uni.cache.get('shopUserInfo') const user = uni.cache.get('shopUserInfo')
const shopUserId = user.id const shopUserId = user.id
const allGoods = cartStore.allGoods const allGoods = cartStore.allGoods
hasCouponCanUse.value = await returnHasCouponCanUse({ hasCouponCanUse.value = await returnHasCouponCanUse({
goodsOrderPrice, goodsOrderPrice,
dinnerType, dinnerType,
@@ -584,6 +586,11 @@
user user
}) })
console.log('hasCouponCanUse', hasCouponCanUse.value); console.log('hasCouponCanUse', hasCouponCanUse.value);
}
})
onMounted(() => {
getConsumeDiscount()
}) })
</script> </script>

View File

@@ -18,7 +18,8 @@ export async function returnHasCouponCanUse(args) {
if(!res||res.length<=0){ if(!res||res.length<=0){
return false return false
} }
console.log('returnHasCouponCanUse:goodsOrderPrice',goodsOrderPrice);
console.log('returnHasCouponCanUse:allGoods',allGoods);
const canDikouGoodsArr = UTILS.returnCanDikouGoods(allGoods, [], user); const canDikouGoodsArr = UTILS.returnCanDikouGoods(allGoods, [], user);
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
const coupon = res[i] const coupon = res[i]

View File

@@ -126,12 +126,11 @@ export function returnCouponCanUse(args) {
selCoupon, selCoupon,
shopInfo shopInfo
} = args; } = args;
// 优惠券未启用 // 优惠券未启用
if (!coupon.use) { if (!coupon.use) {
return { return {
canUse: false, canUse: false,
reason: "优惠券未启用" reason:coupon.noUseRestrictions|| "不在可用时间段内"
}; };
} }