appointments.vue 6.0 KB

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