const { authService } = require('../../services') Page({ data: { name: '', organization: '', organizationPhone: '', phone: '', code: '', sending: false, submitting: false, countdown: 0, error: '', }, onInput(event: WechatMiniprogram.Input) { this.setData({ [event.currentTarget.dataset.field]: event.detail.value, error: '' }) }, async onSendCode() { const { phone } = this.data if (!/^1\d{10}$/.test(phone)) return this.setData({ error: '请输入正确的手机号' }) this.setData({ sending: true, error: '' }) try { await authService.sendPhoneCode(phone) this.setData({ countdown: 60 }) const timer = setInterval(() => { if (this.data.countdown <= 1) { clearInterval(timer) this.setData({ countdown: 0 }) } else this.setData({ countdown: this.data.countdown - 1 }) }, 1000) } catch (error: any) { this.setData({ error: error?.message || '验证码发送失败' }) } finally { this.setData({ sending: false }) } }, async onRegister() { const { name, organization, organizationPhone, phone, code } = this.data if (!name || !organization || !organizationPhone || !/^1\d{10}$/.test(phone) || !code) { return this.setData({ error: '请完整填写注册信息' }) } this.setData({ submitting: true, error: '' }) try { const verification = await authService.verifyPhone(phone, code) await authService.register({ name, organization, organizationPhone, phone, verificationTransaction: verification.verificationTransaction }) wx.showModal({ title: '提交成功', content: '注册申请已提交,请按页面提示完成资料完善。', showCancel: false, success: () => wx.navigateBack() }) } catch (error: any) { this.setData({ error: error?.message || '注册失败,请重试' }) } finally { this.setData({ submitting: false }) } }, })