import React from 'react' import { View, ScrollView } from '@tarojs/components' import GiftCard, { GiftCardProps } from './GiftCard' export interface GiftCardListProps { /** 礼品卡列表数据 */ gifts: GiftCardProps[] /** 列表标题 */ title?: string /** 布局方式:vertical-垂直布局 horizontal-水平滚动 grid-网格布局 */ layout?: 'vertical' | 'horizontal' | 'grid' /** 网格列数(仅在grid布局时有效) */ columns?: number /** 是否显示空状态 */ showEmpty?: boolean /** 空状态文案 */ emptyText?: string /** 礼品卡点击事件 */ onGiftClick?: (gift: GiftCardProps, index: number) => void /** 礼品卡使用事件 */ onGiftUse?: (gift: GiftCardProps, index: number) => void /** 礼品卡详情事件 */ onGiftDetail?: (gift: GiftCardProps, index: number) => void } const GiftCardList: React.FC = ({ gifts = [], title, layout = 'vertical', columns = 2, showEmpty = true, emptyText = '暂无礼品卡', onGiftClick, onGiftUse, onGiftDetail }) => { const handleGiftClick = (gift: GiftCardProps, index: number) => { onGiftClick?.(gift, index) } const handleGiftUse = (gift: GiftCardProps, index: number) => { onGiftUse?.(gift, index) } const handleGiftDetail = (gift: GiftCardProps, index: number) => { onGiftDetail?.(gift, index) } // 垂直布局 if (layout === 'vertical') { return ( {title && ( {title} )} {gifts.length === 0 ? ( showEmpty && ( 🎁 {emptyText} ) ) : ( gifts.map((gift, index) => ( <> handleGiftClick(gift, index)} onUse={() => handleGiftUse(gift, index)} onDetail={() => handleGiftDetail(gift, index)} /> )) )} ) } // 网格布局 if (layout === 'grid') { return ( {title && ( {title} )} {gifts.length === 0 ? ( showEmpty && ( 🎁 {emptyText} ) ) : ( {gifts.map((gift, index) => ( handleGiftClick(gift, index)} onUse={() => handleGiftUse(gift, index)} onDetail={() => handleGiftDetail(gift, index)} /> ))} )} ) } // 水平滚动布局 return ( {title && ( {title} )} {gifts.length === 0 ? ( showEmpty && ( 🎁 {emptyText} ) ) : ( {gifts.map((gift, index) => ( handleGiftClick(gift, index)} onUse={() => handleGiftUse(gift, index)} onDetail={() => handleGiftDetail(gift, index)} /> ))} )} ) } export default GiftCardList