index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <view class="course-page">
  3. <!-- 进行中的课程(上课状态) -->
  4. <view v-if="activeCourse" class="active-card">
  5. <view class="active-badge">
  6. <text class="active-badge-text">⏰ 课程进行中</text>
  7. </view>
  8. <text class="active-name">{{ activeCourse.level }} {{ activeCourse.name }}</text>
  9. <text class="active-desc">{{ activeCourse.description || '当前正在进行的课程' }}</text>
  10. <view class="active-time">
  11. <text class="active-time-text">开始 {{ fmtTime(activeCourse.startTime) }}</text>
  12. <text class="active-time-text" v-if="activeCourse.endTime">结束 {{ fmtTime(activeCourse.endTime) }}</text>
  13. </view>
  14. <button class="active-btn" :class="{ 'btn-disabled': isReviewing(activeCourse) }"
  15. :disabled="isReviewing(activeCourse)" @click="handleAction(activeCourse)">
  16. {{ actionText(activeCourse) }}
  17. </button>
  18. </view>
  19. <view class="section-title">全部课程</view>
  20. <view class="course-list">
  21. <view class="course-card" v-for="(c, idx) in courses" :key="idx">
  22. <view class="course-head">
  23. <text class="course-level">{{ c.level }}</text>
  24. <text class="course-name">{{ c.name }}</text>
  25. </view>
  26. <view class="course-desc" v-if="c.description">{{ c.description }}</view>
  27. <view class="course-tags">
  28. <text class="course-tag" :class="'st-' + c.effectiveStatus">{{ statusLabel(c.effectiveStatus) }}</text>
  29. <text class="course-tag mine" :class="'my-' + c.myStatus">{{ myLabel(c.myStatus) }}</text>
  30. </view>
  31. <button class="course-btn" :class="{ 'btn-disabled': isReviewing(c) }"
  32. :disabled="isReviewing(c)" @click="handleAction(c)">
  33. {{ actionText(c) }}
  34. </button>
  35. </view>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import { getCourseList, enterCourse } from '@/utils/api.js'
  41. import { formatDateTime } from '@/utils/format.js'
  42. export default {
  43. data() {
  44. return {
  45. courses: [],
  46. loading: false
  47. }
  48. },
  49. computed: {
  50. isLoggedIn() {
  51. return this.$store.getters.isLoggedIn
  52. },
  53. activeCourse() {
  54. var list = this.courses || []
  55. for (var i = 0; i < list.length; i++) {
  56. if (list[i].effectiveStatus === 'active') {
  57. return list[i]
  58. }
  59. }
  60. return null
  61. }
  62. },
  63. onShow() {
  64. this.loadCourses()
  65. },
  66. methods: {
  67. loadCourses() {
  68. if (!this.isLoggedIn) return
  69. var self = this
  70. self.loading = true
  71. getCourseList().then(function(resp) {
  72. self.courses = resp.data || []
  73. }).catch(function() {
  74. uni.showToast({ title: '获取课程列表失败', icon: 'none' })
  75. }).finally(function() {
  76. self.loading = false
  77. })
  78. },
  79. statusLabel(st) {
  80. var map = { upcoming: '未开始', active: '进行中', finished: '已结束', draft: '未发布' }
  81. return map[st] || st || '-'
  82. },
  83. myLabel(st) {
  84. var map = { none: '未报名', pending: '待支付', paid: '已支付', reviewing: '审核中', confirmed: '已进班', rejected: '未通过' }
  85. return map[st] || st || '-'
  86. },
  87. isReviewing(c) {
  88. return c && c.myStatus === 'reviewing'
  89. },
  90. actionText(c) {
  91. if (!c) return ''
  92. var s = c.myStatus
  93. if (s === 'confirmed') return '进入课程'
  94. if (s === 'reviewing') return '等待审核'
  95. if (s === 'pending') return '去支付'
  96. if (s === 'paid' || s === 'rejected') return '申请进班'
  97. return '报名进班'
  98. },
  99. handleAction(c) {
  100. if (!c) return
  101. var s = c.myStatus
  102. if (s === 'confirmed') {
  103. uni.navigateTo({ url: '/pages/course/detail?courseId=' + c.id })
  104. } else if (s === 'pending') {
  105. uni.navigateTo({ url: '/pages/enroll/list' })
  106. } else if (s === 'paid' || s === 'rejected') {
  107. this.applyEnter(c)
  108. } else {
  109. // 未报名:先走报名流程
  110. uni.navigateTo({ url: '/pages/enroll/list' })
  111. }
  112. },
  113. applyEnter(c) {
  114. var self = this
  115. uni.showModal({
  116. title: '申请进班',
  117. content: '确认申请进入「' + c.name + '」?班主任/管理员审核通过后即可进入课程。',
  118. success: function(res) {
  119. if (!res.confirm) return
  120. enterCourse(c.id).then(function(resp) {
  121. var d = resp.data || {}
  122. uni.showToast({ title: d.message || '申请已提交', icon: 'none' })
  123. self.loadCourses()
  124. }).catch(function(err) {
  125. var msg = (err && err.message) || '申请失败'
  126. uni.showToast({ title: msg, icon: 'none' })
  127. // 未完成报名/支付等场景引导去报名
  128. if (msg.indexOf('报名') !== -1 || msg.indexOf('支付') !== -1) {
  129. setTimeout(function() {
  130. uni.navigateTo({ url: '/pages/enroll/list' })
  131. }, 1200)
  132. }
  133. })
  134. }
  135. })
  136. },
  137. fmtTime(v) {
  138. if (!v) return ''
  139. return formatDateTime(v)
  140. }
  141. }
  142. }
  143. </script>
  144. <style scoped>
  145. .course-page { min-height: 100vh; background: #F5F5F5; padding: 24rpx 32rpx; }
  146. .section-title { font-size: 30rpx; font-weight: 600; color: #1E293B; margin-bottom: 16rpx; border-left: 8rpx solid #F97316; padding-left: 16rpx; }
  147. .active-card { background: linear-gradient(135deg, #F97316, #EA580C); border-radius: 20rpx; padding: 32rpx; margin-bottom: 32rpx; }
  148. .active-badge { display: inline-block; background: rgba(255,255,255,0.2); border-radius: 100rpx; padding: 4rpx 20rpx; margin-bottom: 16rpx; }
  149. .active-badge-text { font-size: 22rpx; color: #FFF; font-weight: 600; }
  150. .active-name { display: block; font-size: 36rpx; font-weight: 700; color: #FFF; margin-bottom: 8rpx; }
  151. .active-desc { display: block; font-size: 26rpx; color: rgba(255,255,255,0.9); margin-bottom: 16rpx; }
  152. .active-time { display: flex; flex-direction: column; margin-bottom: 24rpx; }
  153. .active-time-text { font-size: 22rpx; color: rgba(255,255,255,0.8); margin-bottom: 4rpx; }
  154. .active-btn { background: #FFF; color: #EA580C; font-size: 30rpx; font-weight: 600; border-radius: 48rpx; height: 80rpx; line-height: 80rpx; border: none; margin: 0; }
  155. .active-btn:active { opacity: 0.9; }
  156. .course-list { display: flex; flex-direction: column; }
  157. .course-card { background: #FFF; border-radius: 16rpx; padding: 28rpx; margin-bottom: 20rpx; }
  158. .course-head { display: flex; align-items: center; margin-bottom: 8rpx; }
  159. .course-level { font-size: 24rpx; font-weight: 600; color: #F97316; background: #FFF7ED; border-radius: 8rpx; padding: 4rpx 14rpx; margin-right: 16rpx; }
  160. .course-name { font-size: 30rpx; font-weight: 600; color: #1E293B; flex: 1; }
  161. .course-desc { font-size: 24rpx; color: #64748B; margin-bottom: 16rpx; line-height: 1.6; }
  162. .course-tags { display: flex; align-items: center; margin-bottom: 20rpx; }
  163. .course-tag { font-size: 20rpx; color: #64748B; background: #F1F5F9; border-radius: 6rpx; padding: 4rpx 14rpx; margin-right: 12rpx; }
  164. .course-tag.st-upcoming { color: #F97316; background: #FFF7ED; }
  165. .course-tag.st-active { color: #22C55E; background: #F0FDF4; }
  166. .course-tag.st-finished { color: #94A3B8; background: #F1F5F9; }
  167. .course-tag.mine { color: #6366F1; background: #EEF2FF; }
  168. .course-tag.my-confirmed { color: #22C55E; background: #F0FDF4; }
  169. .course-tag.my-reviewing { color: #F97316; background: #FFF7ED; }
  170. .course-tag.my-rejected { color: #EF5350; background: #FEF2F2; }
  171. .course-btn { background: linear-gradient(135deg, #F97316, #EA580C); color: #FFF; font-size: 28rpx; font-weight: 600; border-radius: 44rpx; height: 76rpx; line-height: 76rpx; border: none; margin: 0; }
  172. .course-btn:active { opacity: 0.9; }
  173. .btn-disabled { background: #E2E8F0; color: #94A3B8; }
  174. </style>