appointments.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <template>
  2. <view class="container">
  3. <view class="header">
  4. <text class="title">我的预约</text>
  5. <text class="subtitle">查看测评预约状态</text>
  6. </view>
  7. <!-- 预约列表 -->
  8. <view class="appointment-list" v-if="appointments.length > 0">
  9. <view class="appointment-card" v-for="item in appointments" :key="item.id">
  10. <view class="card-header">
  11. <text class="appointment-id">#{{ item.id }}</text>
  12. <view class="status-badge" :class="'status-' + item.status">
  13. <text>{{ item.statusText || getStatusText(item.status) }}</text>
  14. </view>
  15. </view>
  16. <view class="card-body">
  17. <view class="info-row">
  18. <text class="label">预约日期</text>
  19. <text class="value">{{ item.appointmentDate || '待确认' }}</text>
  20. </view>
  21. <view class="info-row">
  22. <text class="label">预约时间</text>
  23. <text class="value">{{ item.appointmentTime || '待确认' }}</text>
  24. </view>
  25. <view class="info-row" v-if="item.notes">
  26. <text class="label">备注</text>
  27. <text class="value">{{ item.notes }}</text>
  28. </view>
  29. <view class="info-row">
  30. <text class="label">创建时间</text>
  31. <text class="value">{{ formatTime(item.createdAt) }}</text>
  32. </view>
  33. </view>
  34. <view class="card-footer" v-if="item.status === 0">
  35. <button class="btn-cancel" size="mini" @click="handleCancel(item.id)">取消预约</button>
  36. </view>
  37. <view class="card-footer" v-if="item.status === 2">
  38. <button class="btn-view-report" size="mini" @click="viewReport(item.id)">查看报告</button>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="empty-state" v-else>
  43. <text class="empty-icon">📋</text>
  44. <text class="empty-text">暂无预约记录</text>
  45. <text class="empty-hint">申请测评后此处会显示预约状态</text>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import { getMyAppointments, cancelAppointment } from '../../utils/api.js'
  51. export default {
  52. data() {
  53. return {
  54. appointments: []
  55. }
  56. },
  57. onShow() {
  58. this.loadAppointments()
  59. },
  60. methods: {
  61. async loadAppointments() {
  62. try {
  63. const res = await getMyAppointments()
  64. if (res.code === 200) {
  65. this.appointments = res.data || []
  66. }
  67. } catch (e) {
  68. console.error('加载预约列表失败', e)
  69. }
  70. },
  71. getStatusText(status) {
  72. const map = { 0: '待确认', 1: '已确认', 2: '已完成', 3: '已取消', 4: '未到' }
  73. return map[status] || '未知'
  74. },
  75. formatTime(ts) {
  76. if (!ts) return ''
  77. const d = new Date(ts)
  78. 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')}`
  79. },
  80. handleCancel(id) {
  81. uni.showModal({
  82. title: '取消预约',
  83. content: '确定取消此预约?',
  84. success: async (res) => {
  85. if (res.confirm) {
  86. try {
  87. const result = await cancelAppointment(id)
  88. if (result.code === 200) {
  89. uni.showToast({ title: '已取消', icon: 'success' })
  90. this.loadAppointments()
  91. }
  92. } catch (e) {
  93. uni.showToast({ title: '操作失败', icon: 'none' })
  94. }
  95. }
  96. }
  97. })
  98. },
  99. viewReport(appointmentId) {
  100. uni.navigateTo({ url: '/pages/assessment/results' })
  101. }
  102. }
  103. }
  104. </script>
  105. <style scoped>
  106. .container {
  107. padding: 30rpx;
  108. background: #F8F8F8;
  109. min-height: 100vh;
  110. }
  111. .header {
  112. text-align: center;
  113. padding: 40rpx 0 30rpx;
  114. }
  115. .title {
  116. font-size: 48rpx;
  117. font-weight: bold;
  118. color: #333;
  119. display: block;
  120. margin-bottom: 16rpx;
  121. }
  122. .subtitle {
  123. font-size: 26rpx;
  124. color: #666;
  125. }
  126. .appointment-list {
  127. display: flex;
  128. flex-direction: column;
  129. gap: 24rpx;
  130. }
  131. .appointment-card {
  132. background: #fff;
  133. border-radius: 20rpx;
  134. padding: 30rpx;
  135. }
  136. .card-header {
  137. display: flex;
  138. justify-content: space-between;
  139. align-items: center;
  140. margin-bottom: 20rpx;
  141. padding-bottom: 16rpx;
  142. border-bottom: 1rpx solid #eee;
  143. }
  144. .appointment-id {
  145. font-size: 24rpx;
  146. color: #999;
  147. }
  148. .status-badge {
  149. padding: 6rpx 16rpx;
  150. border-radius: 8rpx;
  151. font-size: 22rpx;
  152. }
  153. .status-0 { background: #FFF3E0; color: #FF9800; }
  154. .status-1 { background: #E3F2FD; color: #2196F3; }
  155. .status-2 { background: #E8F5E9; color: #4CAF50; }
  156. .status-3 { background: #F5F5F5; color: #9E9E9E; }
  157. .status-4 { background: #FFEBEE; color: #F44336; }
  158. .card-body {
  159. margin-bottom: 20rpx;
  160. }
  161. .info-row {
  162. display: flex;
  163. justify-content: space-between;
  164. padding: 10rpx 0;
  165. font-size: 26rpx;
  166. }
  167. .label { color: #999; }
  168. .value { color: #333; }
  169. .card-footer {
  170. padding-top: 16rpx;
  171. border-top: 1rpx dashed #eee;
  172. display: flex;
  173. justify-content: flex-end;
  174. }
  175. .btn-cancel {
  176. background: #F5F5F5;
  177. color: #999;
  178. font-size: 26rpx;
  179. border-radius: 10rpx;
  180. width: 200rpx;
  181. }
  182. .btn-view-report {
  183. background: #667eea;
  184. color: #fff;
  185. font-size: 26rpx;
  186. border-radius: 10rpx;
  187. width: 200rpx;
  188. }
  189. .empty-state {
  190. text-align: center;
  191. padding: 120rpx 0;
  192. }
  193. .empty-icon {
  194. font-size: 80rpx;
  195. display: block;
  196. margin-bottom: 20rpx;
  197. }
  198. .empty-text {
  199. font-size: 28rpx;
  200. color: #999;
  201. display: block;
  202. margin-bottom: 10rpx;
  203. }
  204. .empty-hint {
  205. font-size: 24rpx;
  206. color: #CCC;
  207. display: block;
  208. }
  209. </style>