index.vue 14 KB

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