/** * 团购券开台页面 */ import { View, Text, Image, Input } from '@tarojs/components' import Taro, { useLoad } from '@tarojs/taro' import { useState } from 'react' import './index.scss' // 使用本地图片资源 const phoneIcon = require('../startTable/images/phone.png') const scanIcon = require('./images/scanIconIn.png') // 券类型枚举 enum CouponType { THIRD_PARTY = 'third_party', ACTIVITY = 'activity', } // 券数据接口 interface Coupon { id: number type: string // '团八' | '黑八' duration: string couponType: string // '活动抵时券' | '抵时券' title: string expireDate: string description: string details: string[] expanded: boolean } const CouponStart = () => { const [couponCode, setCouponCode] = useState('') // 券码 const [selectedCouponType, setSelectedCouponType] = useState(CouponType.THIRD_PARTY) const [selectedCouponId, setSelectedCouponId] = useState(1) // 选中的券ID // 券列表数据 const [coupons, setCoupons] = useState([ { id: 1, type: '团八', duration: '20', couponType: '活动抵时券', title: '20分钟通用券(体验券)', expireDate: '2025-10-01 16:21', description: '需要交押金,超时扣押金\n单笔满40分钟可减免20分钟', details: ['不限时段,全天可用', '适用类型:中八', '每桌只单限用1张'], expanded: false, }, { id: 2, type: '黑八', duration: '180', couponType: '抵时券', title: '自助中式台球3小时59.9元体验券', expireDate: '2025-11-01 09:00', description: '', details: ['不限时段,全天可用'], expanded: false, }, ]) useLoad(() => { console.log('团购券开台页面加载') }) // 拨打电话 const handlePhoneCall = () => { Taro.makePhoneCall({ phoneNumber: '100-666-XXXX', }).catch((err) => { console.error('拨打电话失败:', err) }) } // 扫描券码 const handleScanCode = () => { Taro.scanCode({ scanType: ['qrCode', 'barCode'], }).then((res) => { setCouponCode(res.result) }).catch((err) => { console.error('扫码失败:', err) }) } // 切换券类型 const handleSwitchType = (type: CouponType) => { setSelectedCouponType(type) } // 选择券 const handleSelectCoupon = (id: number) => { setSelectedCouponId(id) } // 展开/收起券详情 const handleToggleExpand = (id: number) => { setCoupons(prev => prev.map(coupon => coupon.id === id ? { ...coupon, expanded: !coupon.expanded } : coupon )) } // 跳转到我的卡券页面 const handleGoMyCoupons = () => { Taro.navigateTo({ url: '/pageScan/myCoupons/index' }) } // 兑换开台 const handleExchange = () => { if (!selectedCouponId) { Taro.showToast({ title: '请选择一张券', icon: 'none', duration: 2000 }) return } console.log('兑换开台,选中券ID:', selectedCouponId) Taro.showToast({ title: '功能开发中', icon: 'none', duration: 2000 }) } return ( {/* 内容区域 */} {/* 台球桌信息卡片 */} {/* 顶部:店名和电话 */} 北京黑八大师联盟球厅店 联系店长 {/* 台球桌标题 */} [中式台球]来力.山岩-A03/3号球桌 {/* 价格信息 */} ¥28.80 /小时 押金 ¥100.00 VIP ¥20.00 {/* 价格时段 */} 价格时段:00:00-24:00 {/* 使用说明 */} 打开美团、抖音、大众点评或快手等 长按复制券码贴到对方输入框 点击[兑换],成功兑换团购券 注:也可以通过扫团购券码完成兑换 {/* 券码输入框 */} setCouponCode(e.detail.value)} /> {/* 券类型选项卡 */} handleSwitchType(CouponType.THIRD_PARTY)} > 第三方卡券 {selectedCouponType === CouponType.THIRD_PARTY && } handleSwitchType(CouponType.ACTIVITY)} > 活动卡券 {selectedCouponType === CouponType.ACTIVITY && } 共{coupons.length}张 {/* 券列表 */} {coupons.map((coupon) => ( {/* 左上角标签 */} {coupon.type} handleSelectCoupon(coupon.id)}> {/* 左侧:时长和券类型 */} {coupon.duration} 分钟 {coupon.couponType} {/* 右侧:信息区域 */} {/* 标题行:标题 + 选择按钮 */} {coupon.title} { e.stopPropagation() handleSelectCoupon(coupon.id) }} > {selectedCouponId === coupon.id && } {/* 有效期 */} 有效日期至:{coupon.expireDate} {/* 描述 */} {coupon.description && {coupon.description}} {/* 详情区域 */} {/* 第一条详情 + 展开/收起按钮 */} {coupon.details.length > 0 && ( {coupon.details[0]} handleToggleExpand(coupon.id)} > {coupon.expanded ? '∧' : '∨'} )} {/* 展开时显示其余详情 */} {coupon.expanded && coupon.details.slice(1).map((detail, index) => ( {detail} ))} ))} {/* 底部提示 */} 到底了~ {/* 底部固定按钮 */} 兑换开台 ) } export default CouponStart