马梓彭 b157e73eb2 新增检录进度页面
新增裁判认证页面
对接检录页面
对接成绩查询页面
2026-09-01 23:13:21 +08:00

137 lines
5.7 KiB
JavaScript

const auth = require('../../../utils/auth');
const competition = require('../../../utils/competition');
const PHONE_RE = /^1[3-9]\d{9}$/;
Page({
data: {
loading: true,
submitting: false,
uploading: false,
profile: {},
levels: [],
levelNames: [],
levelIndex: 0,
roleOptions: [],
selectedRoles: [],
name: '',
mobile: '',
verificationCode: '',
region: [],
regionText: '',
regionCodes: [],
certificateUrl: '',
auditStatusText: '',
auditRemark: ''
},
onLoad() { this.loadData(); },
onPullDownRefresh() { this.loadData().finally(() => wx.stopPullDownRefresh()); },
loadData() {
this.setData({ loading: true });
return Promise.all([
competition.fetchRefereeProfileOptions(),
competition.fetchRefereeProfile()
]).then(([options, profile]) => {
const levels = Array.isArray(options && options.levels) ? options.levels : [];
const roles = Array.isArray(options && options.roles) ? options.roles : [];
const rawRoles = profile.roles != null ? profile.roles : profile.roleValues;
const selectedRoles = competition.splitRefereeRoles(rawRoles);
const regionNames = [profile.provinceName, profile.cityName, profile.districtName].filter(Boolean);
const levelIndex = Math.max(0, levels.findIndex((item) => Number(item.value) === Number(profile.level)));
this.setData({
profile,
levels,
levelNames: levels.map((item) => item.label || item.name || String(item.value)),
levelIndex,
roleOptions: roles.map((item) => Object.assign({}, item, { checked: selectedRoles.includes(Number(item.value)) })),
selectedRoles,
name: profile.name || '',
mobile: profile.mobile || '',
region: regionNames,
regionText: regionNames.join(' / '),
regionCodes: [profile.provinceCode, profile.cityCode, profile.districtCode].filter(Boolean),
certificateUrl: profile.certificateUrl || '',
auditStatusText: profile.auditStatusText || '',
auditRemark: profile.auditRemark || ''
});
}).catch((err) => wx.showToast({ title: (err && err.message) || '裁判资料加载失败', icon: 'none' }))
.finally(() => this.setData({ loading: false }));
},
onNameInput(e) { this.setData({ name: (e.detail.value || '').trim() }); },
onMobileInput(e) { this.setData({ mobile: (e.detail.value || '').trim() }); },
onCodeInput(e) { this.setData({ verificationCode: (e.detail.value || '').trim() }); },
onRegionChange(e) {
const region = e.detail.value || [];
this.setData({ region, regionText: region.filter(Boolean).join(' / '), regionCodes: e.detail.code || [] });
},
onLevelChange(e) { this.setData({ levelIndex: Number(e.detail.value) || 0 }); },
onRoleChange(e) {
const selectedRoles = (e.detail.value || []).map(Number);
this.setData({
selectedRoles,
roleOptions: this.data.roleOptions.map((item) => Object.assign({}, item, { checked: selectedRoles.includes(Number(item.value)) }))
});
},
onSendCode() {
if (!PHONE_RE.test(this.data.mobile)) {
wx.showToast({ title: '请输入正确的手机号', icon: 'none' });
return;
}
auth.sendVerificationCode(this.data.mobile)
.then(() => wx.showToast({ title: '验证码已发送', icon: 'success' }))
.catch((err) => wx.showToast({ title: (err && err.message) || '验证码发送失败', icon: 'none' }));
},
onUploadCertificate() {
wx.chooseMedia({
count: 1,
mediaType: ['image'],
success: (res) => {
const filePath = res && res.tempFiles && res.tempFiles[0] && res.tempFiles[0].tempFilePath;
if (!filePath) return;
this.setData({ uploading: true });
auth.uploadFile(filePath)
.then((certificateUrl) => this.setData({ certificateUrl }))
.catch((err) => wx.showToast({ title: (err && err.message) || '证书上传失败', icon: 'none' }))
.finally(() => this.setData({ uploading: false }));
}
});
},
onSubmit() {
if (this.data.submitting) return;
const { name, mobile, verificationCode, region, regionCodes, levels, levelIndex, certificateUrl, selectedRoles } = this.data;
if (!name) return wx.showToast({ title: '请输入姓名', icon: 'none' });
if (mobile && !PHONE_RE.test(mobile)) return wx.showToast({ title: '请输入正确的手机号', icon: 'none' });
if (region.length !== 3 || regionCodes.length !== 3) return wx.showToast({ title: '请选择完整所在地区', icon: 'none' });
if (!levels[levelIndex]) return wx.showToast({ title: '请选择裁判级别', icon: 'none' });
if (!certificateUrl) return wx.showToast({ title: '请上传裁判证书', icon: 'none' });
if (!selectedRoles.length) return wx.showToast({ title: '请至少选择一个裁判角色', icon: 'none' });
const payload = {
name,
mobile: mobile || undefined,
verificationCode: verificationCode || undefined,
provinceCode: String(regionCodes[0]), provinceName: region[0],
cityCode: String(regionCodes[1]), cityName: region[1],
districtCode: String(regionCodes[2]), districtName: region[2],
level: Number(levels[levelIndex].value),
certificateUrl,
roles: selectedRoles
};
this.setData({ submitting: true });
competition.submitRefereeProfile(payload)
.then((profile) => {
wx.showToast({ title: '裁判资料已提交', icon: 'success' });
if (profile) this.setData({ auditStatusText: profile.auditStatusText || '待审核', auditRemark: profile.auditRemark || '' });
})
.catch((err) => wx.showToast({ title: (err && err.message) || '提交失败', icon: 'none' }))
.finally(() => this.setData({ submitting: false }));
}
});