import React, { useState, useEffect } from 'react' import { View, Text, ScrollView } from '@tarojs/components' import Taro, { useRouter } from '@tarojs/taro' import { getShopBooking, cancelShopBooking } from '@/api/shop/shopBooking' import type { ShopBooking, BookingStatus } from '@/api/shop/shopBooking/model' definePageConfig({ navigationBarTitleText: '预约详情', }) const BookingDetailPage: React.FC = () => { const router = useRouter() const [order, setOrder] = useState(null) const [loading, setLoading] = useState(true) const [cancelling, setCancelling] = useState(false) // 获取预约详情 const loadBookingDetail = async () => { const id = router.params.id if (!id) { Taro.showToast({ title: '参数错误', icon: 'none' }) setLoading(false) return } try { const data = await getShopBooking(id) setOrder(data) } catch (e: any) { console.error('获取预约详情失败:', e) Taro.showToast({ title: e.message || '获取详情失败', icon: 'none' }) } finally { setLoading(false) } } useEffect(() => { loadBookingDetail() }, []) // 获取状态标签 const getStatusInfo = (status: BookingStatus | undefined) => { const map: Record = { 'pending': { label: '待服务', color: 'text-orange-500', bg: 'bg-orange-50' }, 'confirmed': { label: '已确认', color: 'text-blue-500', bg: 'bg-blue-50' }, 'in_progress': { label: '进行中', color: 'text-blue-500', bg: 'bg-blue-50' }, 'completed': { label: '已完成', color: 'text-green-500', bg: 'bg-green-50' }, 'cancelled': { label: '已取消', color: 'text-gray-400', bg: 'bg-gray-100' }, 'rescheduled': { label: '已改签', color: 'text-purple-500', bg: 'bg-purple-50' }, } return map[status as BookingStatus] || { label: '未知', color: 'text-gray-400', bg: 'bg-gray-100' } } // 取消预约 const handleCancel = () => { if (!order?.id) return Taro.showModal({ title: '确认取消', content: '确定取消该预约吗?\n\n取消后将无法恢复。', confirmColor: '#0e932e', success: async (res) => { if (res.confirm) { try { setCancelling(true) await cancelShopBooking(order.id) Taro.showToast({ title: '已取消', icon: 'success' }) // 重新加载详情 setTimeout(() => loadBookingDetail(), 1500) } catch (e: any) { console.error('取消预约失败:', e) Taro.showToast({ title: e.message || '取消失败', icon: 'none' }) } finally { setCancelling(false) } } } }) } // 改签预约 const handleReschedule = () => { if (order?.id) { Taro.navigateTo({ url: `/pages/booking/reschedule/index?id=${order.id}` }) } } // 返回列表 const handleBackToList = () => { Taro.navigateBack() } if (loading) { return ( 加载中... ) } if (!order) { return ( 暂无数据 返回列表 ) } const statusInfo = getStatusInfo(order.status) return ( {/* 状态卡片 */} 📅 {statusInfo.label} 预约编号:{order.bookingNo} {/* 预约信息 */} 预约信息 服务名称 {order.serviceName || '预约服务'} 预约日期 {order.bookingDate || '-'} 预约时段 {order.bookingTime || '-'} {order.price > 0 && ( 服务费用 ¥{order.price} )} 预约备注 {order.remark || '无'} {/* 联系人信息 */} {(order.contactName || order.contactPhone) && ( 联系人 {order.contactName && ( 姓名 {order.contactName} )} {order.contactPhone && ( 电话 Taro.makePhoneCall({ phoneNumber: order.contactPhone })} > {order.contactPhone} 📞 )} )} {/* 门店信息 */} 门店信息 🏪 {order.storeName || '门店'} {order.storePhone && ( 📞 Taro.makePhoneCall({ phoneNumber: order.storePhone })} > {order.storePhone} )} {order.address && ( 📍 {order.address} )} {/* 创建时间 */} {order.createTime && ( 预约时间:{order.createTime} )} {/* 操作按钮 - 仅待服务状态显示 */} {order.status === 'pending' && ( {cancelling ? '取消中...' : '取消预约'} 改签预约 )} ) } export default BookingDetailPage