107 lines
2.4 KiB
JavaScript
107 lines
2.4 KiB
JavaScript
const auth = require('../../utils/auth');
|
|
|
|
function authStatusText(status) {
|
|
const map = {
|
|
0: '未认证',
|
|
1: '已认证',
|
|
2: '审核中'
|
|
};
|
|
return map[status] || `状态${status}`;
|
|
}
|
|
|
|
Page({
|
|
data: {
|
|
loggedIn: false,
|
|
profile: null,
|
|
authStatusText: '-',
|
|
|
|
showAuthForm: false,
|
|
|
|
authForm: {
|
|
name: '',
|
|
mobile: '',
|
|
idCardNumber: ''
|
|
}
|
|
|
|
},
|
|
|
|
onShow() {
|
|
const accessToken = wx.getStorageSync('accessToken') || '';
|
|
if (!accessToken) {
|
|
this.setData({ loggedIn: false, profile: null, authStatusText: '-' });
|
|
return;
|
|
}
|
|
this.setData({ loggedIn: true });
|
|
this.loadProfile();
|
|
},
|
|
|
|
onPullDownRefresh() {
|
|
this.loadProfile().finally(() => wx.stopPullDownRefresh());
|
|
},
|
|
|
|
loadProfile() {
|
|
return auth
|
|
.fetchMyProfile()
|
|
.then((profile) => {
|
|
const p = profile || {};
|
|
const st = p && typeof p.authStatus === 'number' ? p.authStatus : 0;
|
|
this.setData({
|
|
profile: p,
|
|
authStatusText: authStatusText(st)
|
|
});
|
|
})
|
|
.catch(() => {});
|
|
},
|
|
|
|
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' });
|
|
},
|
|
|
|
toggleAuthForm() {
|
|
this.setData({ showAuthForm: !this.data.showAuthForm });
|
|
},
|
|
|
|
onAuthInput(e) {
|
|
const key = e.currentTarget.dataset.key;
|
|
this.setData({
|
|
authForm: {
|
|
...this.data.authForm,
|
|
[key]: e.detail.value
|
|
}
|
|
});
|
|
},
|
|
|
|
submitAuth() {
|
|
const { name, mobile, idCardNumber } = this.data.authForm;
|
|
if (!name) return wx.showToast({ title: '请输入姓名', icon: 'none' });
|
|
if (!mobile) return wx.showToast({ title: '请输入手机号', icon: 'none' });
|
|
if (!idCardNumber) return wx.showToast({ title: '请输入身份证号', icon: 'none' });
|
|
|
|
wx.showLoading({ title: '提交中...' });
|
|
auth
|
|
.submitMyAuth({ name, mobile, idCardNumber })
|
|
.then(() => {
|
|
wx.showToast({ title: '提交成功', icon: 'success' });
|
|
this.setData({ showAuthForm: false });
|
|
return this.loadProfile();
|
|
})
|
|
.catch(() => {
|
|
wx.showToast({ title: '提交失败', icon: 'none' });
|
|
})
|
|
.finally(() => wx.hideLoading());
|
|
}
|
|
});
|
|
|