import React from 'react' import { View, Text } from '@tarojs/components' import GiftCard from '@/components/GiftCard' import { ShopGift } from '@/api/shop/shopGift/model' const StatusTest: React.FC = () => { // 测试不同状态的礼品卡 const testGifts: ShopGift[] = [ { id: 1, name: '未使用礼品卡', goodsName: '杜尔伯特草原奶香牛上脑(2kg,分4小包)', goodsImage: 'https://img.alicdn.com/imgextra/i1/2206571109/O1CN01QZxQJJ1Uw8QZxQJJ_!!2206571109.jpg', description: '未使用状态的礼品卡', code: 'UNUSED1234567890', goodsId: 101, faceValue: '200', type: 10, status: 0, // 未使用 expireTime: '2024-12-31 23:59:59', instructions: '适用于实物商品兑换', contactInfo: '400-800-8888' }, { id: 2, name: '已使用礼品卡', goodsName: '星巴克经典拿铁咖啡券', goodsImage: 'https://img.alicdn.com/imgextra/i2/2206571109/O1CN01ABC123_!!2206571109.jpg', description: '已使用状态的礼品卡', code: 'USED001234567890', goodsId: 102, faceValue: '100', type: 20, status: 1, // 已使用 useTime: '2024-08-15 14:30:00', useLocation: '星巴克王府井店', instructions: '适用于虚拟商品兑换', contactInfo: '400-800-8888' }, { id: 3, name: '失效礼品卡', goodsName: '海底捞4人套餐券', goodsImage: 'https://img.alicdn.com/imgextra/i3/2206571109/O1CN01DEF456_!!2206571109.jpg', description: '失效状态的礼品卡', code: 'INVALID1234567890', goodsId: 103, faceValue: '300', type: 30, status: 2, // 失效 expireTime: '2024-07-31 23:59:59', instructions: '适用于服务类商品兑换', contactInfo: '400-800-8888' } ] // 转换数据格式 const transformGiftData = (gift: ShopGift) => { return { id: gift.id || 0, name: gift.name || '礼品卡', goodsName: gift.goodsName, description: gift.description || gift.instructions, code: gift.code, goodsImage: gift.goodsImage, faceValue: gift.faceValue, type: gift.type, status: gift.status, // 使用 status 字段 expireTime: gift.expireTime, useTime: gift.useTime, useLocation: gift.useLocation, contactInfo: gift.contactInfo, goodsInfo: { ...((gift.goodsName || gift.goodsId) && { specification: `礼品卡面值:¥${gift.faceValue}`, category: getTypeText(gift.type), tags: [ getTypeText(gift.type), getStatusText(gift.status), '测试卡片' ].filter(Boolean), instructions: [ '这是状态测试卡片', '请检查状态显示是否正确', '不可兑换现金' ], notices: [ '这是测试数据', '请勿实际使用', '仅用于状态测试' ] }) }, showCode: gift.status === 0, // 只有未使用状态显示兑换码 showUseBtn: gift.status === 0, // 只有未使用状态显示使用按钮 showDetailBtn: true, showGoodsDetail: true, theme: getThemeByType(gift.type), onUse: () => console.log('使用:', gift.goodsName || gift.name), onDetail: () => console.log('详情:', gift.goodsName || gift.name), onClick: () => console.log('点击:', gift.goodsName || gift.name) } } const getTypeText = (type?: number): string => { switch (type) { case 10: return '实物礼品卡' case 20: return '虚拟礼品卡' case 30: return '服务礼品卡' default: return '通用礼品卡' } } const getStatusText = (status?: number): string => { switch (status) { case 0: return '未使用' case 1: return '已使用' case 2: return '失效' default: return '未知状态' } } const getThemeByType = (type?: number): 'gold' | 'silver' | 'bronze' | 'blue' | 'green' | 'purple' => { switch (type) { case 10: return 'gold' case 20: return 'blue' case 30: return 'green' default: return 'purple' } } const getExpectedBehavior = (status?: number): string => { switch (status) { case 0: return '显示兑换码和使用按钮' case 1: return '显示使用时间,无兑换码和使用按钮' case 2: return '显示失效状态,无兑换码和使用按钮' default: return '未知行为' } } return ( {/* 页面标题 */} 礼品卡状态字段测试 验证 status 字段替代 useStatus 字段 {/* 状态说明 */} 状态字段说明: • status=0 (未使用) → 显示"未使用"标签 • status=1 (已使用) → 显示"已使用"标签 • status=2 (失效) → 显示"失效"标签 {/* 修改说明 */} 字段修改说明: ✅ useStatus 字段已废弃 ✅ 使用 status 字段替代 ✅ 状态文本更新:可用→未使用,已过期→失效 ✅ Tab标签文本同步更新 {/* 礼品卡列表 */} {testGifts.map((gift, index) => ( 测试 {index + 1}: status={gift.status} → {getStatusText(gift.status)} 预期行为: {getExpectedBehavior(gift.status)} ))} {/* 验证清单 */} 验证清单: □ status=0 的卡片显示"未使用"标签 □ status=0 的卡片显示兑换码和使用按钮 □ status=1 的卡片显示"已使用"标签 □ status=1 的卡片显示使用时间 □ status=1 的卡片不显示兑换码和使用按钮 □ status=2 的卡片显示"失效"标签 □ status=2 的卡片有状态遮罩 □ 所有非0状态的卡片都有disabled样式 {/* API 参数说明 */} API 参数更新: • 筛选参数:useStatus → status • 返回字段:useStatus → status • 状态值:0未使用 1已使用 2失效 ) } export default StatusTest