Files
mp-10550/src/components/CouponList.tsx
赵忠林 9d9762ef17 feat(theme): 实现主题切换系统并优化经销商相关页面
- 新增主题切换系统,支持智能主题和手动选择
- 更新经销商首页、团队、订单、提现等页面样式
- 添加主题相关的Hook和样式工具函数
- 优化部分组件样式以适配新主题
2025-08-19 00:08:26 +08:00

97 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<CouponListProps> = ({
coupons = [],
title,
layout = 'vertical',
showEmpty = true,
emptyText = '暂无优惠券',
onCouponClick
}) => {
const handleCouponClick = (coupon: CouponCardProps, index: number) => {
onCouponClick?.(coupon, index)
}
// 垂直布局
if (layout === 'vertical') {
return (
<View className="p-4">
{title && (
<View className="font-semibold text-gray-800 mb-4">{title}</View>
)}
{coupons.length === 0 ? (
showEmpty && (
<View className="text-center py-10 px-5 text-gray-500">
{emptyText}
</View>
)
) : (
coupons.map((coupon, index) => (
<View
key={index}
onClick={() => handleCouponClick(coupon, index)}
>
<CouponCard {...coupon} />
</View>
))
)}
</View>
)
}
// 水平滚动布局
return (
<View>
{title && (
<View className="font-semibold text-gray-800 mb-4 pl-4">
{title}
</View>
)}
{coupons.length === 0 ? (
showEmpty && (
<View className="text-center py-10 px-5 text-gray-500">
{emptyText}
</View>
)
) : (
<ScrollView
scrollX
className="flex p-4 gap-2 overflow-x-auto"
showScrollbar={false}
>
{coupons.map((coupon, index) => (
<View
key={index}
className="flex-shrink-0 w-60 mb-0"
onClick={() => handleCouponClick(coupon, index)}
>
<CouponCard {...coupon} />
</View>
))}
</ScrollView>
)}
</View>
)
}
export default CouponList