import {useState, useEffect} from "react"; import {useRouter} from '@tarojs/taro' import {Button, ConfigProvider, Tag, Divider, Image} from '@nutui/nutui-react-taro' import {ArrowLeft, Gift, Clock, Location, Phone, Share, Copy} from '@nutui/icons-react-taro' import Taro from '@tarojs/taro' import {View, Text} from '@tarojs/components' import {ShopGift} from "@/api/shop/shopGift/model"; import {getShopGift} from "@/api/shop/shopGift"; import GiftCardShare from "@/components/GiftCardShare"; import dayjs from "dayjs"; const GiftCardDetail = () => { const router = useRouter() const [gift, setGift] = useState(null) const [loading, setLoading] = useState(true) const [showShare, setShowShare] = useState(false) const giftId = router.params.id useEffect(() => { if (giftId) { loadGiftDetail() } }, [giftId]) const loadGiftDetail = async () => { try { setLoading(true) const data = await getShopGift(Number(giftId)) setGift(data) } catch (error) { console.error('获取礼品卡详情失败:', error) Taro.showToast({ title: '获取礼品卡详情失败', icon: 'error' }) } finally { setLoading(false) } } // 获取礼品卡类型文本 const getGiftTypeText = (type?: number) => { switch (type) { case 10: return '实物礼品卡' case 20: return '虚拟礼品卡' case 30: return '服务礼品卡' default: return '礼品卡' } } // 获取礼品卡面值显示 const getGiftValueDisplay = () => { if (!gift || !gift.faceValue) return '' return `¥${gift.faceValue}` } // 获取使用条件文本 const getUsageText = () => { if (!gift) return '' if (gift.instructions) { return gift.instructions } switch (gift.type) { case 10: return '请到指定门店使用此礼品卡' case 20: return '可在线上平台直接使用' case 30: return '请联系客服预约服务时间' default: return '请按照使用说明进行操作' } } // 获取有效期文本 const getValidityText = () => { if (!gift) return '' if (gift.validDays) { return `有效期${gift.validDays}天` } else if (gift.expireTime) { return `有效期至 ${dayjs(gift.expireTime).format('YYYY年MM月DD日')}` } else { return '长期有效' } } // 获取礼品卡状态 const getGiftStatus = () => { if (!gift) return { status: 0, text: '未知', color: 'default' } switch (gift.useStatus) { case 0: return { status: 0, text: '可使用', color: 'success' } case 1: return { status: 1, text: '已使用', color: 'warning' } case 2: return { status: 2, text: '已过期', color: 'danger' } default: return { status: 0, text: '未知', color: 'default' } } } // 使用礼品卡 const handleUseGift = () => { if (!gift) return Taro.showModal({ title: '使用礼品卡', content: `确定要使用"${gift.name}"吗?`, success: (res) => { if (res.confirm) { // 跳转到礼品卡使用页面 Taro.navigateTo({ url: `/user/gift/use?id=${gift.id}` }) } } }) } // 复制兑换码 const handleCopyCode = () => { if (!gift?.code) return Taro.setClipboardData({ data: gift.code, success: () => { Taro.showToast({ title: '兑换码已复制', icon: 'success' }) }, fail: () => { Taro.showToast({ title: '复制失败', icon: 'error' }) } }) } // 返回上一页 const handleBack = () => { Taro.navigateBack() } if (loading) { return ( 加载中... ) } if (!gift) { return ( 礼品卡不存在 ) } const statusInfo = getGiftStatus() return ( {/* 礼品卡卡片 */} {getGiftValueDisplay()} {getGiftTypeText(gift.type)} {gift.goodsImage ? ( ) : ( )} {gift.name} {gift.description || getUsageText()} {/* 兑换码 */} {gift.code && ( 兑换码 {gift.code} )} {/* 详细信息 */} 使用说明 有效期 {getValidityText()} 礼品卡类型 {getGiftTypeText(gift.type)} {gift.useLocation && ( <> 使用地址 {gift.useLocation} )} {gift.contactInfo && ( <> 客服联系 {gift.contactInfo} )} {gift.instructions && ( <> 使用说明 {gift.instructions} )} {gift.useTime && ( <> 使用记录 使用时间:{dayjs(gift.useTime).format('YYYY-MM-DD HH:mm')} )} {/* 底部操作按钮 */} {statusInfo.status === 0 && ( {gift.code && ( )} )} {/* 分享弹窗 */} {gift && ( setShowShare(false)} /> )} ); }; export default GiftCardDetail;