index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <view class="mine-page">
  3. <view class="profile-card">
  4. <view class="avatar">👤</view>
  5. <view class="profile-info">
  6. <text class="profile-name">{{ name || '未登录' }}</text>
  7. <text class="profile-role">角色:{{ roleLabel }}</text>
  8. <text class="profile-verify" :class="verifyClass">校验:{{ verifyLabel }}</text>
  9. </view>
  10. </view>
  11. <view class="section-card">
  12. <text class="section-title">🎓 完课证书</text>
  13. <view v-if="certLoading" class="empty-text">加载中...</view>
  14. <view v-else-if="cert.eligible && cert.certNo" class="cert-ok">
  15. <text class="cert-no">{{ cert.certNo }}</text>
  16. <text class="cert-tip">恭喜完成离场验收全部 6 项!</text>
  17. <button class="mini-btn" @click="copyCertNo">复制证书号</button>
  18. </view>
  19. <view v-else-if="cert.items && cert.items.length">
  20. <text class="cert-progress">已完成 {{ certDoneCount }}/6 项</text>
  21. <view class="cert-items">
  22. <view class="cert-item" v-for="(it, idx) in cert.items" :key="idx">
  23. <text class="cert-icon">{{ it.ok ? '✅' : '⬜' }}</text>
  24. <text class="cert-label">{{ it.label }}</text>
  25. </view>
  26. </view>
  27. </view>
  28. <view v-else class="empty-text">暂无证书信息,完成 6 项离场验收后可领取</view>
  29. </view>
  30. <view class="section-card">
  31. <text class="section-title">🎟️ 卡券核销</text>
  32. <view v-if="coupons.length === 0" class="empty-text">暂无卡券</view>
  33. <view class="coupon-list">
  34. <view class="coupon-item" v-for="(c, idx) in coupons" :key="idx">
  35. <view class="coupon-info">
  36. <text class="coupon-code">{{ c.code }}</text>
  37. <text class="coupon-status" :class="c.status">{{ couponStatusText(c) }}</text>
  38. </view>
  39. <text v-if="c.status === 'unused'" class="redeem-btn" @click="redeem(c)">核销</text>
  40. </view>
  41. </view>
  42. </view>
  43. <view class="menu-card">
  44. <view class="menu-item" @click="goTo('/pages/enroll/list')">
  45. <text class="menu-icon">🎫</text>
  46. <text class="menu-text">报名中心</text>
  47. <text class="menu-arrow">›</text>
  48. </view>
  49. <view class="menu-item" @click="goTo('/pages/group-order/index')">
  50. <text class="menu-icon">👨‍👩‍👧‍👦</text>
  51. <text class="menu-text">团报</text>
  52. <text class="menu-arrow">›</text>
  53. </view>
  54. <view class="menu-item" @click="goTo('/pages/case/index')">
  55. <text class="menu-icon">📋</text>
  56. <text class="menu-text">案例授权</text>
  57. <text class="menu-arrow">›</text>
  58. </view>
  59. <view class="menu-item" @click="goTo('/pages/verify/index')">
  60. <text class="menu-icon">🎓</text>
  61. <text class="menu-text">校友信息</text>
  62. <text class="menu-arrow">›</text>
  63. </view>
  64. </view>
  65. <view class="course-entry" @click="switchToTab('/pages/course/index')">
  66. <text class="course-entry-icon">📖</text>
  67. <view class="course-entry-text">
  68. <text class="course-entry-title">课程内容</text>
  69. <text class="course-entry-sub">课前资料 · 小组 · 行动计划 · 积分榜 等请前往</text>
  70. </view>
  71. <text class="course-entry-arrow">›</text>
  72. </view>
  73. <button v-if="isLoggedIn" class="logout-btn" @click="handleLogout">退出登录</button>
  74. <button v-else class="logout-btn login-entry" @click="goLogin">点击登录</button>
  75. </view>
  76. </template>
  77. <script>
  78. import { getMyCert, getMyCoupons, redeemCoupon } from '@/utils/api.js'
  79. export default {
  80. data() {
  81. return {
  82. certLoading: true,
  83. cert: {},
  84. coupons: [],
  85. redeemingId: 0
  86. }
  87. },
  88. computed: {
  89. isLoggedIn() {
  90. return this.$store.getters.isLoggedIn
  91. },
  92. name() {
  93. var stored = uni.getStorageSync('userInfo')
  94. var realName = this.$store.state.name || stored && stored.name || ''
  95. if (realName) return realName
  96. // 未填写真实姓名前,用微信昵称展示
  97. return this.$store.state.nickname || stored && stored.nickname || '未登录'
  98. },
  99. roleLabel() {
  100. var r = this.$store.state.role || 'student'
  101. var map = { student: '学员', admin: '管理员' }
  102. return map[r] || r
  103. },
  104. verifyLabel() {
  105. var v = this.$store.state.alumniVerify
  106. var map = { accepted: '已通过', pending: '待审核', rejected: '未通过' }
  107. return map[v] || v || '未校验'
  108. },
  109. verifyClass() {
  110. var v = this.$store.state.alumniVerify
  111. return v === 'accepted' ? 'verify-pass' : (v === 'pending' ? 'verify-pending' : 'verify-fail')
  112. },
  113. certDoneCount() {
  114. var items = this.cert.items || []
  115. var done = 0
  116. for (var i = 0; i < items.length; i++) {
  117. if (items[i].ok) done++
  118. }
  119. return done
  120. }
  121. },
  122. onShow() {
  123. // 未登录不请求个人数据(卡券/证书接口需登录态,避免 401 误触发登录过期弹窗)
  124. if (!this.isLoggedIn) return
  125. this.loadCert()
  126. this.loadCoupons()
  127. },
  128. methods: {
  129. goLogin() {
  130. // 未登录入口:回首页并触发登录浮层
  131. uni.switchTab({ url: '/pages/index/index' })
  132. setTimeout(function() {
  133. uni.$emit('showLoginSheet', {})
  134. }, 400)
  135. },
  136. goTo(url) {
  137. uni.navigateTo({ url: url })
  138. },
  139. switchToTab(url) {
  140. uni.switchTab({ url: url })
  141. },
  142. loadCert() {
  143. var self = this
  144. self.certLoading = true
  145. getMyCert().then(function(resp) {
  146. self.cert = resp.data || {}
  147. }).catch(function() {
  148. self.cert = {}
  149. }).finally(function() {
  150. self.certLoading = false
  151. })
  152. },
  153. loadCoupons() {
  154. var self = this
  155. getMyCoupons().then(function(resp) {
  156. self.coupons = resp.data || []
  157. }).catch(function() {})
  158. },
  159. copyCertNo() {
  160. var certNo = this.cert.certNo || ''
  161. uni.setClipboardData({
  162. data: certNo,
  163. success: function() {
  164. uni.showToast({ title: '已复制', icon: 'success' })
  165. }
  166. })
  167. },
  168. couponStatusText(c) {
  169. var map = { unused: '未使用', used: '已使用', expired: '已过期' }
  170. return map[c.status] || c.status
  171. },
  172. redeem(c) {
  173. var self = this
  174. if (self.redeemingId === c.id) return
  175. uni.showModal({
  176. title: '核销卡券',
  177. content: '确定核销卡券 ' + (c.code || '') + ' 吗?',
  178. success: function(res) {
  179. if (!res.confirm) return
  180. self.redeemingId = c.id
  181. redeemCoupon({ id: c.id }).then(function() {
  182. uni.showToast({ title: '核销成功', icon: 'success' })
  183. self.loadCoupons()
  184. }).catch(function(err) {
  185. uni.showToast({ title: (err && err.message) || '核销失败', icon: 'none' })
  186. }).finally(function() {
  187. self.redeemingId = 0
  188. })
  189. }
  190. })
  191. },
  192. handleLogout() {
  193. var self = this
  194. uni.showModal({
  195. title: '确认退出',
  196. content: '确定要退出登录吗?',
  197. success: function(res) {
  198. if (res.confirm) {
  199. self.$store.commit('logout')
  200. // 登录页已下线,退出后回首页(首页展示点击登录入口)
  201. uni.reLaunch({ url: '/pages/index/index' })
  202. }
  203. }
  204. })
  205. }
  206. }
  207. }
  208. </script>
  209. <style scoped>
  210. .mine-page { min-height: 100vh; background: #F5F5F5; padding: 24rpx 32rpx; }
  211. .profile-card { display: flex; align-items: center; background: linear-gradient(135deg, #F97316, #EA580C); border-radius: 16rpx; padding: 40rpx 32rpx; margin-bottom: 24rpx; }
  212. .avatar { width: 100rpx; height: 100rpx; border-radius: 50rpx; background: rgba(255,255,255,0.25); display: flex; align-items: center; justify-content: center; font-size: 56rpx; margin-right: 24rpx; flex-shrink: 0; }
  213. .profile-info { flex: 1; }
  214. .profile-name { display: block; font-size: 36rpx; font-weight: 700; color: #FFF; margin-bottom: 8rpx; }
  215. .profile-role { display: block; font-size: 26rpx; color: rgba(255,255,255,0.85); margin-bottom: 4rpx; }
  216. .profile-verify { display: block; font-size: 24rpx; padding: 4rpx 16rpx; border-radius: 6rpx; margin-top: 8rpx; }
  217. .verify-pass { background: rgba(34,197,94,0.2); color: #86EFAC; }
  218. .verify-pending { background: rgba(255,183,77,0.2); color: #FFD54F; }
  219. .verify-fail { background: rgba(239,83,80,0.2); color: #E57373; }
  220. .section-card { background: #FFF; border-radius: 16rpx; padding: 28rpx 32rpx; margin-bottom: 24rpx; }
  221. .section-title { display: block; font-size: 30rpx; font-weight: 700; color: #1E293B; margin-bottom: 16rpx; }
  222. .empty-text { font-size: 26rpx; color: #94A3B8; text-align: center; padding: 24rpx 0; }
  223. .cert-ok { display: flex; flex-direction: column; align-items: center; padding: 16rpx 0; }
  224. .cert-no { font-size: 32rpx; font-weight: 700; color: #F97316; font-family: monospace; margin-bottom: 12rpx; }
  225. .cert-tip { font-size: 26rpx; color: #22C55E; margin-bottom: 20rpx; }
  226. .mini-btn { width: 240rpx; height: 64rpx; line-height: 64rpx; background: #F97316; color: #FFF; font-size: 26rpx; border-radius: 32rpx; border: none; padding: 0; text-align: center; }
  227. .mini-btn:active { opacity: 0.85; }
  228. .cert-progress { display: block; font-size: 26rpx; color: #64748B; margin-bottom: 16rpx; }
  229. .cert-items { }
  230. .cert-item { display: flex; align-items: center; padding: 10rpx 0; }
  231. .cert-icon { font-size: 28rpx; margin-right: 12rpx; }
  232. .cert-label { font-size: 26rpx; color: #1E293B; }
  233. .coupon-list { }
  234. .coupon-item { display: flex; justify-content: space-between; align-items: center; padding: 20rpx 0; border-bottom: 1rpx solid #F1F5F9; }
  235. .coupon-info { display: flex; align-items: center; flex-wrap: wrap; flex: 1; margin-right: 16rpx; }
  236. .coupon-code { font-size: 24rpx; color: #64748B; font-family: monospace; margin-right: 16rpx; }
  237. .coupon-status { font-size: 22rpx; padding: 4rpx 12rpx; border-radius: 6rpx; }
  238. .coupon-status.unused { background: #F0FDF4; color: #22C55E; }
  239. .coupon-status.used { background: #F1F5F9; color: #94A3B8; }
  240. .coupon-status.expired { background: #FEF2F2; color: #EF4444; }
  241. .redeem-btn { font-size: 26rpx; color: #F97316; font-weight: 600; padding: 8rpx 24rpx; border: 2rpx solid #FED7AA; border-radius: 28rpx; }
  242. .redeem-btn:active { background: #FFF7ED; }
  243. .menu-card { background: #FFF; border-radius: 16rpx; overflow: hidden; margin-bottom: 32rpx; }
  244. .menu-item { display: flex; align-items: center; padding: 28rpx 32rpx; border-bottom: 1rpx solid #F1F5F9; }
  245. .menu-item:active { background: #F8FAFC; }
  246. .menu-icon { font-size: 36rpx; margin-right: 20rpx; }
  247. .menu-text { flex: 1; font-size: 30rpx; color: #1E293B; }
  248. .menu-arrow { font-size: 32rpx; color: #CBD5E1; }
  249. .course-entry { display: flex; align-items: center; background: #FFF; border-radius: 16rpx; padding: 28rpx 32rpx; margin-bottom: 32rpx; }
  250. .course-entry:active { background: #F8FAFC; }
  251. .course-entry-icon { font-size: 44rpx; margin-right: 20rpx; }
  252. .course-entry-text { flex: 1; display: flex; flex-direction: column; }
  253. .course-entry-title { font-size: 30rpx; font-weight: 600; color: #1E293B; margin-bottom: 6rpx; }
  254. .course-entry-sub { font-size: 24rpx; color: #64748B; }
  255. .course-entry-arrow { font-size: 36rpx; color: #CBD5E1; }
  256. .logout-btn { width: 100%; height: 88rpx; line-height: 88rpx; background: #FFF; color: #EF5350; font-size: 30rpx; font-weight: 500; border-radius: 16rpx; border: 2rpx solid #FEE2E2; }
  257. .logout-btn:active { opacity: 0.85; }
  258. </style>