index.vue 14 KB

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