list.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <view class="enroll-page">
  3. <view class="section-card">
  4. <text class="section-title">选择课程</text>
  5. <text class="card-desc">填写联系方式与准备情况,缴费后由助教分配班次</text>
  6. <view v-if="loading" class="empty-tip">加载中…</view>
  7. <view v-else-if="courses.length === 0" class="empty-tip">暂无可报名课程</view>
  8. <view v-else>
  9. <view class="course-card" v-for="item in courses" :key="item.id">
  10. <view class="course-head">
  11. <text class="course-level">{{ item.level }}</text>
  12. <text class="course-name">{{ item.name }}</text>
  13. </view>
  14. <view class="course-price-box">
  15. <text class="course-price" v-if="item.price > 0">¥{{ fenToYuan(item.price) }}</text>
  16. <text class="course-price-free" v-else>免费</text>
  17. <text class="member-price" v-if="item.memberPrice > 0 && item.memberPrice < item.price">
  18. 会员价 ¥{{ fenToYuan(item.memberPrice) }}
  19. </text>
  20. </view>
  21. <view class="course-status-box">
  22. <text class="status-text" :class="item.statusCls">
  23. {{ item.statusLabel }}
  24. </text>
  25. </view>
  26. <view class="course-foot">
  27. <button
  28. class="enroll-btn"
  29. :disabled="!canEnroll(item)"
  30. @click="handleCourseClick(item)"
  31. >
  32. {{ getButtonText(item) }}
  33. </button>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. <view class="section-card">
  39. <text class="section-title">我的报名</text>
  40. <view v-if="mineLoading" class="empty-tip">加载中…</view>
  41. <view v-else-if="mineList.length === 0" class="empty-tip">暂无报名记录</view>
  42. <view v-else>
  43. <view class="mine-item" v-for="item in mineList" :key="item.id">
  44. <view class="mine-head">
  45. <text class="mine-class">
  46. <text v-if="item.courseName" class="mine-course">{{ item.courseName }}</text>
  47. {{ item.className || '' }}
  48. </text>
  49. <text class="mine-status">{{ statusLabel(item.status) }}</text>
  50. </view>
  51. <text class="mine-time" v-if="item.createdAt">报名时间:{{ formatDateTime(item.createdAt) }}</text>
  52. <view class="mine-actions" v-if="item.status === 'pending' && item.orderNo">
  53. <button class="mine-btn cancel-btn" @click="cancelOrder(item)">取消订单</button>
  54. <button class="mine-btn pay-btn" @click="goPay(item)">去支付</button>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. import { getCourseList, getMyEnrollments, cancelPayOrder } from '@/utils/api.js'
  63. import { fenToYuan, formatDateTime } from '@/utils/format.js'
  64. import { guardPage } from '@/utils/guard.js'
  65. export default {
  66. data() {
  67. return {
  68. courses: [],
  69. mineList: [],
  70. loading: false,
  71. mineLoading: false
  72. }
  73. },
  74. onShow() {
  75. if (!guardPage()) return
  76. this.loadCourses()
  77. this.loadMine()
  78. },
  79. methods: {
  80. fenToYuan: fenToYuan,
  81. formatDateTime: formatDateTime,
  82. loadCourses() {
  83. var self = this
  84. var statusLabelMap = { draft: '未开放', active: '报名中', finished: '已结束' }
  85. self.loading = true
  86. getCourseList().then(function(resp) {
  87. var raw = resp.data || []
  88. self.courses = raw.map(function(item) {
  89. var st = item.effectiveStatus
  90. var cls = 'status-active'
  91. if (st === 'draft') cls = 'status-draft'
  92. if (st === 'finished') cls = 'status-finished'
  93. item.statusCls = cls
  94. item.statusLabel = statusLabelMap[st] || '未知'
  95. return item
  96. })
  97. }).catch(function() {
  98. uni.showToast({ title: '加载课程失败', icon: 'none' })
  99. }).finally(function() {
  100. self.loading = false
  101. })
  102. },
  103. loadMine() {
  104. var self = this
  105. self.mineLoading = true
  106. getMyEnrollments().then(function(resp) {
  107. self.mineList = resp.data || []
  108. }).catch(function() {}).finally(function() {
  109. self.mineLoading = false
  110. })
  111. },
  112. getButtonText(item) {
  113. var status = item.myStatus
  114. if (status === 'pending') return '去支付'
  115. if (status === 'paid') return '待审核'
  116. if (status === 'reviewing') return '审核中'
  117. if (status === 'confirmed') return '已进班'
  118. if (status === 'rejected') return '重新报名'
  119. return '立即报名'
  120. },
  121. canEnroll(item) {
  122. if (item.effectiveStatus === 'draft' || item.effectiveStatus === 'finished') return false
  123. if (item.myStatus === 'paid' || item.myStatus === 'reviewing' || item.myStatus === 'confirmed') return false
  124. return true
  125. },
  126. handleCourseClick(item) {
  127. if (item.myStatus === 'pending') {
  128. var mine = this.mineList.filter(function(m) { return m.courseId === item.id })[0]
  129. if (mine) {
  130. this.goPay(mine)
  131. } else {
  132. uni.showToast({ title: '未找到订单', icon: 'none' })
  133. }
  134. } else {
  135. this.goForm(item)
  136. }
  137. },
  138. statusLabel(status) {
  139. var map = { pending: '待支付', paid: '已支付', reviewing: '进班审核中', confirmed: '已进班', rejected: '进班被拒', cancelled: '已取消' }
  140. return map[status] || status || '未知'
  141. },
  142. goForm(course) {
  143. var userInfo = uni.getStorageSync('userInfo') || {}
  144. var courseName = course.level + ' ' + course.name
  145. uni.navigateTo({
  146. url: '/pages/enroll/form?courseId=' + course.id +
  147. '&courseName=' + encodeURIComponent(courseName) +
  148. '&name=' + encodeURIComponent(userInfo.name || '') +
  149. '&phone=' + encodeURIComponent(userInfo.phone || '')
  150. })
  151. },
  152. goPay(item) {
  153. uni.navigateTo({ url: '/pages/pay/index?enrollmentId=' + item.id })
  154. },
  155. cancelOrder(item) {
  156. var self = this
  157. uni.showModal({
  158. title: '取消订单',
  159. content: '确定取消该报名订单吗?',
  160. success: function(res) {
  161. if (!res.confirm) return
  162. cancelPayOrder({ orderNo: item.orderNo }).then(function() {
  163. uni.showToast({ title: '已取消', icon: 'success' })
  164. self.loadMine()
  165. }).catch(function(err) {
  166. uni.showToast({ title: (err && err.message) || '取消失败', icon: 'none' })
  167. })
  168. }
  169. })
  170. }
  171. }
  172. }
  173. </script>
  174. <style scoped>
  175. .enroll-page { min-height: 100vh; background: #F5F5F5; padding: 32rpx; }
  176. .section-card { background: #FFF; border-radius: 16rpx; padding: 32rpx; margin-bottom: 24rpx; }
  177. .section-title { display: block; font-size: 32rpx; font-weight: 700; color: #1E293B; margin-bottom: 8rpx; border-left: 8rpx solid #F97316; padding-left: 16rpx; }
  178. .card-desc { display: block; font-size: 26rpx; color: #64748B; margin-bottom: 24rpx; }
  179. .empty-tip { font-size: 26rpx; color: #94A3B8; padding: 32rpx 0; text-align: center; }
  180. .course-card { border: 2rpx solid #E2E8F0; border-radius: 12rpx; padding: 24rpx; margin-bottom: 20rpx; }
  181. .course-head { display: flex; align-items: center; margin-bottom: 12rpx; }
  182. .course-level { background: #F97316; color: #FFF; padding: 2rpx 8rpx; border-radius: 4rpx; margin-right: 12rpx; font-weight: 600; font-size: 24rpx; }
  183. .course-name { font-size: 30rpx; font-weight: 600; color: #1E293B; flex: 1; }
  184. .course-price-box { display: flex; align-items: center; gap: 16rpx; margin-bottom: 12rpx; }
  185. .course-price { font-size: 28rpx; color: #F97316; font-weight: 600; }
  186. .course-price-free { font-size: 28rpx; color: #22C55E; font-weight: 600; }
  187. .member-price { font-size: 24rpx; color: #64748B; }
  188. .course-status-box { margin-bottom: 16rpx; }
  189. .status-text { font-size: 24rpx; }
  190. .status-active { color: #22C55E; }
  191. .status-draft { color: #94A3B8; }
  192. .status-finished { color: #EF4444; }
  193. .course-foot { display: flex; align-items: center; justify-content: flex-end; }
  194. .enroll-btn { width: 200rpx; height: 64rpx; line-height: 64rpx; font-size: 26rpx; background: #F97316; color: #FFF; border-radius: 32rpx; border: none; margin: 0; }
  195. .enroll-btn:active { opacity: 0.85; }
  196. .enroll-btn:disabled { background: #CBD5E1; }
  197. .mine-item { padding: 20rpx 0; border-bottom: 1rpx solid #F1F5F9; }
  198. .mine-item:last-child { border-bottom: none; }
  199. .mine-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8rpx; }
  200. .mine-class { font-size: 28rpx; color: #1E293B; font-weight: 500; flex: 1; }
  201. .mine-course { font-weight: 700; margin-right: 8rpx; }
  202. .mine-status { font-size: 24rpx; color: #F97316; }
  203. .mine-time { font-size: 24rpx; color: #94A3B8; }
  204. .mine-actions { display: flex; justify-content: flex-end; margin-top: 16rpx; }
  205. .mine-btn { width: 160rpx; height: 56rpx; line-height: 56rpx; font-size: 24rpx; border-radius: 28rpx; border: none; margin: 0 0 0 16rpx; }
  206. .mine-btn:active { opacity: 0.85; }
  207. .cancel-btn { background: #F1F5F9; color: #64748B; }
  208. .pay-btn { background: #F97316; color: #FFF; }
  209. </style>