const auth = require('../../utils/auth'); const competition = require('../../utils/competition'); const { ROLE, ROLE_META, getProfileRole, updateEventTabBar } = require('../../utils/role'); function normalizeAuthStatus(v) { if (v == null || v === '') return 0; const n = Number(v); return Number.isNaN(n) ? 0 : n; } /** 0 未认证 | 1 审核中 | 2 审核通过 | 3 审核失败 | 4 已取消 */ function authStatusText(status) { const map = { 0: '未认证', 1: '审核中', 2: '审核通过', 3: '审核失败', 4: '已取消' }; return map[normalizeAuthStatus(status)] || '未认证'; } /** 裁判资料审核状态:0 待提交 | 1 待审核 | 2 通过 | 3 拒绝 | 4 已取消 */ function refereeAuditStatusText(status) { const map = { 0: '未认证', 1: '待审核', 2: '审核通过', 3: '审核未通过', 4: '已取消' }; return map[normalizeAuthStatus(status)] || '未认证'; } function authDescText(isReferee, status, remark) { const st = normalizeAuthStatus(status); if (!isReferee) return st === 2 ? '已完成实名认证' : '点击进行身份认证'; if (st === 1) return '裁判资料审核中,请耐心等待'; if (st === 2) return '认证已通过,可报名赛事执裁'; if (st === 3) return remark ? `审核未通过:${remark}` : '审核未通过,点击修改后重新提交'; if (st === 4) return '认证已取消,点击重新提交'; return '完成认证后可参与赛事执裁'; } function maskPhone(phone) { if (!phone || phone.length < 7) return phone || ''; return phone.substring(0, 3) + '****' + phone.substring(7); } Page({ data: { loggedIn: false, profile: {}, maskedPhone: '', authStatus: 0, authStatusText: '未认证', authDesc: '点击进行身份认证', role: ROLE.PARTICIPANT, roleLabel: ROLE_META.participant.label, isParticipant: true, isReferee: false, isChecker: false }, onShow() { const accessToken = wx.getStorageSync('accessToken') || ''; if (!accessToken) { updateEventTabBar(ROLE.PARTICIPANT); this.setData({ loggedIn: false, profile: {}, maskedPhone: '', authStatus: 0, authStatusText: '未认证', authDesc: '点击进行身份认证' }); return; } this.setData({ loggedIn: true }); this.loadProfile(); }, onPullDownRefresh() { this.loadProfile().finally(() => wx.stopPullDownRefresh()); }, loadProfile() { return auth .fetchMyProfile() .then((profile) => { const p = profile || {}; const st = normalizeAuthStatus(p.authStatus != null ? p.authStatus : p.AuthStatus); const phone = p.mobile || p.phone || ''; const role = getProfileRole(p); const roleMeta = ROLE_META[role] || ROLE_META.participant; updateEventTabBar(role); this.setData({ profile: p, maskedPhone: maskPhone(phone), authStatusText: authStatusText(st), authStatus: st, authDesc: authDescText(role === ROLE.REFEREE, st, ''), role, roleLabel: roleMeta.label, isParticipant: role === ROLE.PARTICIPANT, isReferee: role === ROLE.REFEREE, isChecker: role === ROLE.CHECKER }); // 裁判的认证入口指向裁判资料页,徽章须显示裁判资料的审核状态, if (role === ROLE.REFEREE) return this.loadRefereeAuditStatus(); return null; }) .catch(() => {}); }, loadRefereeAuditStatus() { return competition .fetchRefereeProfile() .then((p) => { const st = normalizeAuthStatus(p && p.auditStatus); this.setData({ authStatus: st, authStatusText: (p && p.auditStatusText) || refereeAuditStatusText(st), authDesc: authDescText(true, st, (p && p.auditRemark) || '') }); }) .catch((err) => { wx.showToast({ title: (err && err.message) || '裁判认证状态加载失败', icon: 'none' }); }); }, goToLogin() { wx.navigateTo({ url: '/subpackages/mine/login/login' }); }, goToPoints() { wx.navigateTo({ url: '/subpackages/mine/points/points' }); }, goToCert() { wx.navigateTo({ url: '/subpackages/mine/cert/cert' }); }, goToRecords() { wx.navigateTo({ url: '/subpackages/mine/records/records' }); }, goToAuth() { wx.navigateTo({ url: this.data.isReferee ? '/subpackages/mine/referee-profile/referee-profile' : '/subpackages/mine/auth/auth' }); }, goToOrders() { wx.navigateTo({ url: '/subpackages/mine/order/order' }); }, goToTeam() { wx.navigateTo({ url: '/subpackages/mine/team/team' }); }, goToScores() { wx.navigateTo({ url: '/subpackages/mine/scores/scores' }); }, goToCheckin() { wx.navigateTo({ url: '/subpackages/mine/checkin/checkin' }); }, onLogout() { wx.showModal({ title: '提示', content: '确定要退出登录吗?', confirmText: '退出', confirmColor: '#e53935', success: (res) => { if (!res.confirm) return; wx.clearStorageSync(); updateEventTabBar(ROLE.PARTICIPANT); this.setData({ loggedIn: false, profile: {}, maskedPhone: '', authStatus: 0, authStatusText: '未认证', authDesc: '点击进行身份认证' }); } }); }, onChooseAvatar(e) { const tempFilePath = e.detail.avatarUrl; if (!tempFilePath) return; // 先展示本地预览 // this.setData({ 'profile.avatar': tempFilePath }); wx.showLoading({ title: '上传中...', mask: true }); auth .uploadFile(tempFilePath) .then((url) => { return auth.updateProfile({ "avatarUrl": url }).then(() => url); }) .then((url) => { this.setData({ 'profile.avatar': url }); wx.showToast({ title: '头像更新成功', icon: 'success' }); }) .catch((err) => { wx.showToast({ title: (err && err.message) || '头像更新失败', icon: 'none' }); // 回滚预览,重新加载 profile this.loadProfile(); }) .finally(() => { wx.hideLoading(); }); }, onFetchOpenId() { wx.login({ success: (res) => { console.log('res', res); } }); } });