| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- <template>
- <view class="container">
- <view class="header">
- <text class="title">我的预约</text>
- <text class="subtitle">查看测评预约状态</text>
- </view>
- <!-- 预约列表 -->
- <view class="appointment-list" v-if="appointments.length > 0">
- <view class="appointment-card" v-for="item in appointments" :key="item.id">
- <view class="card-header">
- <text class="appointment-id">#{{ item.id }}</text>
- <view class="status-badge" :class="'status-' + item.status">
- <text>{{ item.statusText || getStatusText(item.status) }}</text>
- </view>
- </view>
- <view class="card-body">
- <view class="info-row">
- <text class="label">预约日期</text>
- <text class="value">{{ item.appointmentDate || '待确认' }}</text>
- </view>
- <view class="info-row">
- <text class="label">预约时间</text>
- <text class="value">{{ item.appointmentTime || '待确认' }}</text>
- </view>
- <view class="info-row" v-if="item.notes">
- <text class="label">备注</text>
- <text class="value">{{ item.notes }}</text>
- </view>
- <view class="info-row">
- <text class="label">创建时间</text>
- <text class="value">{{ formatTime(item.createdAt) }}</text>
- </view>
- </view>
- <view class="card-footer" v-if="item.status === 0">
- <button class="btn-cancel" size="mini" @click="handleCancel(item.id)">取消预约</button>
- </view>
- <view class="card-footer" v-if="item.status === 2">
- <button class="btn-view-report" size="mini" @click="viewReport(item.id)">查看报告</button>
- </view>
- </view>
- </view>
- <view class="empty-state" v-else>
- <text class="empty-icon">📋</text>
- <text class="empty-text">暂无预约记录</text>
- <text class="empty-hint">申请测评后此处会显示预约状态</text>
- </view>
- </view>
- </template>
- <script>
- import { getMyAppointments, cancelAppointment } from '../../utils/api.js'
- export default {
- data() {
- return {
- appointments: []
- }
- },
- onShow() {
- this.loadAppointments()
- },
- methods: {
- async loadAppointments() {
- try {
- const res = await getMyAppointments()
- if (res.code === 200) {
- this.appointments = res.data || []
- }
- } catch (e) {
- console.error('加载预约列表失败', e)
- }
- },
- getStatusText(status) {
- const map = { 0: '待确认', 1: '已确认', 2: '已完成', 3: '已取消', 4: '未到' }
- return map[status] || '未知'
- },
- formatTime(ts) {
- if (!ts) return ''
- const d = new Date(ts)
- return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')} ${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`
- },
- handleCancel(id) {
- uni.showModal({
- title: '取消预约',
- content: '确定取消此预约?',
- success: async (res) => {
- if (res.confirm) {
- try {
- const result = await cancelAppointment(id)
- if (result.code === 200) {
- uni.showToast({ title: '已取消', icon: 'success' })
- this.loadAppointments()
- }
- } catch (e) {
- uni.showToast({ title: '操作失败', icon: 'none' })
- }
- }
- }
- })
- },
- viewReport(appointmentId) {
- uni.navigateTo({ url: '/pages/assessment/results' })
- }
- }
- }
- </script>
- <style scoped>
- .container {
- padding: 30rpx;
- background: #F8F8F8;
- min-height: 100vh;
- }
- .header {
- text-align: center;
- padding: 40rpx 0 30rpx;
- }
- .title {
- font-size: 48rpx;
- font-weight: bold;
- color: #333;
- display: block;
- margin-bottom: 16rpx;
- }
- .subtitle {
- font-size: 26rpx;
- color: #666;
- }
- .appointment-list {
- display: flex;
- flex-direction: column;
- gap: 24rpx;
- }
- .appointment-card {
- background: #fff;
- border-radius: 20rpx;
- padding: 30rpx;
- }
- .card-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 20rpx;
- padding-bottom: 16rpx;
- border-bottom: 1rpx solid #eee;
- }
- .appointment-id {
- font-size: 24rpx;
- color: #999;
- }
- .status-badge {
- padding: 6rpx 16rpx;
- border-radius: 8rpx;
- font-size: 22rpx;
- }
- .status-0 { background: #FFF3E0; color: #FF9800; }
- .status-1 { background: #E3F2FD; color: #2196F3; }
- .status-2 { background: #E8F5E9; color: #4CAF50; }
- .status-3 { background: #F5F5F5; color: #9E9E9E; }
- .status-4 { background: #FFEBEE; color: #F44336; }
- .card-body {
- margin-bottom: 20rpx;
- }
- .info-row {
- display: flex;
- justify-content: space-between;
- padding: 10rpx 0;
- font-size: 26rpx;
- }
- .label { color: #999; }
- .value { color: #333; }
- .card-footer {
- padding-top: 16rpx;
- border-top: 1rpx dashed #eee;
- display: flex;
- justify-content: flex-end;
- }
- .btn-cancel {
- background: #F5F5F5;
- color: #999;
- font-size: 26rpx;
- border-radius: 10rpx;
- width: 200rpx;
- }
- .btn-view-report {
- background: #667eea;
- color: #fff;
- font-size: 26rpx;
- border-radius: 10rpx;
- width: 200rpx;
- }
- .empty-state {
- text-align: center;
- padding: 120rpx 0;
- }
- .empty-icon {
- font-size: 80rpx;
- display: block;
- margin-bottom: 20rpx;
- }
- .empty-text {
- font-size: 28rpx;
- color: #999;
- display: block;
- margin-bottom: 10rpx;
- }
- .empty-hint {
- font-size: 24rpx;
- color: #CCC;
- display: block;
- }
- </style>
|