182 lines
5.8 KiB
JavaScript
182 lines
5.8 KiB
JavaScript
/**
|
||
* 审核中页 U16 / H10(Phase 05 P05-T16)
|
||
*
|
||
* 重构要点(遵循 AGENTS.md 不变量):
|
||
* - 数据:userStore.fetchReviewStatus + verificationService.getStatus(并行)
|
||
* - 状态自检:onShow 读取 userStore.state.userState.profileReviewStatus,
|
||
* 若已 approved → reLaunch 首页;若 need_edit/rejected → redirectTo 审核驳回页
|
||
* (AGENTS 第 9 条:DB 是 Source of Truth,状态以服务端为准)
|
||
* - 路由:仅读 userState,不放宽 Required;只读展示,无修改入口
|
||
* - 帮助:底部提示联系平台工作人员
|
||
*/
|
||
const { userStore, appStore, getReviewRedirectPath } = require('../../stores');
|
||
const { verificationService } = require('../../services');
|
||
const { ROUTE, PROFILE_REVIEW } = require('../../constants');
|
||
|
||
// 审核步骤:1 已提交 → 2 审核中 → 3 审核完成
|
||
const REVIEW_STEPS = [
|
||
{ key: 'submitted', label: '提交资料', icon: '✓' },
|
||
{ key: 'reviewing', label: '人工审核', icon: '◉' },
|
||
{ key: 'done', label: '审核完成', icon: '○' },
|
||
];
|
||
|
||
Page({
|
||
data: {
|
||
statusBarHeight: 20,
|
||
navBarHeight: 44,
|
||
loading: true,
|
||
refreshing: false,
|
||
// 实名认证状态
|
||
verificationStatus: 'pending',
|
||
verificationLabel: '认证中',
|
||
verificationKind: 'warning',
|
||
// 资料审核状态
|
||
profileReviewStatus: PROFILE_REVIEW.PENDING,
|
||
profileReviewLabel: '审核中',
|
||
profileReviewKind: 'warning',
|
||
submittedAt: null,
|
||
reviewedAt: null,
|
||
// 步骤
|
||
steps: REVIEW_STEPS,
|
||
currentStepIndex: 1,
|
||
},
|
||
|
||
onLoad() {
|
||
this._initSystemInfo();
|
||
},
|
||
|
||
onShow() {
|
||
// 路由守卫:若审核状态已变化,引导至合适页面
|
||
// (用户可能在别的页面停留时被审核通过/驳回)
|
||
const redirect = getReviewRedirectPath();
|
||
if (redirect && redirect !== ROUTE.REVIEW.PENDING) {
|
||
// 状态变为 need_edit/rejected → 跳驳回页
|
||
wx.redirectTo({ url: redirect });
|
||
return;
|
||
}
|
||
if (!redirect) {
|
||
// 状态变为 approved → 跳首页
|
||
wx.reLaunch({ url: ROUTE.TAB.HOME });
|
||
return;
|
||
}
|
||
// 仍为 pending,正常展示
|
||
this.loadStatus();
|
||
},
|
||
|
||
_initSystemInfo() {
|
||
try {
|
||
const sysInfo = wx.getSystemInfoSync();
|
||
this.setData({
|
||
statusBarHeight: sysInfo.statusBarHeight || 20,
|
||
navBarHeight: 44,
|
||
});
|
||
} catch (e) { /* 使用默认值 */ }
|
||
},
|
||
|
||
// ============ 数据加载 ============
|
||
async loadStatus() {
|
||
this.setData({ loading: true });
|
||
try {
|
||
// 并行拉取资料审核态 + 实名认证态;任一失败不阻塞另一个
|
||
const [review, verification] = await Promise.all([
|
||
userStore.fetchReviewStatus().catch(() => null),
|
||
verificationService.getStatus().catch(() => null),
|
||
]);
|
||
|
||
const profileReviewStatus = (review && review.status) || PROFILE_REVIEW.PENDING;
|
||
|
||
// 取到最新状态后重新校验是否需要跳转(状态可能在审核中变为 approved/need_edit)
|
||
if (profileReviewStatus === PROFILE_REVIEW.APPROVED) {
|
||
wx.reLaunch({ url: ROUTE.TAB.HOME });
|
||
return;
|
||
}
|
||
if (profileReviewStatus === PROFILE_REVIEW.NEED_EDIT || profileReviewStatus === PROFILE_REVIEW.REJECTED) {
|
||
wx.redirectTo({ url: ROUTE.REVIEW.REJECTED });
|
||
return;
|
||
}
|
||
const submittedAt = (review && review.submittedAt) || null;
|
||
const reviewedAt = (review && review.reviewedAt) || null;
|
||
|
||
const verificationStatus = (verification && verification.status) || 'pending';
|
||
const verificationLabelMap = {
|
||
not_submitted: '未提交',
|
||
pending: '认证中',
|
||
approved: '已完成',
|
||
rejected: '未通过',
|
||
};
|
||
const verificationKindMap = {
|
||
not_submitted: 'disabled',
|
||
pending: 'warning',
|
||
approved: 'success',
|
||
rejected: 'danger',
|
||
};
|
||
|
||
const profileReviewLabelMap = {
|
||
not_submitted: '未提交',
|
||
pending: '审核中',
|
||
approved: '已通过',
|
||
need_edit: '需修改',
|
||
rejected: '未通过',
|
||
};
|
||
const profileReviewKindMap = {
|
||
not_submitted: 'disabled',
|
||
pending: 'warning',
|
||
approved: 'success',
|
||
need_edit: 'warning',
|
||
rejected: 'danger',
|
||
};
|
||
|
||
// 步骤索引:approved → 2(完成),pending → 1(审核中),其他 → 0
|
||
let currentStepIndex = 1;
|
||
if (profileReviewStatus === PROFILE_REVIEW.APPROVED) currentStepIndex = 2;
|
||
else if (profileReviewStatus === PROFILE_REVIEW.NOT_SUBMITTED) currentStepIndex = 0;
|
||
|
||
this.setData({
|
||
loading: false,
|
||
verificationStatus,
|
||
verificationLabel: verificationLabelMap[verificationStatus] || '认证中',
|
||
verificationKind: verificationKindMap[verificationStatus] || 'warning',
|
||
profileReviewStatus,
|
||
profileReviewLabel: profileReviewLabelMap[profileReviewStatus] || '审核中',
|
||
profileReviewKind: profileReviewKindMap[profileReviewStatus] || 'warning',
|
||
submittedAt,
|
||
reviewedAt,
|
||
currentStepIndex,
|
||
});
|
||
} catch (err) {
|
||
this.setData({ loading: false });
|
||
appStore.toastError(err, '加载失败');
|
||
}
|
||
},
|
||
|
||
// ============ 下拉刷新 ============
|
||
async onPullDownRefresh() {
|
||
// 先刷新 userState(确保 getReviewRedirectPath 读到最新状态)
|
||
try {
|
||
await userStore.fetchStatus();
|
||
} catch (e) { /* 不阻塞 */ }
|
||
await this.loadStatus();
|
||
wx.stopPullDownRefresh();
|
||
},
|
||
|
||
onRefresh() {
|
||
this.loadStatus();
|
||
},
|
||
|
||
// ============ 导航 ============
|
||
/**
|
||
* 查看我的资料:跳转"我的"Tab
|
||
* 不直接跳 profile-confirm,避免审核中再触发"提交审核"
|
||
*/
|
||
onViewProfile() {
|
||
wx.switchTab({ url: ROUTE.TAB.MINE });
|
||
},
|
||
|
||
/**
|
||
* 联系工作人员:跳转帮助中心
|
||
*/
|
||
onContactHelp() {
|
||
wx.navigateTo({ url: ROUTE.SETTINGS.HELP_CENTER });
|
||
},
|
||
});
|