import React, { useState, useEffect } from 'react' import { View, Text, ScrollView } from '@tarojs/components' import Taro, { useRouter } from '@tarojs/taro' import { Button } from '@nutui/nutui-react-taro' import { getShopBooking, rescheduleShopBooking } from '@/api/shop/shopBooking' import type { ShopBooking } from '@/api/shop/shopBooking/model' import dayjs from 'dayjs' definePageConfig({ navigationBarTitleText: '改签预约', }) const BookingReschedulePage: React.FC = () => { const router = useRouter() const bookingId = router.params.id const [originalBooking, setOriginalBooking] = useState(null) const [loading, setLoading] = useState(true) const [submitting, setSubmitting] = useState(false) const [newDate, setNewDate] = useState('') const [newTime, setNewTime] = useState('') const getDateRange = () => { const dates: { value: string; label: string }[] = [] const today = dayjs() for (let i = 1; i <= 14; i++) { const d = today.add(i, 'day') const weekDays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'] dates.push({ value: d.format('YYYY-MM-DD'), label: `${d.month() + 1}月${d.date()}日 ${weekDays[d.day()]}`, }) } return dates } const dateRange = getDateRange() const timeSlots = [ { label: '09:00-10:00', value: '09:00-10:00' }, { label: '10:00-11:00', value: '10:00-11:00' }, { label: '11:00-12:00', value: '11:00-12:00' }, { label: '14:00-15:00', value: '14:00-15:00' }, { label: '15:00-16:00', value: '15:00-16:00' }, { label: '16:00-17:00', value: '16:00-17:00' }, { label: '17:00-18:00', value: '17:00-18:00' }, ] useEffect(() => { if (!bookingId) { Taro.showToast({ title: '参数错误', icon: 'none' }) setLoading(false) return } fetchBookingDetail() }, [bookingId]) const fetchBookingDetail = async () => { try { const data = await getShopBooking(bookingId) setOriginalBooking(data) } catch (e: any) { console.error('获取预约详情失败:', e) Taro.showToast({ title: e.message || '获取详情失败', icon: 'none' }) } finally { setLoading(false) } } const handleSubmit = () => { if (!newDate) { Taro.showToast({ title: '请选择新日期', icon: 'none' }) return } if (!newTime) { Taro.showToast({ title: '请选择新时段', icon: 'none' }) return } const oldDate = originalBooking?.bookingDate || '-' const oldTime = originalBooking?.bookingTime || '-' const confirmContent = `确定将预约从\n${oldDate} ${oldTime}\n改签至\n${newDate} ${newTime}吗?` Taro.showModal({ title: '确认改签', content: confirmContent, confirmText: '确认改签', confirmColor: '#0e932e', success: async (res) => { if (res.confirm) { await submitReschedule() } } }) } const submitReschedule = async () => { try { setSubmitting(true) await rescheduleShopBooking({ bookingId: bookingId, newDate: newDate, newTime: newTime, }) Taro.showToast({ title: '改签成功', icon: 'success' }) setTimeout(() => { Taro.navigateBack() }, 1500) } catch (e: any) { console.error('改签失败:', e) Taro.showToast({ title: e.message || '改签失败', icon: 'none' }) } finally { setSubmitting(false) } } if (loading) { return ( 加载中... ) } if (!originalBooking) { return ( 预约信息不存在 ) } return ( 原预约信息 预约编号 {originalBooking.id} 服务类型 {originalBooking.serviceName} 预约日期 {originalBooking.bookingDate} 预约时段 {originalBooking.bookingTime} 选择新日期 {dateRange.map(date => ( setNewDate(date.value)} > {date.label} ))} 选择新时段 {timeSlots.map(slot => ( setNewTime(slot.value)} > {slot.label} ))} 改签说明 1. 每个订单只能改签一次,请谨慎选择 2. 改签需提前2小时申请 3. 改签不收取任何手续费 4. 如有疑问,请联系客服咨询 ) } export default BookingReschedulePage