detail.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <view class="course-detail-page">
  3. <!-- 课程介绍 -->
  4. <view class="course-head">
  5. <text class="course-level">{{ course.level || 'L' }}</text>
  6. <text class="course-name">{{ course.name }}</text>
  7. <text class="course-status" :class="'st-' + course.effectiveStatus">{{ statusLabel(course.effectiveStatus) }}</text>
  8. <text class="course-desc" v-if="course.description">{{ course.description }}</text>
  9. <text class="course-time" v-if="course.startTime || course.endTime">
  10. 开课 {{ fmtDate(course.startTime) }} · 结课 {{ fmtDate(course.endTime) }}
  11. </text>
  12. <text class="course-class" v-if="className">我的班次:{{ className }}</text>
  13. </view>
  14. <!-- 未报名:先报名 -->
  15. <view class="action-card" v-if="enrollmentStatus === 'none'">
  16. <text class="action-title">报名参加本课程</text>
  17. <text class="action-desc">填写报名信息并完成支付后,即可申请进班学习</text>
  18. <button class="action-btn" @click="goTo('/pages/enroll/list')">去报名</button>
  19. </view>
  20. <!-- 已报名未进班 -->
  21. <view class="action-card" v-else-if="enrollmentStatus === 'pending'">
  22. <text class="action-title">报名待支付</text>
  23. <text class="action-desc">完成支付后即可申请进班</text>
  24. <button class="action-btn" @click="goTo('/pages/enroll/list')">去支付</button>
  25. </view>
  26. <view class="action-card" v-else-if="enrollmentStatus === 'paid'">
  27. <text class="action-title">已报名,待进班</text>
  28. <text class="action-desc">提交进班申请后由班主任审核,审核通过即可开始学习</text>
  29. <button class="action-btn" :disabled="enterLoading" @click="applyEnter">申请进班</button>
  30. </view>
  31. <view class="action-card" v-else-if="enrollmentStatus === 'reviewing'">
  32. <text class="action-title">进班审核中</text>
  33. <text class="action-desc">班主任正在审核你的进班申请,请耐心等待</text>
  34. <button class="action-btn disabled" disabled>审核中</button>
  35. </view>
  36. <view class="action-card" v-else-if="enrollmentStatus === 'rejected'">
  37. <text class="action-title">进班申请被驳回</text>
  38. <text class="action-desc">可重新提交进班申请,或联系班主任了解原因</text>
  39. <button class="action-btn" :disabled="enterLoading" @click="applyEnter">重新申请进班</button>
  40. </view>
  41. <!-- 已进班:课程学习安排(班次=上课期次,负责上课时间地点) -->
  42. <template v-if="enrollmentStatus === 'confirmed'">
  43. <view class="class-info-card" v-if="className">
  44. <text class="class-info-title">上课班次</text>
  45. <text class="class-info-name">{{ className }}</text>
  46. <text class="class-info-time" v-if="classTime">上课时间:{{ classTime }}</text>
  47. <text class="class-info-place" v-if="classPlace">上课地点:{{ classPlace }}</text>
  48. </view>
  49. <!-- 课程前:课前准备 -->
  50. <view class="stage-card" v-if="stage === 'upcoming'">
  51. <text class="stage-icon">📅</text>
  52. <view class="stage-text">
  53. <text class="stage-title">课程即将开课</text>
  54. <text class="stage-sub">先完成课前准备,做好学习规划</text>
  55. </view>
  56. </view>
  57. <!-- 课程中:学习进度 -->
  58. <view class="section-card" v-if="stage === 'active'">
  59. <view class="section-head">
  60. <text class="section-title">学习进度</text>
  61. <text class="progress-count">{{ progress.done }}/{{ progress.total }} 项完成</text>
  62. </view>
  63. <view class="progress-bar">
  64. <view class="progress-fill" :style="{ width: progressPercent }"></view>
  65. </view>
  66. <view class="progress-list">
  67. <view class="progress-item" v-for="(it, idx) in progress.items" :key="idx">
  68. <text class="progress-icon" :class="{ done: it.ok }">{{ it.ok ? '✅' : '⬜' }}</text>
  69. <text class="progress-label">{{ it.label }}</text>
  70. </view>
  71. </view>
  72. </view>
  73. <!-- 课程后:结业事项 -->
  74. <view class="stage-card" v-if="stage === 'finished'">
  75. <text class="stage-icon">🎉</text>
  76. <view class="stage-text">
  77. <text class="stage-title">课程已结束</text>
  78. <text class="stage-sub">完成结业事项,收获学习成果</text>
  79. </view>
  80. </view>
  81. <!-- 本阶段要做的事 -->
  82. <view class="stage-title-block">本阶段要做的事</view>
  83. <view class="nav-grid">
  84. <view class="nav-item" v-for="(g, idx) in stageMenus" :key="idx" @click="onMenu(g)">
  85. <text class="nav-icon">{{ g.icon }}</text>
  86. <text class="nav-text">{{ g.text }}</text>
  87. </view>
  88. </view>
  89. </template>
  90. </view>
  91. </template>
  92. <script>
  93. import { getMyCourse, getCourseProgress, enterCourse } from '@/utils/api.js'
  94. import { formatDateTime } from '@/utils/format.js'
  95. import { requireLogin } from '@/utils/guard.js'
  96. export default {
  97. data() {
  98. return {
  99. course: {},
  100. className: '',
  101. classTime: '',
  102. classPlace: '',
  103. enrollment: null,
  104. progress: { done: 0, total: 0, items: [] },
  105. enterLoading: false
  106. }
  107. },
  108. computed: {
  109. isLoggedIn() {
  110. return this.$store.getters.isLoggedIn
  111. },
  112. progressPercent() {
  113. var total = this.progress.total || 0
  114. if (!total) return '0%'
  115. var pct = Math.round((this.progress.done || 0) * 100 / total)
  116. return pct + '%'
  117. },
  118. // 课程所处阶段:upcoming(前) / active(中) / finished(后) / draft
  119. stage() {
  120. return this.course.effectiveStatus || 'active'
  121. },
  122. enrollmentStatus() {
  123. if (!this.enrollment || !this.enrollment.status) return 'none'
  124. return this.enrollment.status
  125. },
  126. stageMenus() {
  127. if (this.stage === 'upcoming') {
  128. // 课程前:课前准备
  129. return [
  130. { icon: '📄', text: '课前资料', url: '/pages/material/index' },
  131. { icon: '📝', text: '兴趣调研', url: '/pages/survey/index' },
  132. { icon: '📅', text: '行动计划', url: '/pages/plan/index' },
  133. { icon: '👥', text: '我的小组', url: '/pages/group/index' }
  134. ]
  135. }
  136. if (this.stage === 'finished') {
  137. // 课程后:结业事项
  138. return [
  139. { icon: '📋', text: '三本账', url: '/pages/assignment/index' },
  140. { icon: '📅', text: '行动计划', url: '/pages/plan/index' },
  141. { icon: '🏆', text: '积分榜', url: '/pages/scoreboard/index' },
  142. { icon: '🗳️', text: '路演投票', url: '/pages/vote/index' }
  143. ]
  144. }
  145. // 课程中:学习内容
  146. return [
  147. { icon: '📄', text: '课前资料', url: '/pages/material/index' },
  148. { icon: '👥', text: '我的小组', url: '/pages/group/index' },
  149. { icon: '✅', text: '装机打卡', url: '/pages/checkin/index', tab: true },
  150. { icon: '📤', text: '成果上传', url: '/pages/upload/index' },
  151. { icon: '📝', text: '教学卡', url: '/pages/teaching/index' },
  152. { icon: '🎤', text: '路演材料', url: '/pages/roadmap/index' },
  153. { icon: '🗳️', text: '路演投票', url: '/pages/vote/index' },
  154. { icon: '🏆', text: '积分榜', url: '/pages/scoreboard/index' },
  155. { icon: '📅', text: '行动计划', url: '/pages/plan/index' },
  156. { icon: '📋', text: '三本账', url: '/pages/assignment/index' }
  157. ]
  158. }
  159. },
  160. onLoad(options) {
  161. this.courseId = (options && options.courseId) || ''
  162. this.loadAll()
  163. },
  164. methods: {
  165. loadAll() {
  166. var self = this
  167. getMyCourse(self.courseId).then(function(resp) {
  168. var d = resp.data || {}
  169. var c = d.course || {}
  170. self.course = c
  171. self.className = d.className || ''
  172. self.classTime = d.classTime || ''
  173. self.classPlace = d.classPlace || ''
  174. self.enrollment = d.enrollment || null
  175. }).catch(function() {})
  176. // 学习进度需登录后请求,未登录浏览时不调用(避免 401 误触发登录过期弹窗)
  177. if (self.isLoggedIn) {
  178. getCourseProgress().then(function(resp) {
  179. var d = resp.data || {}
  180. self.progress = {
  181. done: d.done || 0,
  182. total: d.total || 0,
  183. items: d.items || []
  184. }
  185. }).catch(function() {})
  186. }
  187. },
  188. onMenu(g) {
  189. if (!g) return
  190. if (g.tab) {
  191. uni.switchTab({ url: g.url })
  192. } else {
  193. uni.navigateTo({ url: g.url })
  194. }
  195. },
  196. applyEnter() {
  197. var self = this
  198. if (!requireLogin()) return
  199. if (!self.course.id) return
  200. uni.showModal({
  201. title: '申请进班',
  202. content: '确认提交进班申请?提交后由班主任审核。',
  203. success: function(res) {
  204. if (!res.confirm) return
  205. self.enterLoading = true
  206. enterCourse(self.course.id).then(function(resp) {
  207. uni.showToast({ title: '已提交申请', icon: 'success' })
  208. self.loadAll()
  209. }).catch(function(err) {
  210. var msg = (err && err.message) || '提交失败'
  211. if (msg.indexOf('报名') >= 0 || msg.indexOf('支付') >= 0) {
  212. uni.showModal({
  213. title: '提示',
  214. content: msg,
  215. confirmText: '去报名',
  216. success: function(r) {
  217. if (r.confirm) {
  218. uni.navigateTo({ url: '/pages/enroll/list' })
  219. }
  220. }
  221. })
  222. } else {
  223. uni.showToast({ title: msg, icon: 'none' })
  224. }
  225. }).finally(function() {
  226. self.enterLoading = false
  227. })
  228. }
  229. })
  230. },
  231. statusLabel(st) {
  232. var map = { upcoming: '未开始', active: '进行中', finished: '已结束', draft: '未发布' }
  233. return map[st] || st || '-'
  234. },
  235. fmtDate(v) {
  236. if (!v) return '-'
  237. return formatDateTime(v)
  238. },
  239. goTo(url) {
  240. // 去报名/去支付为实际操作,未登录先引导登录(课程信息浏览已放行)
  241. if (!requireLogin()) return
  242. uni.navigateTo({ url: url })
  243. }
  244. }
  245. }
  246. </script>
  247. <style scoped>
  248. .course-detail-page { min-height: 100vh; background: #F5F5F5; padding: 24rpx 32rpx; }
  249. .course-head { background: #FFF; border-radius: 20rpx; padding: 32rpx; margin-bottom: 24rpx; display: flex; flex-direction: column; }
  250. .action-card { background: #FFF; border-radius: 16rpx; padding: 32rpx; margin-bottom: 24rpx; display: flex; flex-direction: column; align-items: center; }
  251. .action-title { font-size: 32rpx; font-weight: 700; color: #1E293B; margin-bottom: 12rpx; }
  252. .action-desc { font-size: 26rpx; color: #64748B; text-align: center; line-height: 1.6; margin-bottom: 28rpx; }
  253. .action-btn { width: 100%; height: 88rpx; line-height: 88rpx; background: linear-gradient(135deg, #F97316, #EA580C); color: #FFF; font-size: 30rpx; font-weight: 600; border-radius: 44rpx; border: none; }
  254. .action-btn.disabled { background: #F1F5F9; color: #94A3B8; }
  255. .action-btn:active { opacity: 0.88; }
  256. .course-level { align-self: flex-start; font-size: 22rpx; font-weight: 600; color: #F97316; background: #FFF7ED; border-radius: 8rpx; padding: 4rpx 14rpx; margin-bottom: 12rpx; }
  257. .course-name { font-size: 36rpx; font-weight: 700; color: #1E293B; margin-bottom: 8rpx; }
  258. .course-status { align-self: flex-start; font-size: 22rpx; border-radius: 6rpx; padding: 4rpx 16rpx; margin-bottom: 12rpx; }
  259. .course-status.st-upcoming { color: #F97316; background: #FFF7ED; }
  260. .course-status.st-active { color: #22C55E; background: #F0FDF4; }
  261. .course-status.st-finished { color: #94A3B8; background: #F1F5F9; }
  262. .course-desc { font-size: 26rpx; color: #64748B; line-height: 1.6; margin-bottom: 8rpx; }
  263. .course-time { font-size: 24rpx; color: #94A3B8; margin-bottom: 8rpx; }
  264. .course-class { font-size: 24rpx; color: #1E293B; background: #F1F5F9; border-radius: 8rpx; padding: 8rpx 16rpx; align-self: flex-start; }
  265. .class-info-card { background: #FFF; border-radius: 16rpx; padding: 28rpx 32rpx; margin-bottom: 24rpx; display: flex; flex-direction: column; }
  266. .class-info-title { font-size: 24rpx; color: #94A3B8; margin-bottom: 8rpx; }
  267. .class-info-name { font-size: 30rpx; font-weight: 700; color: #1E293B; margin-bottom: 8rpx; }
  268. .class-info-time { font-size: 26rpx; color: #475569; margin-bottom: 4rpx; }
  269. .class-info-place { font-size: 26rpx; color: #475569; }
  270. .stage-card { display: flex; align-items: center; background: #FFF; border-radius: 16rpx; padding: 28rpx 32rpx; margin-bottom: 24rpx; }
  271. .stage-icon { font-size: 48rpx; margin-right: 20rpx; }
  272. .stage-text { display: flex; flex-direction: column; }
  273. .stage-title { font-size: 30rpx; font-weight: 700; color: #1E293B; margin-bottom: 6rpx; }
  274. .stage-sub { font-size: 24rpx; color: #64748B; }
  275. .stage-title-block { font-size: 30rpx; font-weight: 600; color: #1E293B; margin-bottom: 16rpx; border-left: 8rpx solid #F97316; padding-left: 16rpx; }
  276. .section-card { background: #FFF; border-radius: 16rpx; padding: 28rpx; margin-bottom: 24rpx; }
  277. .section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16rpx; }
  278. .section-title { font-size: 30rpx; font-weight: 600; color: #1E293B; border-left: 8rpx solid #F97316; padding-left: 16rpx; }
  279. .progress-count { font-size: 24rpx; color: #64748B; }
  280. .progress-bar { height: 16rpx; background: #F1F5F9; border-radius: 8rpx; overflow: hidden; margin-bottom: 20rpx; }
  281. .progress-fill { height: 100%; background: linear-gradient(90deg, #F97316, #EA580C); border-radius: 8rpx; }
  282. .progress-list { display: flex; flex-direction: column; }
  283. .progress-item { display: flex; align-items: center; padding: 10rpx 0; }
  284. .progress-icon { font-size: 28rpx; margin-right: 12rpx; }
  285. .progress-label { font-size: 26rpx; color: #1E293B; }
  286. .nav-grid { display: flex; flex-wrap: wrap; gap: 0; background: #FFF; border-radius: 16rpx; overflow: hidden; }
  287. .nav-item { width: 25%; display: flex; flex-direction: column; align-items: center; padding: 28rpx 0; }
  288. .nav-item:active { background: #F8FAFC; }
  289. .nav-icon { font-size: 44rpx; margin-bottom: 8rpx; }
  290. .nav-text { font-size: 24rpx; color: #1E293B; text-align: center; }
  291. </style>