detail.vue 16 KB

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