import { StyleProp, ViewStyle, TextStyle, ImageSourcePropType } from 'react-native'; import type { SelectionOption } from '../DbSelectionButton/DbSelectionButton.types'; /** SelectionButton 配置 */ export interface SelectionButtonConfig { /** 按钮样式:圆角大小 */ borderRadius?: number; /** 按钮间距 */ gap?: number; /** 选中背景色 */ activeBackgroundColor?: string; /** 选中文字颜色 */ activeTextColor?: string; /** 未选中背景色 */ inactiveBackgroundColor?: string; /** 未选中文字颜色 */ inactiveTextColor?: string; /** 未选中边框颜色 */ inactiveBorderColor?: string; /** 是否可取消选择 */ deselectable?: boolean; /** 自定义按钮渲染 */ renderButton?: (option: SelectionOption, isSelected: boolean, onPress: () => void) => React.ReactNode; } /** SKU 属性值选项 */ export interface SkuAttributeValue { /** 属性值 ID */ id: string; /** 属性值名称 */ name: string; /** 是否禁用(如库存为 0) */ disabled?: boolean; /** 关联图片 URL(如颜色对应的商品图) */ imageUrl?: string; } /** SKU 属性组 */ export interface SkuAttribute { /** 属性组 ID */ id: string; /** 属性组名称(如"颜色"、"版本") */ name: string; /** 属性值列表 */ values: SkuAttributeValue[]; /** 选择模式:单选(默认) / 多选 */ multiple?: boolean; } /** SKU 组合(对应一个具体的商品规格) */ export interface SkuCombination { /** SKU ID */ id: string; /** 价格 */ price: number; /** 原价(划线价) */ originalPrice?: number; /** 库存 */ stock: number; /** 图片 URL */ imageUrl?: string; /** SKU 编码 */ skuCode?: string; /** 属性值 ID 映射 */ attributes: Record; } /** 商品信息 */ export interface SkuGoodsInfo { /** 商品图片 URL */ imageUrl: string; /** 商品图片本地资源(优先于 imageUrl) */ imageSource?: ImageSourcePropType; /** 商品名称 */ title?: string; /** 商品编号 */ goodsCode?: string; /** 价格 */ price: number; /** 原价(划线价) */ originalPrice?: number; /** 货币符号 */ currency?: string; } /** SKU 选择结果 */ export interface SkuSelectedResult { /** 选中的属性值 { 属性组ID: 属性值ID } */ selectedAttributes: Record; /** 购买数量 */ quantity: number; /** 匹配的 SKU 组合(如果配置了 combinations) */ selectedSku?: SkuCombination; } /** DbSku 组件属性 */ export interface DbSkuProps { /** 是否显示 */ visible: boolean; /** 关闭回调 */ onClose?: () => void; /** 商品信息 */ goods: SkuGoodsInfo; /** SKU 属性组列表 */ attributes: SkuAttribute[]; /** 默认选中的属性值 */ defaultSelected?: Record; /** SKU 组合列表(用于联动价格、库存、禁用等) */ combinations?: SkuCombination[]; /** 属性选择变化回调 */ onAttributeChange?: (attributeId: string, valueId: string, allSelected: Record) => void; /** 是否显示购买数量 */ showQuantity?: boolean; /** 购买数量标题 */ quantityTitle?: string; /** 默认购买数量 */ defaultQuantity?: number; /** 最小购买数量 */ minQuantity?: number; /** 最大购买数量 */ maxQuantity?: number; /** 数量变化回调 */ onQuantityChange?: (quantity: number) => void; /** 确认按钮文案 */ confirmText?: string; /** 确认回调 */ onConfirm?: (result: SkuSelectedResult) => void; /** 加入购物车文案 */ addCartText?: string; /** 加入购物车回调 */ onAddCart?: (result: SkuSelectedResult) => void; /** 是否显示加入购物车按钮 */ showAddCart?: boolean; /** 自定义渲染商品信息区域 */ renderGoodsInfo?: (goods: SkuGoodsInfo) => React.ReactNode; /** 自定义渲染底部操作按钮 */ renderFooter?: (result: SkuSelectedResult) => React.ReactNode; /** 自定义渲染额外内容(在属性和数量之间) */ renderExtra?: () => React.ReactNode; /** * 自定义渲染单个属性区域 * 传入后完全接管该属性的渲染,包括标题和选项 */ renderAttribute?: (attribute: SkuAttribute, options: SelectionOption[], selectedValue: string | undefined, onChange: (value: string) => void) => React.ReactNode; /** * 自定义渲染整个属性列表区域 * 传入后完全接管所有属性的渲染 */ renderAttributes?: (attributes: SkuAttribute[], selectedAttrs: Record, onAttributeChange: (attributeId: string, valueId: string) => void) => React.ReactNode; /** SelectionButton 配置 */ selectionButtonConfig?: SelectionButtonConfig; /** 弹窗样式 */ popupStyle?: StyleProp; /** 商品信息区域样式 */ goodsInfoStyle?: StyleProp; /** 价格文字样式 */ priceStyle?: StyleProp; /** 属性区域样式 */ attributeStyle?: StyleProp; /** 属性标题样式 */ attributeTitleStyle?: StyleProp; /** 操作按钮区域样式 */ footerStyle?: StyleProp; }