fix:修复bug

This commit is contained in:
2026-03-17 12:03:54 +08:00
parent 5d7b973ddd
commit 60df817de5
32 changed files with 654 additions and 528 deletions
@@ -3,12 +3,12 @@ import {useConfigStore} from "@/store";
import {receiveCouponApi} from "@/pages-user/service";
const configStore = useConfigStore()
const {t} = useI18n()
const { t, locale } = useI18n()
const emit = defineEmits(['confirm'])
const props = defineProps({
couponList: {
type: Array,
type: Array as unknown as PropType<any[]>,
default: () => []
}
})
@@ -37,6 +37,57 @@ function confirmCoupon(item: any) {
defineExpose({
init
});
function daySuffix(value: unknown) {
const n = Number(value)
const isEn = String(locale.value || '').toLowerCase().startsWith('en')
if (isEn) {
return n === 1 ? ` ${t('pages-store.store.day')}` : ` ${t('pages-store.store.days')}`
}
return t('pages-store.store.days')
}
function isEnLocale() {
return String(locale.value || '').toLowerCase().startsWith('en')
}
function formatMoney(value: unknown) {
const n = Number(value)
if (!Number.isFinite(n)) return '0.00'
return n.toFixed(2)
}
function couponTitleText(item: any) {
const type = Number(item?.couponType)
const discountValue = Number(item?.discountValue)
// 标题保持原样:折扣券显示百分比,满减券只显示减免金额(不展示门槛)
if (type === 1) {
const pct = Number.isFinite(discountValue) ? Number(discountValue * 100).toFixed(0) : '0'
return `${pct}% ${t('pages-store.store.couponOff')}`
}
return `$${formatMoney(discountValue)} ${t('pages-store.store.couponOff')}`
}
function couponBenefitText(item: any) {
const type = Number(item?.couponType)
const discountValue = Number(item?.discountValue)
const minAmount = Number(item?.minAmount)
if (type === 2) {
const discountText = `$${formatMoney(discountValue)}`
const hasMin = Number.isFinite(minAmount) && minAmount > 0
if (hasMin) {
const minText = `$${formatMoney(minAmount)}`
return isEnLocale() ? `Min ${minText} · Off ${discountText}` : `${minText}${discountText} 优惠`
}
return isEnLocale() ? `Off ${discountText}` : `立减${discountText}`
}
const pct = Number.isFinite(discountValue) ? Number(discountValue * 100).toFixed(0) : '0'
return `${pct}%`
}
</script>
<template>
@@ -44,20 +95,15 @@ defineExpose({
<view class="bg-#F5F5F5 px-32rpx pt-30rpx">
<view class="text-40rpx lh-40rpx text-#333 font-bold text-center mb-60rpx">{{ t('pages-store.store.claimCoupon') }}</view>
<scroll-view scroll-y class="h-1000rpx">
<template v-for="item in couponList">
<template v-for="item in couponList" :key="item.id">
<view class="coupon-item h-328rpx flex flex-col mb-30rpx last:mb-0">
<view class="flex-1 pt-40rpx px-58rpx">
<view class="line-clamp-1 text-34rpx lh-34rpx text-#333 font-bold">
<!-- couponType 1-折扣券, 2-满减券-->
<template v-if="item.couponType === 1">
{{ Number(item.discountValue * 100).toFixed(0) }}% {{ t('pages-store.store.couponOff') }}
</template>
<template v-else>
${{ item.discountValue }} {{ t('pages-store.store.couponOff') }}
</template>
{{ couponTitleText(item) }}
</view>
<view class="text-24rpx lh-32rpx text-#999 my-18rpx">
{{ t('pages-store.store.validDays') }}: {{ item.validDays }} {{ t('pages-store.store.days') }}
{{ t('pages-store.store.validDays') }}: {{ item.validDays }}{{ daySuffix(item.validDays) }}
</view>
<view class="text-24rpx lh-32rpx text-#999 my-18rpx">
{{ item.nameZh }}
@@ -67,12 +113,8 @@ defineExpose({
class="w-36rpx h-36rpx shrink-0 mr-10rpx"
src="@img/chef/106.png"
></image>
{{ t('pages-store.store.get') }} <template v-if="item.couponType === 1">
{{ Number(item.discountValue * 100).toFixed(0) }}%
</template>
<template v-else>
${{ item.discountValue }}
</template> {{ t('pages-store.store.couponOff') }}
{{ t('pages-store.store.get') }} {{ couponBenefitText(item) }}
<template v-if="Number(item?.couponType) === 1"> {{ t('pages-store.store.couponOff') }}</template>
</view>
</view>
<template v-if="item.userCouponVo">