list.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. <LoadingSkeleton v-if="loading" :rows="3" />
  7. <ErrorState v-else-if="error" message="课程加载失败" @retry="loadCourses" />
  8. <EmptyState v-else-if="courses.length === 0" icon="📚" title="暂无可报名课程" desc="新课程发布后可在此报名" action-text="重新加载" @action="loadCourses" />
  9. <view v-else>
  10. <view class="course-card" v-for="item in courses" :key="item.id">
  11. <view class="course-head">
  12. <text class="course-level">{{ item.level }}</text>
  13. <text class="course-name">{{ item.name }}</text>
  14. </view>
  15. <view class="course-price-box">
  16. <text class="course-price" v-if="item.price > 0">¥{{ fenToYuan(item.price) }}</text>
  17. <text class="course-price-free" v-else>免费</text>
  18. <text class="member-price" v-if="item.memberPrice > 0 && item.memberPrice < item.price">
  19. 会员价 ¥{{ fenToYuan(item.memberPrice) }}
  20. </text>
  21. </view>
  22. <view class="course-status-box">
  23. <text class="status-text" :class="item.statusCls">
  24. {{ item.statusLabel }}
  25. </text>
  26. </view>
  27. <view class="course-foot">
  28. <button
  29. class="enroll-btn"
  30. :disabled="!canEnroll(item)"
  31. @click="handleCourseClick(item)"
  32. >
  33. {{ getButtonText(item) }}
  34. </button>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="section-card">
  40. <text class="section-title">我的报名</text>
  41. <LoadingSkeleton v-if="mineLoading" :rows="2" />
  42. <ErrorState v-else-if="mineError" message="我的报名加载失败" @retry="loadMine" />
  43. <EmptyState v-else-if="mineList.length === 0" icon="📭" title="暂无报名记录" desc="报名后会在此展示进度" />
  44. <view v-else>
  45. <view class="mine-item" v-for="item in mineList" :key="item.id">
  46. <view class="mine-head">
  47. <text class="mine-class">
  48. <text v-if="item.courseName" class="mine-course">{{ item.courseName }}</text>
  49. {{ item.className || '' }}
  50. </text>
  51. <text class="mine-status">{{ statusLabel(item.status) }}</text>
  52. </view>
  53. <text class="mine-time" v-if="item.createdAt">报名时间:{{ formatDateTime(item.createdAt) }}</text>
  54. <view class="mine-enroll" v-if="item.enrollmentStatus && item.enrollmentStatus !== 'none'">
  55. <text class="mine-enroll-status" :class="item.enrollmentStatusCls">{{ item.enrollmentStatusLabel }}</text>
  56. <text class="mine-enroll-deadline" v-if="item.validUntil">有效期至 {{ formatDateOnly(item.validUntil) }}</text>
  57. <button class="mine-btn activate-btn" v-if="item.enrollmentStatus === 'dormant'" @click="activateEnroll(item)">激活学籍</button>
  58. </view>
  59. <view class="mine-actions" v-if="item.status === 'pending' && item.orderNo">
  60. <button class="mine-btn cancel-btn" @click="cancelOrder(item)">取消订单</button>
  61. <button class="mine-btn pay-btn" @click="goPay(item)">去支付</button>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. </template>
  68. <script>
  69. import { getCourseList, getMyEnrollments, cancelPayOrder, activateEnrollment } from '@/utils/api.js'
  70. import { fenToYuan, formatDateTime } from '@/utils/format.js'
  71. import { guardPage } from '@/utils/guard.js'
  72. import { captureInviteCode } from '@/utils/invite.js'
  73. import LoadingSkeleton from '@/components/loading-skeleton.vue'
  74. import ErrorState from '@/components/error-state.vue'
  75. import EmptyState from '@/components/empty-state.vue'
  76. export default {
  77. components: { LoadingSkeleton, ErrorState, EmptyState },
  78. data() {
  79. return {
  80. courses: [],
  81. mineList: [],
  82. loading: false,
  83. mineLoading: false,
  84. error: false,
  85. mineError: false
  86. }
  87. },
  88. onLoad(options) {
  89. // 海报/分享文案落地页:捕获 inviteCode 与扫码 scene 中的邀请码,供报名表单回填
  90. captureInviteCode(options)
  91. },
  92. onShow() {
  93. if (!guardPage()) return
  94. this.loadCourses()
  95. this.loadMine()
  96. },
  97. methods: {
  98. fenToYuan: fenToYuan,
  99. formatDateTime: formatDateTime,
  100. loadCourses() {
  101. var self = this
  102. var statusLabelMap = { draft: '未开放', active: '报名中', finished: '已结束' }
  103. self.loading = true
  104. self.error = false
  105. getCourseList().then(function(resp) {
  106. var raw = resp.data || []
  107. self.courses = raw.map(function(item) {
  108. var st = item.effectiveStatus
  109. var cls = 'status-active'
  110. if (st === 'draft') cls = 'status-draft'
  111. if (st === 'finished') cls = 'status-finished'
  112. item.statusCls = cls
  113. item.statusLabel = statusLabelMap[st] || '未知'
  114. return item
  115. })
  116. }).catch(function() {
  117. self.error = true
  118. }).finally(function() {
  119. self.loading = false
  120. })
  121. },
  122. loadMine() {
  123. var self = this
  124. var enrollLabelMap = { active: '学籍生效中', dormant: '学籍已休眠', none: '无学籍' }
  125. self.mineLoading = true
  126. self.mineError = false
  127. getMyEnrollments().then(function(resp) {
  128. var raw = resp.data || []
  129. self.mineList = raw.map(function(item) {
  130. var st = item.enrollmentStatus
  131. var cls = 'enroll-none'
  132. if (st === 'active') cls = 'enroll-active'
  133. if (st === 'dormant') cls = 'enroll-dormant'
  134. item.enrollmentStatusCls = cls
  135. item.enrollmentStatusLabel = enrollLabelMap[st] || '未知'
  136. return item
  137. })
  138. }).catch(function() {
  139. self.mineError = true
  140. }).finally(function() {
  141. self.mineLoading = false
  142. })
  143. },
  144. getButtonText(item) {
  145. var status = item.myStatus
  146. if (status === 'pending') return '去支付'
  147. if (status === 'paid') return '待审核'
  148. if (status === 'reviewing') return '审核中'
  149. if (status === 'confirmed') return '已进班'
  150. if (status === 'rejected') return '重新报名'
  151. return '立即报名'
  152. },
  153. canEnroll(item) {
  154. if (item.effectiveStatus === 'draft' || item.effectiveStatus === 'finished') return false
  155. if (item.myStatus === 'paid' || item.myStatus === 'reviewing' || item.myStatus === 'confirmed') return false
  156. return true
  157. },
  158. handleCourseClick(item) {
  159. if (item.myStatus === 'pending') {
  160. var mine = this.mineList.filter(function(m) { return m.courseId === item.id })[0]
  161. if (mine) {
  162. this.goPay(mine)
  163. } else {
  164. uni.showToast({ title: '未找到订单', icon: 'none' })
  165. }
  166. } else {
  167. this.goForm(item)
  168. }
  169. },
  170. statusLabel(status) {
  171. var map = { pending: '待支付', paid: '已支付', reviewing: '进班审核中', confirmed: '已进班', rejected: '进班被拒', cancelled: '已取消' }
  172. return map[status] || status || '未知'
  173. },
  174. goForm(course) {
  175. var userInfo = uni.getStorageSync('userInfo') || {}
  176. var courseName = course.level + ' ' + course.name
  177. uni.navigateTo({
  178. url: '/pages/enroll/form?courseId=' + course.id +
  179. '&courseName=' + encodeURIComponent(courseName) +
  180. '&name=' + encodeURIComponent(userInfo.name || '') +
  181. '&phone=' + encodeURIComponent(userInfo.phone || '')
  182. })
  183. },
  184. goPay(item) {
  185. uni.navigateTo({ url: '/pages/pay/index?enrollmentId=' + item.id })
  186. },
  187. cancelOrder(item) {
  188. var self = this
  189. uni.showModal({
  190. title: '取消订单',
  191. content: '确定取消该报名订单吗?',
  192. success: function(res) {
  193. if (!res.confirm) return
  194. cancelPayOrder({ orderNo: item.orderNo }).then(function() {
  195. uni.showToast({ title: '已取消', icon: 'success' })
  196. self.loadMine()
  197. }).catch(function(err) {
  198. uni.showToast({ title: (err && err.message) || '取消失败', icon: 'none' })
  199. })
  200. }
  201. })
  202. },
  203. formatDateOnly(str) {
  204. return str ? str.substring(0, 10) : ''
  205. },
  206. activateEnroll(item) {
  207. var self = this
  208. uni.showModal({
  209. title: '激活学籍',
  210. content: '学籍已休眠,激活费 = 课程费 20%。激活后学籍重新生效 12 个月,确认激活?',
  211. success: function(res) {
  212. if (!res.confirm) return
  213. activateEnrollment({ enrollmentId: item.id }).then(function(resp) {
  214. var d = resp.data || {}
  215. var until = d.validUntil ? d.validUntil.substring(0, 10) : ''
  216. uni.showToast({ title: until ? '激活成功,有效期至 ' + until : '激活成功', icon: 'none' })
  217. self.loadMine()
  218. }).catch(function(err) {
  219. uni.showToast({ title: (err && err.message) || '激活失败', icon: 'none' })
  220. })
  221. }
  222. })
  223. }
  224. }
  225. }
  226. </script>
  227. <style scoped>
  228. .enroll-page { min-height: 100vh; background: #F5FAFE; padding: 32rpx; }
  229. .section-card { background: #FFF; border-radius: 16rpx; padding: 32rpx; margin-bottom: 24rpx; }
  230. .section-title { display: block; font-size: 32rpx; font-weight: 700; color: #1E3A5F; margin-bottom: 8rpx; border-left: 8rpx solid #2E6FA8; padding-left: 16rpx; }
  231. .card-desc { display: block; font-size: 26rpx; color: #3B5A78; margin-bottom: 24rpx; }
  232. .empty-tip { font-size: 26rpx; color: #6B7B8C; padding: 32rpx 0; text-align: center; }
  233. .course-card { border: 2rpx solid #E3ECF4; border-radius: 12rpx; padding: 24rpx; margin-bottom: 20rpx; }
  234. .course-head { display: flex; align-items: center; margin-bottom: 12rpx; }
  235. .course-level { background: #2E6FA8; color: #FFF; padding: 2rpx 8rpx; border-radius: 4rpx; margin-right: 12rpx; font-weight: 600; font-size: 24rpx; }
  236. .course-name { font-size: 30rpx; font-weight: 600; color: #1E3A5F; flex: 1; }
  237. .course-price-box { display: flex; align-items: center; gap: 16rpx; margin-bottom: 12rpx; }
  238. .course-price { font-size: 28rpx; color: #2E6FA8; font-weight: 600; }
  239. .course-price-free { font-size: 28rpx; color: #0E8A4F; font-weight: 600; }
  240. .member-price { font-size: 24rpx; color: #3B5A78; }
  241. .course-status-box { margin-bottom: 16rpx; }
  242. .status-text { font-size: 24rpx; }
  243. .status-active { color: #0E8A4F; }
  244. .status-draft { color: #6B7B8C; }
  245. .status-finished { color: #C0392B; }
  246. .course-foot { display: flex; align-items: center; justify-content: flex-end; }
  247. .enroll-btn { width: 200rpx; height: 64rpx; line-height: 64rpx; font-size: 26rpx; background: #2E6FA8; color: #FFF; border-radius: 32rpx; border: none; margin: 0; }
  248. .enroll-btn:active { opacity: 0.85; }
  249. .enroll-btn:disabled { background: #C3D2DF; }
  250. .mine-item { padding: 20rpx 0; border-bottom: 1rpx solid #E3ECF4; }
  251. .mine-item:last-child { border-bottom: none; }
  252. .mine-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8rpx; }
  253. .mine-class { font-size: 28rpx; color: #1E3A5F; font-weight: 500; flex: 1; }
  254. .mine-course { font-weight: 700; margin-right: 8rpx; }
  255. .mine-status { font-size: 24rpx; color: #2E6FA8; }
  256. .mine-time { font-size: 24rpx; color: #6B7B8C; }
  257. .mine-actions { display: flex; justify-content: flex-end; margin-top: 16rpx; }
  258. .mine-btn { width: 160rpx; height: 56rpx; line-height: 56rpx; font-size: 24rpx; border-radius: 28rpx; border: none; margin: 0 0 0 16rpx; }
  259. .mine-btn:active { opacity: 0.85; }
  260. .cancel-btn { background: #E3ECF4; color: #3B5A78; }
  261. .pay-btn { background: #2E6FA8; color: #FFF; }
  262. .mine-enroll { display: flex; align-items: center; margin-top: 12rpx; }
  263. .mine-enroll-status { font-size: 24rpx; padding: 2rpx 12rpx; border-radius: 4rpx; color: #FFF; }
  264. .enroll-active { background: #0E8A4F; }
  265. .enroll-dormant { background: #B9770E; }
  266. .mine-enroll-deadline { font-size: 24rpx; color: #6B7B8C; margin-left: 16rpx; flex: 1; }
  267. .activate-btn { background: #B9770E; color: #FFF; }
  268. </style>