|
|
@@ -0,0 +1,1006 @@
|
|
|
+<template>
|
|
|
+ <view class="page-container">
|
|
|
+ <!-- 主要内容区域 -->
|
|
|
+ <scroll-view class="main-content" scroll-y enhanced>
|
|
|
+ <!-- 顶部星期卡片区域 -->
|
|
|
+ <view class="week-cards-container">
|
|
|
+ <!-- 我的预约按钮卡片(固定) -->
|
|
|
+ <view class="my-appointments-card" @click="goToMyAppointments">
|
|
|
+ <view class="card-text-container">
|
|
|
+ <text class="card-text-line">我的</text>
|
|
|
+ <text class="card-text-line">预约</text>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+
|
|
|
+ <!-- 星期卡片横向滑动区域 -->
|
|
|
+ <scroll-view
|
|
|
+ class="week-scroll-container"
|
|
|
+ scroll-x
|
|
|
+ >
|
|
|
+ <view class="week-cards-wrapper">
|
|
|
+ <view
|
|
|
+ v-for="(day, index) in weekDates"
|
|
|
+ :key="day.date"
|
|
|
+ class="week-card"
|
|
|
+ :class="{ active: selectedDate === day.date, today: day.isToday }"
|
|
|
+ @click="selectDate(day.date, index)"
|
|
|
+ >
|
|
|
+ <text class="day-name">{{ day.dayName }}</text>
|
|
|
+ <text v-if="!day.isToday" class="day-number">{{ day.dayNumber }}</text>
|
|
|
+ <text v-if="day.isToday" class="today-label">今天</text>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </scroll-view>
|
|
|
+ </view>
|
|
|
+
|
|
|
+ <!-- 时间段选择区域 -->
|
|
|
+ <view class="time-slots-section">
|
|
|
+ <!-- 加载状态 -->
|
|
|
+ <view v-if="loadingTimeSlots" class="loading-container">
|
|
|
+ <u-loading-icon mode="circle"></u-loading-icon>
|
|
|
+ <text class="loading-text">加载详细时段中...</text>
|
|
|
+ </view>
|
|
|
+
|
|
|
+ <!-- 分组时间段列表 -->
|
|
|
+ <view v-else-if="timeSlots.length > 0" class="grouped-time-slots">
|
|
|
+ <!-- 上午时段组 -->
|
|
|
+ <view v-if="groupedTimeSlots.morning.length > 0" class="time-group">
|
|
|
+ <view class="group-header">
|
|
|
+ <text class="group-title">上午时段</text>
|
|
|
+ </view>
|
|
|
+ <view class="slots-grid">
|
|
|
+ <view
|
|
|
+ v-for="slot in groupedTimeSlots.morning"
|
|
|
+ :key="slot.id"
|
|
|
+ class="detail-slot-card"
|
|
|
+ :class="{ disabled: !slot.available }"
|
|
|
+ @click="handleTimeSlotClick(slot)"
|
|
|
+ >
|
|
|
+ <view class="slot-time">{{ slot.timeRange }}</view>
|
|
|
+ <view class="slot-counselor">{{ slot.counselorName }}</view>
|
|
|
+ <view class="slot-status-tag">
|
|
|
+ <u-tag
|
|
|
+ :text="getSlotStatusText(slot)"
|
|
|
+ :type="getSlotStatusType(slot)"
|
|
|
+ size="mini"
|
|
|
+ ></u-tag>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+
|
|
|
+ <!-- 下午时段组 -->
|
|
|
+ <view v-if="groupedTimeSlots.afternoon.length > 0" class="time-group">
|
|
|
+ <view class="group-header">
|
|
|
+ <text class="group-title">下午时段</text>
|
|
|
+ </view>
|
|
|
+ <view class="slots-grid">
|
|
|
+ <view
|
|
|
+ v-for="slot in groupedTimeSlots.afternoon"
|
|
|
+ :key="slot.id"
|
|
|
+ class="detail-slot-card"
|
|
|
+ :class="{ disabled: !slot.available }"
|
|
|
+ @click="handleTimeSlotClick(slot)"
|
|
|
+ >
|
|
|
+ <view class="slot-time">{{ slot.timeRange }}</view>
|
|
|
+ <view class="slot-counselor">{{ slot.counselorName }}</view>
|
|
|
+ <view class="slot-status-tag">
|
|
|
+ <u-tag
|
|
|
+ :text="getSlotStatusText(slot)"
|
|
|
+ :type="getSlotStatusType(slot)"
|
|
|
+ size="mini"
|
|
|
+ ></u-tag>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+
|
|
|
+ <!-- 无数据状态 -->
|
|
|
+ <view v-else class="empty-container">
|
|
|
+ <u-empty
|
|
|
+ mode="data"
|
|
|
+ text="当天暂无可预约时段"
|
|
|
+ textColor="#909399"
|
|
|
+ iconColor="#c8c9cc"
|
|
|
+ ></u-empty>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </scroll-view>
|
|
|
+
|
|
|
+ <!-- 预约确认弹窗 -->
|
|
|
+ <u-modal
|
|
|
+ :show="showBookingModal"
|
|
|
+ title="确认预约"
|
|
|
+ confirm-text="确认预约"
|
|
|
+ cancel-text="取消"
|
|
|
+ show-cancel-button
|
|
|
+ closeable
|
|
|
+ @confirm="confirmBooking"
|
|
|
+ @cancel="cancelBooking"
|
|
|
+ @close="cancelBooking"
|
|
|
+ >
|
|
|
+ <view class="booking-modal-content">
|
|
|
+ <view class="booking-detail-item">
|
|
|
+ <text class="detail-label">预约日期:</text>
|
|
|
+ <text class="detail-value">{{ selectedBookingSlot && selectedBookingSlot.dateText }}</text>
|
|
|
+ </view>
|
|
|
+ <view class="booking-detail-item">
|
|
|
+ <text class="detail-label">预约时间:</text>
|
|
|
+ <text class="detail-value">{{ selectedBookingSlot && selectedBookingSlot.timeRange }}</text>
|
|
|
+ </view>
|
|
|
+ <view class="booking-detail-item">
|
|
|
+ <text class="detail-label">咨询师:</text>
|
|
|
+ <text class="detail-value">{{ selectedBookingSlot && selectedBookingSlot.counselorName }}</text>
|
|
|
+ </view>
|
|
|
+
|
|
|
+ <!-- 咨询原因输入框 -->
|
|
|
+ <view class="booking-detail-item reason-item">
|
|
|
+ <text class="detail-label required">咨询原因:</text>
|
|
|
+ </view>
|
|
|
+ <view class="reason-input-container">
|
|
|
+ <u-textarea
|
|
|
+ v-model="consultationReason"
|
|
|
+ placeholder="请简单描述您的咨询需求或困扰..."
|
|
|
+ :maxlength="200"
|
|
|
+ count
|
|
|
+ height="120"
|
|
|
+ :custom-style="{ fontSize: '28rpx', border: '1px solid #d0d7de', borderRadius: '6px' }"
|
|
|
+ ></u-textarea>
|
|
|
+ </view>
|
|
|
+
|
|
|
+ <view class="booking-note">
|
|
|
+ <text class="note-text">请填写具体的咨询原因,提交后等待审核</text>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </u-modal>
|
|
|
+ </view>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import { getAvailableTimeSlots, getAvailableDetailSlots, submitAppointment } from '@/api/xljk'
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: 'XljkReservation',
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ // 日期相关
|
|
|
+ weekDates: [],
|
|
|
+ selectedDate: '',
|
|
|
+ selectedDateText: '',
|
|
|
+ scrollLeft: 0,
|
|
|
+
|
|
|
+ // 时间段相关
|
|
|
+ timeSlots: [],
|
|
|
+ groupedTimeSlots: {
|
|
|
+ morning: [],
|
|
|
+ afternoon: []
|
|
|
+ },
|
|
|
+ loadingTimeSlots: false,
|
|
|
+
|
|
|
+ // 预约相关
|
|
|
+ showBookingModal: false,
|
|
|
+ selectedBookingSlot: null,
|
|
|
+ bookingLoading: false,
|
|
|
+ consultationReason: ''
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onLoad() {
|
|
|
+ try {
|
|
|
+ console.log('🔍 [预约页面] 开始初始化')
|
|
|
+ this.initWeekDates()
|
|
|
+ this.selectTodayAsDefault()
|
|
|
+ console.log('🔍 [预约页面] 初始化完成')
|
|
|
+ } catch (error) {
|
|
|
+ console.error('🔍 [预约页面] 初始化失败:', error)
|
|
|
+ uni.showToast({
|
|
|
+ title: '页面初始化失败',
|
|
|
+ icon: 'error'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ // 获取时段状态文本
|
|
|
+ getSlotStatusText(slot) {
|
|
|
+ if (slot.available) {
|
|
|
+ return '可预约'
|
|
|
+ } else if (slot.isBooked) {
|
|
|
+ return '已约满'
|
|
|
+ } else if (slot.isExpired) {
|
|
|
+ return '已过期'
|
|
|
+ }
|
|
|
+ return '不可约'
|
|
|
+ },
|
|
|
+
|
|
|
+ // 获取时段状态类型
|
|
|
+ getSlotStatusType(slot) {
|
|
|
+ if (slot.available) {
|
|
|
+ return 'success'
|
|
|
+ } else if (slot.isBooked) {
|
|
|
+ return 'error'
|
|
|
+ } else if (slot.isExpired) {
|
|
|
+ return 'warning'
|
|
|
+ }
|
|
|
+ return 'info'
|
|
|
+ },
|
|
|
+
|
|
|
+ // 初始化一周日期数据
|
|
|
+ initWeekDates() {
|
|
|
+ const today = new Date()
|
|
|
+ const weekDates = []
|
|
|
+
|
|
|
+ // 获取本周的7天
|
|
|
+ for (let i = 0; i < 7; i++) {
|
|
|
+ const date = new Date(today)
|
|
|
+ date.setDate(today.getDate() + i)
|
|
|
+
|
|
|
+ const dateStr = this.formatDate(date)
|
|
|
+ const dayNames = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
|
|
|
+
|
|
|
+ weekDates.push({
|
|
|
+ date: dateStr,
|
|
|
+ dayName: dayNames[date.getDay()],
|
|
|
+ dayNumber: date.getDate(),
|
|
|
+ isToday: dateStr === this.formatDate(today),
|
|
|
+ fullDate: date
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ this.weekDates = weekDates
|
|
|
+ },
|
|
|
+
|
|
|
+ // 选择今天作为默认日期
|
|
|
+ selectTodayAsDefault() {
|
|
|
+ const today = this.formatDate(new Date())
|
|
|
+ this.selectDate(today, 0)
|
|
|
+ },
|
|
|
+
|
|
|
+ // 选择日期
|
|
|
+ selectDate(date, index) {
|
|
|
+ this.selectedDate = date
|
|
|
+ this.selectedDateText = this.getDateText(date)
|
|
|
+ this.loadTimeSlots(date)
|
|
|
+ },
|
|
|
+
|
|
|
+ // 获取日期显示文本
|
|
|
+ getDateText(dateStr) {
|
|
|
+ const date = new Date(dateStr)
|
|
|
+ const today = new Date()
|
|
|
+
|
|
|
+ if (dateStr === this.formatDate(today)) {
|
|
|
+ return '今天'
|
|
|
+ }
|
|
|
+
|
|
|
+ const tomorrow = new Date(today)
|
|
|
+ tomorrow.setDate(today.getDate() + 1)
|
|
|
+ if (dateStr === this.formatDate(tomorrow)) {
|
|
|
+ return '明天'
|
|
|
+ }
|
|
|
+
|
|
|
+ const dayAfterTomorrow = new Date(today)
|
|
|
+ dayAfterTomorrow.setDate(today.getDate() + 2)
|
|
|
+ if (dateStr === this.formatDate(dayAfterTomorrow)) {
|
|
|
+ return '后天'
|
|
|
+ }
|
|
|
+
|
|
|
+ return `${date.getMonth() + 1}月${date.getDate()}日`
|
|
|
+ },
|
|
|
+
|
|
|
+ // 加载时间段数据 - 优化为加载详细时段
|
|
|
+ async loadTimeSlots(date) {
|
|
|
+ this.loadingTimeSlots = true
|
|
|
+ this.timeSlots = []
|
|
|
+ this.groupedTimeSlots = { morning: [], afternoon: [] }
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 1. 先获取大时段列表 - 增加参数验证
|
|
|
+ if (!date) {
|
|
|
+ throw new Error('日期参数无效')
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('🔍 开始获取大时段数据,日期:', date)
|
|
|
+ const bigSlotsResponse = await getAvailableTimeSlots(date, date)
|
|
|
+ console.log('🔍 大时段API返回:', bigSlotsResponse)
|
|
|
+
|
|
|
+ // 验证API响应结构
|
|
|
+ if (!bigSlotsResponse || typeof bigSlotsResponse !== 'object') {
|
|
|
+ throw new Error('API响应格式异常')
|
|
|
+ }
|
|
|
+
|
|
|
+ if (bigSlotsResponse.code === 200 && bigSlotsResponse.data && bigSlotsResponse.data.length > 0) {
|
|
|
+ // 2. 并行获取所有详细时段 - 增加数据安全性检查
|
|
|
+ const detailPromises = bigSlotsResponse.data
|
|
|
+ .filter(bigSlot => bigSlot && bigSlot.timeSlot) // 过滤无效数据
|
|
|
+ .map(bigSlot =>
|
|
|
+ getAvailableDetailSlots(date, bigSlot.timeSlot)
|
|
|
+ .then(response => ({
|
|
|
+ bigSlot,
|
|
|
+ detailSlots: response && response.data ? response.data : []
|
|
|
+ }))
|
|
|
+ .catch(error => {
|
|
|
+ console.error(`获取时段 ${bigSlot.timeSlot} 的详细数据失败:`, error)
|
|
|
+ return { bigSlot, detailSlots: [] }
|
|
|
+ })
|
|
|
+ )
|
|
|
+
|
|
|
+ const allDetailResults = await Promise.all(detailPromises)
|
|
|
+ console.log('🔍 详细时段API返回:', allDetailResults)
|
|
|
+
|
|
|
+ // 3. 扁平化并增强数据 - 增加数据安全性检查
|
|
|
+ const allDetailSlots = []
|
|
|
+ allDetailResults.forEach(({ bigSlot, detailSlots }) => {
|
|
|
+ // 确保 bigSlot 和 detailSlots 都是有效的
|
|
|
+ if (!bigSlot || !Array.isArray(detailSlots)) {
|
|
|
+ console.warn('无效的时段数据:', { bigSlot, detailSlots })
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ detailSlots.forEach(detail => {
|
|
|
+ // 确保必要的字段存在
|
|
|
+ if (!detail || !detail.timeSlot) {
|
|
|
+ console.warn('无效的详细时段数据:', detail)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ allDetailSlots.push({
|
|
|
+ id: `${bigSlot.scheduleId || 'unknown'}_${detail.timeSlot}`,
|
|
|
+ timeRange: detail.timeSlot,
|
|
|
+ available: !detail.isBooked && !detail.isExpired,
|
|
|
+ isBooked: Boolean(detail.isBooked),
|
|
|
+ isExpired: Boolean(detail.isExpired),
|
|
|
+ counselorName: bigSlot.counselorName || '未知咨询师',
|
|
|
+ counselorId: bigSlot.counselorId || null,
|
|
|
+ counselorAvatar: '',
|
|
|
+ dateText: this.selectedDateText || '',
|
|
|
+ originalData: {
|
|
|
+ ...detail,
|
|
|
+ parentScheduleId: bigSlot.scheduleId || null,
|
|
|
+ counselorId: bigSlot.counselorId || null,
|
|
|
+ timeSlot: bigSlot.timeSlot || null
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } catch (err) {
|
|
|
+ console.error('处理时段数据时出错:', err, { bigSlot, detail })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ // 4. 按时间排序 - 增加安全性检查
|
|
|
+ allDetailSlots.sort((a, b) => {
|
|
|
+ try {
|
|
|
+ // 安全地获取时间用于排序
|
|
|
+ const timeA = (a.timeRange && typeof a.timeRange === 'string') ? a.timeRange.split('-')[0] : '00:00'
|
|
|
+ const timeB = (b.timeRange && typeof b.timeRange === 'string') ? b.timeRange.split('-')[0] : '00:00'
|
|
|
+ return timeA.localeCompare(timeB)
|
|
|
+ } catch (err) {
|
|
|
+ console.error('时间排序出错:', err, { a, b })
|
|
|
+ return 0 // 如果排序出错,保持原顺序
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ // 5. 按上午下午分组
|
|
|
+ this.groupAndSetTimeSlots(allDetailSlots)
|
|
|
+
|
|
|
+ console.log('🔍 最终处理的详细时段数据:', {
|
|
|
+ total: allDetailSlots.length,
|
|
|
+ morning: this.groupedTimeSlots.morning.length,
|
|
|
+ afternoon: this.groupedTimeSlots.afternoon.length
|
|
|
+ })
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // 如果没有大时段数据
|
|
|
+ this.timeSlots = []
|
|
|
+ this.groupedTimeSlots = { morning: [], afternoon: [] }
|
|
|
+ // 移除Toast提示,避免在没有排班时显示不必要的消息
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('加载详细时段失败:', error)
|
|
|
+
|
|
|
+ // 网络错误时显示友好提示
|
|
|
+ uni.showToast({
|
|
|
+ title: '网络请求失败,请检查网络连接',
|
|
|
+ icon: 'error',
|
|
|
+ duration: 3000
|
|
|
+ })
|
|
|
+
|
|
|
+ // 保持空数组状态
|
|
|
+ this.timeSlots = []
|
|
|
+ this.groupedTimeSlots = { morning: [], afternoon: [] }
|
|
|
+ } finally {
|
|
|
+ this.loadingTimeSlots = false
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 按上午下午分组时段 - 增加安全性检查
|
|
|
+ groupAndSetTimeSlots(detailSlots) {
|
|
|
+ try {
|
|
|
+ // 确保输入是有效数组
|
|
|
+ if (!Array.isArray(detailSlots)) {
|
|
|
+ console.warn('groupAndSetTimeSlots 接收到无效数据:', detailSlots)
|
|
|
+ this.groupedTimeSlots = { morning: [], afternoon: [] }
|
|
|
+ this.timeSlots = []
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 按上午下午分组 - 增加安全性检查
|
|
|
+ const morningSlots = detailSlots.filter(slot => {
|
|
|
+ try {
|
|
|
+ if (!slot || !slot.timeRange || typeof slot.timeRange !== 'string') {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ const timeParts = slot.timeRange.split(':')
|
|
|
+ if (timeParts.length === 0) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ const hour = parseInt(timeParts[0])
|
|
|
+ return !isNaN(hour) && hour < 12
|
|
|
+ } catch (err) {
|
|
|
+ console.warn('处理上午时段时出错:', err, slot)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ const afternoonSlots = detailSlots.filter(slot => {
|
|
|
+ try {
|
|
|
+ if (!slot || !slot.timeRange || typeof slot.timeRange !== 'string') {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ const timeParts = slot.timeRange.split(':')
|
|
|
+ if (timeParts.length === 0) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ const hour = parseInt(timeParts[0])
|
|
|
+ return !isNaN(hour) && hour >= 12
|
|
|
+ } catch (err) {
|
|
|
+ console.warn('处理下午时段时出错:', err, slot)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ this.groupedTimeSlots = {
|
|
|
+ morning: morningSlots,
|
|
|
+ afternoon: afternoonSlots
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保持原有的timeSlots格式兼容现有代码
|
|
|
+ this.timeSlots = [...morningSlots, ...afternoonSlots]
|
|
|
+
|
|
|
+ } catch (error) {
|
|
|
+ console.error('分组时段时出错:', error)
|
|
|
+ // 发生错误时设置为空数组
|
|
|
+ this.groupedTimeSlots = { morning: [], afternoon: [] }
|
|
|
+ this.timeSlots = []
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 刷新时间段
|
|
|
+ refreshTimeSlots() {
|
|
|
+ this.loadTimeSlots(this.selectedDate)
|
|
|
+ },
|
|
|
+
|
|
|
+ // 处理时间段点击
|
|
|
+ handleTimeSlotClick(slot) {
|
|
|
+ console.log('🔍 点击时间段:', slot)
|
|
|
+ console.log('🔍 slot.available:', slot.available)
|
|
|
+
|
|
|
+ if (!slot.available) {
|
|
|
+ let title = '该时段不可预约'
|
|
|
+ if (slot.isBooked) {
|
|
|
+ title = '该时段已约满'
|
|
|
+ } else if (slot.isExpired) {
|
|
|
+ title = '该时段已过期'
|
|
|
+ }
|
|
|
+
|
|
|
+ uni.showToast({
|
|
|
+ title: title,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ this.selectedBookingSlot = slot
|
|
|
+ this.showBookingModal = true
|
|
|
+ console.log('🔍 设置弹窗显示状态:', this.showBookingModal)
|
|
|
+ console.log('🔍 选中的预约时段数据:', this.selectedBookingSlot)
|
|
|
+ },
|
|
|
+
|
|
|
+ // 确认预约
|
|
|
+ async confirmBooking() {
|
|
|
+ if (this.bookingLoading) return
|
|
|
+
|
|
|
+ // 验证咨询原因
|
|
|
+ if (!this.consultationReason || this.consultationReason.trim() === '') {
|
|
|
+ uni.showToast({
|
|
|
+ title: '请填写咨询原因',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.consultationReason.trim().length < 5) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '咨询原因至少需要5个字符',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ this.bookingLoading = true
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 正确获取用户信息 - 使用专门的获取方法,增加错误处理
|
|
|
+ let userInfo = null
|
|
|
+ let studentId = null
|
|
|
+
|
|
|
+ try {
|
|
|
+ const { userStorage } = await import('@/common/storage')
|
|
|
+ userInfo = userStorage.getUserInfo()
|
|
|
+ console.log('🔍 获取到的完整用户信息:', userInfo)
|
|
|
+
|
|
|
+ // 从正确的路径获取用户ID - 增加多层级安全检查
|
|
|
+ if (userInfo && typeof userInfo === 'object' && userInfo.user && typeof userInfo.user === 'object') {
|
|
|
+ studentId = userInfo.user.userId
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('🔍 解析到的学生ID:', studentId)
|
|
|
+ } catch (storageError) {
|
|
|
+ console.error('获取用户信息失败:', storageError)
|
|
|
+ throw new Error('获取用户信息失败,请重新登录')
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!studentId) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '请先登录',
|
|
|
+ icon: 'error'
|
|
|
+ })
|
|
|
+
|
|
|
+ // 跳转到登录页面
|
|
|
+ setTimeout(() => {
|
|
|
+ uni.reLaunch({
|
|
|
+ url: '/pages/login/index'
|
|
|
+ })
|
|
|
+ }, 1500)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构造预约数据
|
|
|
+ const appointmentData = {
|
|
|
+ studentId: studentId,
|
|
|
+ scheduleId: this.selectedBookingSlot.originalData.parentScheduleId,
|
|
|
+ counselorId: this.selectedBookingSlot.originalData.counselorId,
|
|
|
+ appointmentDate: this.selectedDate,
|
|
|
+ appointmentTime: this.selectedBookingSlot.originalData.timeSlot,
|
|
|
+ appointmentDetailTime: this.selectedBookingSlot.timeRange,
|
|
|
+ reason: this.consultationReason.trim() // 使用用户输入的咨询原因
|
|
|
+ }
|
|
|
+
|
|
|
+ // 调用真实API提交预约
|
|
|
+ const response = await submitAppointment(appointmentData)
|
|
|
+
|
|
|
+ if (response.code === 200) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '预约成功',
|
|
|
+ icon: 'success'
|
|
|
+ })
|
|
|
+
|
|
|
+ this.showBookingModal = false
|
|
|
+ this.selectedBookingSlot = null
|
|
|
+ this.consultationReason = '' // 重置咨询原因
|
|
|
+
|
|
|
+ // 刷新时间段数据
|
|
|
+ this.refreshTimeSlots()
|
|
|
+ } else {
|
|
|
+ // API返回错误
|
|
|
+ uni.showToast({
|
|
|
+ title: response.msg || '预约失败',
|
|
|
+ icon: 'error',
|
|
|
+ duration: 3000
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (error) {
|
|
|
+ console.error('预约失败:', error)
|
|
|
+
|
|
|
+ // 处理不同类型的错误
|
|
|
+ let errorMessage = '预约失败'
|
|
|
+ if (error.message && error.message.includes('网络')) {
|
|
|
+ errorMessage = '网络请求失败,请检查网络连接'
|
|
|
+ } else if (error.response && error.response.data && error.response.data.msg) {
|
|
|
+ errorMessage = error.response.data.msg
|
|
|
+ }
|
|
|
+
|
|
|
+ uni.showToast({
|
|
|
+ title: errorMessage,
|
|
|
+ icon: 'error',
|
|
|
+ duration: 3000
|
|
|
+ })
|
|
|
+ } finally {
|
|
|
+ this.bookingLoading = false
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 取消预约弹窗
|
|
|
+ cancelBooking() {
|
|
|
+ this.showBookingModal = false
|
|
|
+ this.selectedBookingSlot = null
|
|
|
+ this.consultationReason = '' // 重置咨询原因
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 跳转到我的预约页面
|
|
|
+ goToMyAppointments() {
|
|
|
+ uni.navigateTo({
|
|
|
+ url: '/pages/xljk/my-appointments/index'
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ // 格式化日期
|
|
|
+ formatDate(date) {
|
|
|
+ try {
|
|
|
+ if (!date || !(date instanceof Date)) {
|
|
|
+ console.error('formatDate 接收到无效日期:', date)
|
|
|
+ return new Date().toISOString().split('T')[0] // 返回今天的日期作为备用
|
|
|
+ }
|
|
|
+
|
|
|
+ const year = date.getFullYear()
|
|
|
+ const month = String(date.getMonth() + 1).padStart(2, '0')
|
|
|
+ const day = String(date.getDate()).padStart(2, '0')
|
|
|
+ return `${year}-${month}-${day}`
|
|
|
+ } catch (error) {
|
|
|
+ console.error('格式化日期时出错:', error, date)
|
|
|
+ return new Date().toISOString().split('T')[0] // 返回今天的日期作为备用
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 通用错误处理方法
|
|
|
+ handleError(error, context = '') {
|
|
|
+ console.error(`[预约页面${context}] 错误:`, error)
|
|
|
+
|
|
|
+ // 根据错误类型显示不同的提示
|
|
|
+ let message = '操作失败,请稍后重试'
|
|
|
+
|
|
|
+ if (error && error.message) {
|
|
|
+ if (error.message.includes('网络')) {
|
|
|
+ message = '网络连接异常,请检查网络'
|
|
|
+ } else if (error.message.includes('登录') || error.message.includes('用户')) {
|
|
|
+ message = '请重新登录'
|
|
|
+ } else if (error.message.includes('参数')) {
|
|
|
+ message = '参数错误,请刷新页面重试'
|
|
|
+ } else {
|
|
|
+ message = error.message
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ uni.showToast({
|
|
|
+ title: message,
|
|
|
+ icon: 'none',
|
|
|
+ duration: 3000
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss" scoped>
|
|
|
+.page-container {
|
|
|
+ min-height: 100vh;
|
|
|
+ background-color: #f5f5f5;
|
|
|
+}
|
|
|
+
|
|
|
+.main-content {
|
|
|
+ height: 100vh;
|
|
|
+ padding: 30rpx 0 0;
|
|
|
+ width: 100%;
|
|
|
+ overflow-x: hidden;
|
|
|
+}
|
|
|
+
|
|
|
+.week-cards-container {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ margin-bottom: 40rpx;
|
|
|
+ height: 140rpx;
|
|
|
+ overflow: visible; /* 确保选中状态的放大效果不被裁剪 */
|
|
|
+ padding: 0 20rpx; /* 左右统一边距 */
|
|
|
+}
|
|
|
+
|
|
|
+.my-appointments-card {
|
|
|
+ width: 90rpx;
|
|
|
+ height: 120rpx;
|
|
|
+ background: #ffffff;
|
|
|
+ border-radius: 20rpx;
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ margin-right: 12rpx;
|
|
|
+ position: relative;
|
|
|
+ transition: all 0.3s ease;
|
|
|
+ box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
|
|
|
+ flex-shrink: 0; /* 防止在flex布局中被压缩 */
|
|
|
+
|
|
|
+ .card-text-container {
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ }
|
|
|
+
|
|
|
+ .card-text-line {
|
|
|
+ font-size: 22rpx;
|
|
|
+ color: #1890ff;
|
|
|
+ font-weight: 500;
|
|
|
+ line-height: 1.2;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+.week-scroll-container {
|
|
|
+ flex: 1;
|
|
|
+ height: 120rpx;
|
|
|
+ overflow-x: auto;
|
|
|
+ overflow-y: visible;
|
|
|
+}
|
|
|
+
|
|
|
+.week-cards-wrapper {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ height: 100%;
|
|
|
+ white-space: nowrap;
|
|
|
+ padding: 0 10rpx; /* 左右留出一些空间,防止选中状态被裁剪 */
|
|
|
+ width: 680rpx;
|
|
|
+}
|
|
|
+
|
|
|
+.week-card {
|
|
|
+ width: 90rpx;
|
|
|
+ height: 120rpx;
|
|
|
+ background: #ffffff;
|
|
|
+ border: 2rpx solid transparent;
|
|
|
+ border-radius: 20rpx !important;
|
|
|
+ box-sizing: border-box;
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ margin-right: 12rpx;
|
|
|
+ position: relative;
|
|
|
+ transition: all 0.3s ease;
|
|
|
+ box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
|
|
|
+ flex-shrink: 0; /* 防止在flex布局中被压缩 */
|
|
|
+
|
|
|
+ &:last-child {
|
|
|
+ margin-right: 0; /* 最后一个卡片不需要右边距 */
|
|
|
+ }
|
|
|
+
|
|
|
+ &.today:not(.active) {
|
|
|
+ border-color: #1890ff !important;
|
|
|
+ border-radius: 20rpx !important;
|
|
|
+ }
|
|
|
+
|
|
|
+ &.active {
|
|
|
+ background: #1890ff !important;
|
|
|
+ border-color: #1890ff !important;
|
|
|
+ border-radius: 20rpx !important;
|
|
|
+ transform: scale(1.05);
|
|
|
+ box-shadow: 0 4rpx 12rpx rgba(24, 144, 255, 0.3);
|
|
|
+ z-index: 10; /* 确保选中状态在最上层显示 */
|
|
|
+
|
|
|
+ .day-name,
|
|
|
+ .day-number,
|
|
|
+ .today-label {
|
|
|
+ color: white !important;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .day-name {
|
|
|
+ font-size: 22rpx;
|
|
|
+ color: #666;
|
|
|
+ margin-bottom: 6rpx;
|
|
|
+ }
|
|
|
+
|
|
|
+ .day-number {
|
|
|
+ font-size: 28rpx;
|
|
|
+ font-weight: 600;
|
|
|
+ color: #333;
|
|
|
+ }
|
|
|
+
|
|
|
+ .today-label {
|
|
|
+ font-size: 28rpx;
|
|
|
+ font-weight: 600;
|
|
|
+ color: #1890ff;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+.time-slots-section {
|
|
|
+ margin-bottom: 30rpx;
|
|
|
+}
|
|
|
+
|
|
|
+.loading-container,
|
|
|
+.empty-container {
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ padding: 80rpx 20rpx;
|
|
|
+
|
|
|
+ .loading-text {
|
|
|
+ font-size: 28rpx;
|
|
|
+ color: #999;
|
|
|
+ margin-top: 20rpx;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+.grouped-time-slots {
|
|
|
+ padding: 0 20rpx;
|
|
|
+
|
|
|
+ .time-group {
|
|
|
+ margin-bottom: 40rpx;
|
|
|
+
|
|
|
+ &:last-child {
|
|
|
+ margin-bottom: 20rpx;
|
|
|
+ }
|
|
|
+
|
|
|
+ .group-header {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ margin-bottom: 20rpx;
|
|
|
+ padding: 0 10rpx;
|
|
|
+
|
|
|
+ .group-title {
|
|
|
+ font-size: 32rpx;
|
|
|
+ font-weight: 600;
|
|
|
+ color: #333;
|
|
|
+ margin-right: 12rpx;
|
|
|
+ }
|
|
|
+
|
|
|
+ .group-count {
|
|
|
+ font-size: 24rpx;
|
|
|
+ color: #666;
|
|
|
+ background: rgba(24, 144, 255, 0.1);
|
|
|
+ padding: 4rpx 12rpx;
|
|
|
+ border-radius: 12rpx;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .slots-grid {
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ gap: 16rpx;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .detail-slot-card {
|
|
|
+ background: #ffffff;
|
|
|
+ border-radius: 16rpx;
|
|
|
+ padding: 30rpx;
|
|
|
+ transition: all 0.3s ease;
|
|
|
+ box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
|
|
|
+ border: 2rpx solid transparent;
|
|
|
+ position: relative;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: space-between;
|
|
|
+
|
|
|
+ &:not(.disabled):active {
|
|
|
+ transform: scale(0.96);
|
|
|
+ background: rgba(24, 144, 255, 0.05);
|
|
|
+ border-color: #1890ff;
|
|
|
+ }
|
|
|
+
|
|
|
+ &.disabled {
|
|
|
+ opacity: 0.6;
|
|
|
+ background: #f5f5f5;
|
|
|
+
|
|
|
+ .slot-time {
|
|
|
+ color: #999;
|
|
|
+ }
|
|
|
+
|
|
|
+ .slot-counselor {
|
|
|
+ color: #999;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .slot-time {
|
|
|
+ font-size: 32rpx;
|
|
|
+ font-weight: 600;
|
|
|
+ color: #333;
|
|
|
+ flex: 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ .slot-status-tag {
|
|
|
+ flex: 0 0 auto;
|
|
|
+ margin: 0 10rpx;
|
|
|
+ pointer-events: none; /* 允许点击事件穿透到父元素 */
|
|
|
+ }
|
|
|
+
|
|
|
+ .slot-counselor {
|
|
|
+ font-size: 28rpx;
|
|
|
+ color: #666;
|
|
|
+ flex: 1;
|
|
|
+ text-align: center;
|
|
|
+ overflow: hidden;
|
|
|
+ text-overflow: ellipsis;
|
|
|
+ white-space: nowrap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 可用状态的特殊样式 */
|
|
|
+ &:not(.disabled) {
|
|
|
+ &:hover {
|
|
|
+ transform: translateY(-2rpx);
|
|
|
+ box-shadow: 0 4rpx 16rpx rgba(24, 144, 255, 0.15);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 已满状态的特殊样式 */
|
|
|
+ &.disabled::before {
|
|
|
+ content: '';
|
|
|
+ position: absolute;
|
|
|
+ top: 0;
|
|
|
+ left: 0;
|
|
|
+ right: 0;
|
|
|
+ bottom: 0;
|
|
|
+ background: rgba(0, 0, 0, 0.05);
|
|
|
+ border-radius: 16rpx;
|
|
|
+ pointer-events: none;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+.booking-modal-content {
|
|
|
+ padding: 20rpx 0;
|
|
|
+
|
|
|
+ .booking-detail-item {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ margin-bottom: 24rpx;
|
|
|
+
|
|
|
+ .detail-label {
|
|
|
+ width: 160rpx;
|
|
|
+ font-size: 28rpx;
|
|
|
+ color: #666;
|
|
|
+
|
|
|
+ &.required::after {
|
|
|
+ content: '*';
|
|
|
+ color: #ff4757;
|
|
|
+ margin-left: 4rpx;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .detail-value {
|
|
|
+ flex: 1;
|
|
|
+ font-size: 28rpx;
|
|
|
+ color: #333;
|
|
|
+ font-weight: 500;
|
|
|
+ }
|
|
|
+
|
|
|
+ &.reason-item {
|
|
|
+ margin-bottom: 16rpx;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .reason-input-container {
|
|
|
+ margin-bottom: 24rpx;
|
|
|
+ padding: 0 4rpx;
|
|
|
+ border: 2rpx solid #e0e0e0;
|
|
|
+ border-radius: 12rpx;
|
|
|
+ background-color: #fafafa;
|
|
|
+ }
|
|
|
+
|
|
|
+ .booking-note {
|
|
|
+ background: rgba(255, 193, 7, 0.1);
|
|
|
+ border: 1rpx solid rgba(255, 193, 7, 0.3);
|
|
|
+ border-radius: 12rpx;
|
|
|
+ padding: 20rpx;
|
|
|
+ margin-top: 30rpx;
|
|
|
+
|
|
|
+ .note-text {
|
|
|
+ font-size: 26rpx;
|
|
|
+ color: #f57c00;
|
|
|
+ line-height: 1.4;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|