/** * 卡券使用页面 */ import { View, Text, Input } from '@tarojs/components' import Taro, { useLoad, useRouter } from '@tarojs/taro' import { useState } from 'react' import { Popup, Button } from '@taroify/core' import { Arrow, Search as SearchIcon } from '@taroify/icons' import './index.scss' // 门店数据接口 interface Store { id: number name: string address: string distance: string } // 城市选项 const cityOptions = [ { title: '选城市', value: 'all' }, { title: '北京', value: 'beijing' }, { title: '上海', value: 'shanghai' }, { title: '广州', value: 'guangzhou' }, { title: '深圳', value: 'shenzhen' }, ] const CouponUse = () => { const router = useRouter() const { couponId } = router.params // 卡券信息(从路由参数或上一页面传递,实际应根据couponId获取) const [couponInfo] = useState({ title: '豪华自助台球厅20分钟通用券(体验券)', duration: '20', validPeriod: '2025.10.01 - 2025.10.07(有效7天)', useMethod: '自动抵扣,单次使用', partialUsable: true, // 部分门店不可用 }) // 城市选择 const [selectedCity, setSelectedCity] = useState('all') const [showCityPicker, setShowCityPicker] = useState(false) // 搜索关键词 const [searchValue, setSearchValue] = useState('') // 已选门店 const [selectedStoreId, setSelectedStoreId] = useState(1) // 门店列表(模拟数据) const [storeList] = useState([ { id: 1, name: '北京黑八大师联盟球厅店', address: '北京市XXX区XXX街道XXXXXXXXXXXXXXXXXXXXXXX路19号606', distance: '0.05km' }, { id: 2, name: '北京晶彩桌球世界店', address: '北京市XXX区XXX街道XXX路19号606', distance: '0.1km' }, { id: 3, name: '北京球坛风云店', address: '北京市XXX区XXXXXXXXXXX街道XXX路19号606', distance: '0.2km' }, ]) useLoad(() => { console.log('卡券使用页面加载') Taro.setNavigationBarTitle({ title: '' }) }) // 获取已选门店名称 const getSelectedStoreName = () => { const store = storeList.find(s => s.id === selectedStoreId) return store ? store.name : '' } // 选择门店 const handleSelectStore = (storeId: number) => { setSelectedStoreId(storeId) } // 搜索 const handleSearch = () => { console.log('搜索', searchValue) Taro.showToast({ title: `搜索: ${searchValue}`, icon: 'none' }) } // 获取当前城市名称 const getCityName = () => { const city = cityOptions.find(c => c.value === selectedCity) return city ? city.title : '选城市' } // 选择城市 const handleSelectCity = (value: string) => { setSelectedCity(value) setShowCityPicker(false) } // 去使用 const handleUse = () => { if (!selectedStoreId) { Taro.showToast({ title: '请选择门店', icon: 'none' }) return } console.log('使用卡券', selectedStoreId) Taro.showToast({ title: '卡券使用成功', icon: 'success' }) } return ( {/* 卡券信息区域 */} {couponInfo.title} 有效期限:{couponInfo.validPeriod} 使用方法:{couponInfo.useMethod} {couponInfo.duration} 分钟
{/* 选择门店区域 */} 选择门店 {couponInfo.partialUsable && ( (部分门店不可用) )} 已选门店:{getSelectedStoreName()} {/* 搜索栏 */} setShowCityPicker(true)}> {getCityName()} setSearchValue(e.detail.value)} onConfirm={handleSearch} /> {/* 城市选择弹窗 */} setShowCityPicker(false)} > 选择城市 {cityOptions.map((city) => ( handleSelectCity(city.value)} > {city.title} {selectedCity === city.value && } ))} {/* 门店列表 */} {storeList.map((store) => ( handleSelectStore(store.id)} > {store.name} {store.address} 距离{store.distance} ))} {/* 到底提示 */} 到底了~ {/* 页脚按钮 */}
) } export default CouponUse