index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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. <!-- 【新增】双身份入口:健康服务工作台入口(命中家政/服务人员角色或已建档时展示,tabBar 保持 4 tab 不变) -->
  12. <IdentityGateCard
  13. :roles="userRoles"
  14. :has-profile="hasHealthProfile"
  15. @enter="goPractitioner"
  16. />
  17. <!-- 【新增】跨小程序合并提示卡片(同一微信开放平台账号跨小程序时展示) -->
  18. <view v-if="crossProgramMerge" class="merge-notice">
  19. <text class="merge-icon">🔗</text>
  20. <text class="merge-text">该账号已与浠艾福账号关联</text>
  21. <text class="merge-sub">您在浠艾福的能量值和会员等级已同步</text>
  22. </view>
  23. <view class="section-card">
  24. <text class="section-title">🎓 完课证书</text>
  25. <LoadingSkeleton v-if="certLoading" :rows="2" />
  26. <ErrorState v-else-if="certError" message="证书信息加载失败" @retry="loadCert" />
  27. <view v-else-if="cert.eligible && cert.certNo" class="cert-ok">
  28. <text class="cert-no">{{ cert.certNo }}</text>
  29. <text class="cert-tip">恭喜完成离场验收全部 6 项!</text>
  30. <button class="mini-btn" @click="copyCertNo">复制证书号</button>
  31. <view class="cert-verify-box">
  32. <view class="verify-input-group">
  33. <input class="verify-input" v-model="verifyInput" placeholder="请输入证书编号查验" />
  34. <button class="verify-btn" @click="doVerify" :disabled="verifying">
  35. {{ verifying ? '查验中' : '查验' }}
  36. </button>
  37. </view>
  38. <text v-if="verifyResult" class="verify-result" :class="verifyResult.valid ? 'res-valid' : 'res-invalid'">
  39. {{ verifyResult.valid ? '有效证书:' + verifyResult.certNo + '(持有人 ' + verifyResult.holderName + ')' : '未查询到该证书编号' }}
  40. </text>
  41. </view>
  42. </view>
  43. <view v-else-if="cert.items && cert.items.length">
  44. <text class="cert-progress">已完成 {{ certDoneCount }}/6 项</text>
  45. <view class="cert-items">
  46. <view class="cert-item" v-for="(it, idx) in cert.items" :key="idx">
  47. <text class="cert-icon">{{ it.ok ? '✅' : '⬜' }}</text>
  48. <text class="cert-label">{{ it.label }}</text>
  49. </view>
  50. </view>
  51. </view>
  52. <view v-else class="empty-text">暂无证书信息,完成 6 项离场验收后可领取</view>
  53. </view>
  54. <view class="section-card" @click="goBadgeWall">
  55. <text class="section-title">🎖 成长地图</text>
  56. <text class="section-sub">徽章墙 · 段位成长 · 荣誉可晒</text>
  57. </view>
  58. <view class="section-card">
  59. <text class="section-title">🎟️ 卡券核销</text>
  60. <LoadingSkeleton v-if="couponLoading" :rows="2" />
  61. <ErrorState v-else-if="couponError" message="卡券加载失败" @retry="loadCoupons" />
  62. <EmptyState v-else-if="coupons.length === 0" icon="🎫" title="暂无卡券" desc="获取到的卡券会展示在这里" />
  63. <view v-else class="coupon-list">
  64. <view class="coupon-item" v-for="(c, idx) in coupons" :key="idx">
  65. <view class="coupon-info">
  66. <text class="coupon-code">{{ c.code }}</text>
  67. <text class="coupon-status" :class="c.status">{{ couponStatusText(c) }}</text>
  68. </view>
  69. <text v-if="c.status === 'unused'" class="redeem-btn" @click="redeem(c)">核销</text>
  70. </view>
  71. </view>
  72. </view>
  73. <view class="menu-card">
  74. <view class="menu-item" @click="goMember">
  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/enroll/list')">
  80. <text class="menu-icon">🎫</text>
  81. <text class="menu-text">报名中心</text>
  82. <text class="menu-arrow">›</text>
  83. </view>
  84. <view class="menu-item" @click="goTo('/pages/group-order/index')">
  85. <text class="menu-icon">👨‍👩‍👧‍👦</text>
  86. <text class="menu-text">团报</text>
  87. <text class="menu-arrow">›</text>
  88. </view>
  89. <view class="menu-item" @click="goTo('/pages/case/index')">
  90. <text class="menu-icon">📋</text>
  91. <text class="menu-text">案例授权</text>
  92. <text class="menu-arrow">›</text>
  93. </view>
  94. <view class="menu-item" @click="goTo('/pages/verify/index')">
  95. <text class="menu-icon">🎓</text>
  96. <text class="menu-text">校友信息</text>
  97. <text class="menu-arrow">›</text>
  98. </view>
  99. <view class="menu-item" @click="goCfc">
  100. <text class="menu-icon">🏡</text>
  101. <text class="menu-text">进入成长家庭</text>
  102. <text class="menu-arrow">›</text>
  103. </view>
  104. </view>
  105. <view class="course-entry" @click="switchToTab('/pages/course/index')">
  106. <text class="course-entry-icon">📖</text>
  107. <view class="course-entry-text">
  108. <text class="course-entry-title">课程内容</text>
  109. <text class="course-entry-sub">课前资料 · 小组 · 行动计划 · 积分榜 等请前往</text>
  110. </view>
  111. <text class="course-entry-arrow">›</text>
  112. </view>
  113. <button v-if="isLoggedIn" class="logout-btn" @click="handleLogout">退出登录</button>
  114. <button v-else class="logout-btn login-entry" @click="goLogin">点击登录</button>
  115. </view>
  116. </template>
  117. <script>
  118. import { getMyCert, getMyCoupons, redeemCoupon, verifyCert, getMyBadges } from '@/utils/api.js'
  119. import { jumpToCfc } from '@/utils/sso.js'
  120. import IdentityGateCard from '@/components/identity-gate-card.vue'
  121. import LoadingSkeleton from '@/components/loading-skeleton.vue'
  122. import ErrorState from '@/components/error-state.vue'
  123. import EmptyState from '@/components/empty-state.vue'
  124. export default {
  125. components: { IdentityGateCard, LoadingSkeleton, ErrorState, EmptyState },
  126. data() {
  127. return {
  128. certLoading: true,
  129. certError: false,
  130. cert: {},
  131. coupons: [],
  132. couponLoading: false,
  133. couponError: false,
  134. redeemingId: 0,
  135. verifyInput: '',
  136. verifyResult: null,
  137. verifying: false,
  138. crossProgramMerge: false,
  139. hasHealthProfile: false
  140. }
  141. },
  142. computed: {
  143. isLoggedIn() {
  144. return this.$store.getters.isLoggedIn
  145. },
  146. name() {
  147. var stored = uni.getStorageSync('userInfo')
  148. var realName = this.$store.state.name || stored && stored.name || ''
  149. if (realName) return realName
  150. // 未填写真实姓名前,用微信昵称展示
  151. return this.$store.state.nickname || stored && stored.nickname || '未登录'
  152. },
  153. roleLabel() {
  154. var r = this.$store.state.role || 'student'
  155. var map = { student: '学员', admin: '管理员' }
  156. return map[r] || r
  157. },
  158. verifyLabel() {
  159. var v = this.$store.state.alumniVerify
  160. var map = { accepted: '已通过', pending: '待审核', rejected: '未通过' }
  161. return map[v] || v || '未校验'
  162. },
  163. verifyClass() {
  164. var v = this.$store.state.alumniVerify
  165. return v === 'accepted' ? 'verify-pass' : (v === 'pending' ? 'verify-pending' : 'verify-fail')
  166. },
  167. certDoneCount() {
  168. var items = this.cert.items || []
  169. var done = 0
  170. for (var i = 0; i < items.length; i++) {
  171. if (items[i].ok) done++
  172. }
  173. return done
  174. },
  175. // 健康服务身份判定:角色 ∈ {housekeeper, worker}(命中任一即由 IdentityGateCard 展示入口)
  176. userRoles() {
  177. var storedRole = uni.getStorageSync('role')
  178. var role = this.$store.state.role || storedRole || 'student'
  179. return [role]
  180. }
  181. },
  182. onShow() {
  183. // 未登录不请求个人数据(卡券/证书接口需登录态,避免 401 误触发登录过期弹窗)
  184. if (!this.isLoggedIn) return
  185. // 从 storage 恢复跨程序合并状态
  186. var merge = uni.getStorageSync('crossProgramMerge')
  187. if (merge !== undefined) {
  188. this.crossProgramMerge = merge === true || merge === 'true'
  189. }
  190. // 恢复健康服务建档标记(由 practitioner/index 成功建档后写入),驱动双身份入口
  191. var hsp = uni.getStorageSync('healthServiceProfile')
  192. this.hasHealthProfile = hsp === true || hsp === 'true'
  193. this.loadCert()
  194. this.loadCoupons()
  195. },
  196. methods: {
  197. goPractitioner() {
  198. uni.navigateTo({ url: '/pages/practitioner/index' })
  199. },
  200. goLogin() {
  201. // 未登录入口:回首页并触发登录浮层
  202. uni.switchTab({ url: '/pages/index/index' })
  203. setTimeout(function() {
  204. uni.$emit('showLoginSheet', {})
  205. }, 400)
  206. },
  207. goTo(url) {
  208. uni.navigateTo({ url: url })
  209. },
  210. goMember() {
  211. uni.navigateTo({ url: '/pages/member/index' })
  212. },
  213. goCfc() {
  214. jumpToCfc()
  215. },
  216. goBadgeWall() {
  217. uni.navigateTo({ url: '/pages/badge/index' })
  218. },
  219. switchToTab(url) {
  220. uni.switchTab({ url: url })
  221. },
  222. loadCert() {
  223. var self = this
  224. self.certLoading = true
  225. self.certError = false
  226. getMyCert().then(function(resp) {
  227. self.cert = resp.data || {}
  228. }).catch(function() {
  229. self.cert = {}
  230. self.certError = true
  231. }).finally(function() {
  232. self.certLoading = false
  233. })
  234. },
  235. loadCoupons() {
  236. var self = this
  237. self.couponLoading = true
  238. self.couponError = false
  239. getMyCoupons().then(function(resp) {
  240. self.coupons = resp.data || []
  241. }).catch(function() {
  242. self.couponError = true
  243. }).finally(function() {
  244. self.couponLoading = false
  245. })
  246. },
  247. copyCertNo() {
  248. var certNo = this.cert.certNo || ''
  249. uni.setClipboardData({
  250. data: certNo,
  251. success: function() {
  252. uni.showToast({ title: '已复制', icon: 'success' })
  253. }
  254. })
  255. },
  256. doVerify() {
  257. var self = this
  258. var certNo = self.verifyInput.trim()
  259. if (!certNo) {
  260. uni.showToast({ title: '请输入证书编号', icon: 'none' })
  261. return
  262. }
  263. self.verifying = true
  264. self.verifyResult = null
  265. verifyCert(certNo).then(function(resp) {
  266. self.verifyResult = resp.data || { valid: false }
  267. }).catch(function(err) {
  268. uni.showToast({ title: (err && err.message) || '查验失败', icon: 'none' })
  269. }).finally(function() {
  270. self.verifying = false
  271. })
  272. },
  273. couponStatusText(c) {
  274. var map = { unused: '未使用', used: '已使用', expired: '已过期' }
  275. return map[c.status] || c.status
  276. },
  277. redeem(c) {
  278. var self = this
  279. if (self.redeemingId === c.id) return
  280. uni.showModal({
  281. title: '核销卡券',
  282. content: '确定核销卡券 ' + (c.code || '') + ' 吗?',
  283. success: function(res) {
  284. if (!res.confirm) return
  285. self.redeemingId = c.id
  286. redeemCoupon({ id: c.id }).then(function() {
  287. uni.showToast({ title: '核销成功', icon: 'success' })
  288. self.loadCoupons()
  289. }).catch(function(err) {
  290. uni.showToast({ title: (err && err.message) || '核销失败', icon: 'none' })
  291. }).finally(function() {
  292. self.redeemingId = 0
  293. })
  294. }
  295. })
  296. },
  297. handleLogout() {
  298. var self = this
  299. uni.showModal({
  300. title: '确认退出',
  301. content: '确定要退出登录吗?',
  302. success: function(res) {
  303. if (res.confirm) {
  304. self.$store.commit('logout')
  305. // 登录页已下线,退出后回首页(首页展示点击登录入口)
  306. uni.reLaunch({ url: '/pages/index/index' })
  307. }
  308. }
  309. })
  310. }
  311. }
  312. }
  313. </script>
  314. <style scoped>
  315. .mine-page { min-height: 100vh; background: #F5FAFE; padding: 24rpx 32rpx; }
  316. .profile-card { display: flex; align-items: center; background: linear-gradient(135deg, #2E6FA8, #1F4E79); border-radius: 16rpx; padding: 40rpx 32rpx; margin-bottom: 24rpx; }
  317. .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; }
  318. .profile-info { flex: 1; }
  319. .profile-name { display: block; font-size: 36rpx; font-weight: 700; color: #FFF; margin-bottom: 8rpx; }
  320. .profile-role { display: block; font-size: 26rpx; color: rgba(255,255,255,0.85); margin-bottom: 4rpx; }
  321. .profile-verify { display: block; font-size: 24rpx; padding: 4rpx 16rpx; border-radius: 6rpx; margin-top: 8rpx; }
  322. .verify-pass { background: rgba(34,197,94,0.2); color: #0E8A4F; }
  323. .verify-pending { background: rgba(255,183,77,0.2); color: #FFB020; }
  324. .verify-fail { background: rgba(239,83,80,0.2); color: #E26B5A; }
  325. .section-card { background: #FFF; border-radius: 16rpx; padding: 28rpx 32rpx; margin-bottom: 24rpx; }
  326. .section-title { display: block; font-size: 30rpx; font-weight: 700; color: #1E3A5F; margin-bottom: 16rpx; }
  327. .section-sub { display: block; font-size: 24rpx; color: #6B7B8C; margin-top: 8rpx; }
  328. .empty-text { font-size: 26rpx; color: #6B7B8C; text-align: center; padding: 24rpx 0; }
  329. .cert-ok { display: flex; flex-direction: column; align-items: center; padding: 16rpx 0; }
  330. .cert-no { font-size: 32rpx; font-weight: 700; color: #2E6FA8; font-family: monospace; margin-bottom: 12rpx; }
  331. .cert-tip { font-size: 26rpx; color: #0E8A4F; margin-bottom: 20rpx; }
  332. .mini-btn { width: 240rpx; height: 64rpx; line-height: 64rpx; background: #2E6FA8; color: #FFF; font-size: 26rpx; border-radius: 32rpx; border: none; padding: 0; text-align: center; }
  333. .mini-btn:active { opacity: 0.85; }
  334. .cert-verify-box { width: 100%; margin-top: 32rpx; padding-top: 32rpx; border-top: 1rpx solid #E3ECF4; display: flex; flex-direction: column; align-items: center; }
  335. .verify-input-group { display: flex; width: 100%; max-width: 500rpx; align-items: center; margin-bottom: 16rpx; }
  336. .verify-input { flex: 1; height: 64rpx; background: #F5FAFE; border: 2rpx solid #E3ECF4; border-radius: 8rpx; padding: 0 20rpx; font-size: 26rpx; color: #1E3A5F; }
  337. .verify-btn { width: 120rpx; height: 64rpx; line-height: 64rpx; background: #2E6FA8; color: #FFF; font-size: 26rpx; border-radius: 8rpx; border: none; padding: 0; margin-left: 16rpx; }
  338. .verify-btn:disabled { background: #C3D2DF; }
  339. .verify-result { font-size: 26rpx; text-align: center; padding: 12rpx 24rpx; border-radius: 8rpx; background: #F5FAFE; }
  340. .res-valid { color: #0E8A4F; border: 1rpx solid #E6F6EE; }
  341. .res-invalid { color: #6B7B8C; border: 1rpx solid #E3ECF4; }
  342. .cert-progress { display: block; font-size: 26rpx; color: #3B5A78; margin-bottom: 16rpx; }
  343. .cert-items { }
  344. .cert-item { display: flex; align-items: center; padding: 10rpx 0; }
  345. .cert-icon { font-size: 28rpx; margin-right: 12rpx; }
  346. .cert-label { font-size: 26rpx; color: #1E3A5F; }
  347. .coupon-list { }
  348. .coupon-item { display: flex; justify-content: space-between; align-items: center; padding: 20rpx 0; border-bottom: 1rpx solid #E3ECF4; }
  349. .coupon-info { display: flex; align-items: center; flex-wrap: wrap; flex: 1; margin-right: 16rpx; }
  350. .coupon-code { font-size: 24rpx; color: #3B5A78; font-family: monospace; margin-right: 16rpx; }
  351. .coupon-status { font-size: 22rpx; padding: 4rpx 12rpx; border-radius: 6rpx; }
  352. .coupon-status.unused { background: #E6F6EE; color: #0E8A4F; }
  353. .coupon-status.used { background: #E3ECF4; color: #6B7B8C; }
  354. .coupon-status.expired { background: #FDE8E8; color: #C0392B; }
  355. .redeem-btn { font-size: 26rpx; color: #2E6FA8; font-weight: 600; padding: 8rpx 24rpx; border: 2rpx solid #C3D2DF; border-radius: 28rpx; }
  356. .redeem-btn:active { background: #E8F3FC; }
  357. .menu-card { background: #FFF; border-radius: 16rpx; overflow: hidden; margin-bottom: 32rpx; }
  358. .menu-item { display: flex; align-items: center; padding: 28rpx 32rpx; border-bottom: 1rpx solid #E3ECF4; }
  359. .menu-item:active { background: #F5FAFE; }
  360. .menu-icon { font-size: 36rpx; margin-right: 20rpx; }
  361. .menu-text { flex: 1; font-size: 30rpx; color: #1E3A5F; }
  362. .menu-arrow { font-size: 32rpx; color: #C3D2DF; }
  363. .course-entry { display: flex; align-items: center; background: #FFF; border-radius: 16rpx; padding: 28rpx 32rpx; margin-bottom: 32rpx; }
  364. .course-entry:active { background: #F5FAFE; }
  365. .course-entry-icon { font-size: 44rpx; margin-right: 20rpx; }
  366. .course-entry-text { flex: 1; display: flex; flex-direction: column; }
  367. .course-entry-title { font-size: 30rpx; font-weight: 600; color: #1E3A5F; margin-bottom: 6rpx; }
  368. .course-entry-sub { font-size: 24rpx; color: #3B5A78; }
  369. .course-entry-arrow { font-size: 36rpx; color: #C3D2DF; }
  370. .logout-btn { width: 100%; height: 88rpx; line-height: 88rpx; background: #FFF; color: #C0392B; font-size: 30rpx; font-weight: 500; border-radius: 16rpx; border: 2rpx solid #FDE8E8; }
  371. .logout-btn:active { opacity: 0.85; }
  372. /* 跨小程序合并提示 */
  373. .merge-notice { display: flex; align-items: center; background: #E8F3FC; border: 2rpx solid #C3D2DF; border-radius: 12rpx; padding: 24rpx 28rpx; margin-bottom: 24rpx; }
  374. .merge-icon { font-size: 40rpx; margin-right: 16rpx; }
  375. .merge-text { display: block; font-size: 26rpx; font-weight: 600; color: #B9770E; }
  376. .merge-sub { display: block; font-size: 22rpx; color: #B9770E; margin-top: 4rpx; }
  377. /* 跨小程序手动绑定入口 */
  378. .bind-card { background: #FFF; border-radius: 16rpx; padding: 28rpx 32rpx; margin-bottom: 24rpx; display: flex; flex-direction: column; }
  379. .bind-title { font-size: 30rpx; font-weight: 600; color: #1E3A5F; margin-bottom: 8rpx; }
  380. .bind-tip { font-size: 22rpx; color: #3B5A78; margin-bottom: 20rpx; }
  381. .bind-input { height: 76rpx; background: #E3ECF4; border-radius: 8rpx; padding: 0 24rpx; font-size: 28rpx; color: #1E3A5F; margin-bottom: 20rpx; }
  382. .bind-btn { width: 100%; height: 80rpx; line-height: 80rpx; background: #2E6FA8; color: #FFF; font-size: 30rpx; font-weight: 600; border-radius: 12rpx; }
  383. .bind-btn[disabled] { opacity: 0.6; }
  384. </style>