diff --git a/pages/rights/rights.vue b/pages/rights/rights.vue index 9298b63..c1ce9aa 100644 --- a/pages/rights/rights.vue +++ b/pages/rights/rights.vue @@ -63,9 +63,9 @@ @@ -84,7 +84,7 @@ 可用权益数 - 10 + {{ rightsCount }} 个 @@ -172,6 +172,10 @@ data() { return { status: 'auth', + // xuchao: 权益概览三字段,首屏用缓存兜底,随后由服务端复查刷新 + expiresTime: uni.getStorageSync('expiresTime') || '', + rightsCount: uni.getStorageSync('rightsCount') || 0, + totalValueFen: uni.getStorageSync('totalValueFen') || 0, form: { realName: '', phone: '', @@ -199,6 +203,13 @@ checkLoading: false } }, + computed: { + // xuchao: 总权益价值分转元,整除去小数,否则保留两位 + totalValueText() { + const yuan = this.totalValueFen / 100 + return Number.isInteger(yuan) ? String(yuan) : yuan.toFixed(2) + } + }, onLoad(options) { if (options.status) { this.status = options.status @@ -238,10 +249,7 @@ phone: phone }).then(res => { if (res.errcode !== 0 || !res.data) return - uni.setStorageSync('isAuth', res.data.isAuth) - uni.setStorageSync('hasWin', res.data.hasWin) - uni.setStorageSync('cardNumber', res.data.cardNumber) - uni.setStorageSync('expiresTime', res.data.expiresTime) + this.applyEligibility(res.data) // xuchao: 服务端已认证则清除取消标记,后续按真实状态展示 if (res.data.isAuth) uni.removeStorageSync('authFlowStarted') const newStatus = res.data.isAuth ? (res.data.hasWin ? 'info' : 'noWin') : 'auth' @@ -253,12 +261,26 @@ } }) }, + // xuchao: 资格查询结果统一写入缓存并回填页面(到期时间/总权益价值/可用权益数) + applyEligibility(data) { + uni.setStorageSync('isAuth', data.isAuth) + uni.setStorageSync('hasWin', data.hasWin) + uni.setStorageSync('cardNumber', data.cardNumber) + uni.setStorageSync('expiresTime', data.expiresTime) + uni.setStorageSync('rightsCount', data.rightsCount || 0) + uni.setStorageSync('totalValueFen', data.totalValueFen || 0) + this.expiresTime = data.expiresTime || '' + this.rightsCount = data.rightsCount || 0 + this.totalValueFen = data.totalValueFen || 0 + }, // xuchao: 认证取消/未通过:清理旧认证缓存并标记流程已发起,取消后应停留认证页 markAuthCanceled() { uni.removeStorageSync('isAuth') uni.removeStorageSync('hasWin') uni.removeStorageSync('cardNumber') uni.removeStorageSync('expiresTime') + uni.removeStorageSync('rightsCount') + uni.removeStorageSync('totalValueFen') uni.setStorageSync('authFlowStarted', true) }, checkAuthResult() { @@ -301,10 +323,7 @@ }).then(eRes => { console.log('eligibility res:', eRes) if (eRes.errcode === 0) { - uni.setStorageSync('isAuth', eRes.data.isAuth) - uni.setStorageSync('hasWin', eRes.data.hasWin) - uni.setStorageSync('cardNumber', eRes.data.cardNumber) - uni.setStorageSync('expiresTime', eRes.data.expiresTime) + this.applyEligibility(eRes.data) // xuchao: 认证成功,清除流程标记 uni.removeStorageSync('authFlowStarted') if (eRes.data.isAuth) {