import React from 'react' import { View, Text } from '@tarojs/components' import type { ShopUserCoupon } from '@/api/shop/shopUserCoupon/model' import { getCouponTypeText, formatCouponValue, isExpiringSoon } from '@/hooks/useCoupon' interface CouponCardProps { coupon: ShopUserCoupon disabled?: boolean onClick?: () => void showDelete?: boolean onDelete?: () => void } const CouponCard: React.FC = ({ coupon, disabled = false, onClick, showDelete = false, onDelete, }) => { const isUsed = coupon.status === 1 const isExpired = coupon.status === 2 || coupon.isExpire === 1 const expiringSoon = isExpiringSoon(coupon) const getValidTime = () => { if (coupon.startTime && coupon.endTime) { return `${coupon.startTime.slice(0, 10)} - ${coupon.endTime.slice(0, 10)}` } return '永久有效' } const getRangeText = () => { switch (coupon.applyRange) { case 10: return '全场通用' case 20: return '指定商品' case 30: return '指定分类' default: return '全场通用' } } return ( {/* 左侧金额区域 */} {formatCouponValue(coupon)} {(() => { if (coupon.type === 50) { // 场地使用券 const parts: string[] = [] if (coupon.useDuration && coupon.useDuration > 0) parts.push(`${coupon.useDuration}分钟`) return parts.length > 0 ? ( {parts.join(' | ')} ) : null } if (coupon.type === 40 || !coupon.minPrice || Number(coupon.minPrice) <= 0) return null return 满{coupon.minPrice}可用 })()} {/* 右侧信息区域 */} {coupon.name || getCouponTypeText(coupon.type)} {expiringSoon && !isUsed && !isExpired && ( 即将过期 )} {getRangeText()} {getValidTime()} {coupon.description && ( {coupon.description} )} {/* 状态标签 */} {isUsed && ( 已使用 )} {isExpired && ( 已过期 )} {!isUsed && !isExpired && ( )} {/* 删除按钮 */} {showDelete && (isUsed || isExpired) && ( { e.stopPropagation(); onDelete?.() }}> 删除 )} ) } export default CouponCard