import React from 'react' import { View, ScrollView } from '@tarojs/components' import CouponCard, { CouponCardProps } from './CouponCard' export interface CouponListProps { /** 优惠券列表数据 */ coupons: CouponCardProps[] /** 列表标题 */ title?: string /** 布局方式:vertical-垂直布局 horizontal-水平滚动 */ layout?: 'vertical' | 'horizontal' /** 是否显示空状态 */ showEmpty?: boolean /** 空状态文案 */ emptyText?: string /** 优惠券点击事件 */ onCouponClick?: (coupon: CouponCardProps, index: number) => void } const CouponList: React.FC = ({ coupons = [], title, layout = 'vertical', showEmpty = true, emptyText = '暂无优惠券', onCouponClick }) => { const handleCouponClick = (coupon: CouponCardProps, index: number) => { onCouponClick?.(coupon, index) } // 垂直布局 if (layout === 'vertical') { return ( {title && ( {title} )} {coupons.length === 0 ? ( showEmpty && ( {emptyText} ) ) : ( coupons.map((coupon, index) => ( handleCouponClick(coupon, index)} > )) )} ) } // 水平滚动布局 return ( {title && ( {title} )} {coupons.length === 0 ? ( showEmpty && ( {emptyText} ) ) : ( {coupons.map((coupon, index) => ( handleCouponClick(coupon, index)} > ))} )} ) } export default CouponList