qingcheng-xiaochengxu/pages/zucepage/zucepage.js
2025-05-15 21:01:14 +08:00

209 lines
4.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import {url} from '../../request'
Page({
/**
* 页面的初始数据
*/
data: {
countdown: 60, // 设置倒计时时长(秒)
timer: null, // 存储计时器
},
name(e){
this.setData({
name:e.detail.value
})
console.log(e.detail.value);
},
phone(e){
this.setData({
phone:e.detail.value
})
console.log(e.detail.value);
},
code(e){
this.setData({
code:e.detail.value
})
console.log(e.detail.value);
},
yanzhengma(e){
this.setData({
yanzhengma:e.detail.value
})
console.log(e.detail.value);
},
password(e){
this.setData({
password:e.detail.value
})
console.log(e.detail.value);
},
getcode(){
const phone = this.data.phone;
if (!/^\d{11}$/.test(phone)) {
wx.showToast({
title: '请输入11位的手机号',
icon: 'none'
});
return;
}
wx.request({
url: url + '/userInfo/code',
method: 'POST',
data: {
templateString: this.data.phone
},
header: {
'content-type': 'application/json'
},
success(res) {
console.log('发送成功', res);
if(res.data.code==1){
wx.showToast({
title: '发送成功',
icon: 'success',
duration: 2000
});
}else{
wx.showToast({
title: res.data.message,
icon: 'success',
duration: 2000
});
}
},
fail(err) {
console.error('请求失败', err);
}
});
this.startCountdown();
},
startCountdown() {
this.setData({
isCountingDown: true,
countdown: 60
});
this.data.timer = setInterval(() => {
let count = this.data.countdown;
if (count <= 1) {
clearInterval(this.data.timer);
this.setData({
isCountingDown: false,
countdown: 60
});
} else {
this.setData({
countdown: count - 1
});
}
}, 1000);
},
onUnload() {
// 页面卸载时清除定时器
if (this.data.timer) {
clearInterval(this.data.timer);
}
},
// 注册
submit(){
const yanzhengma = this.data.yanzhengma
const phone = this.data.phone
const password = this.data.password
const code = this.data.code
const name = this.data.name
if (!name) {
wx.showToast({
title: '请输入昵称',
icon: 'none'
});
return;
}
if (!/^\d{6}$/.test(yanzhengma)) {
wx.showToast({
title: '请输入6位验证码',
icon: 'none'
});
return;
}
if (!/^\d{6,11}$/.test(phone)) {
wx.showToast({
title: '请输入6到11位的账号',
icon: 'none'
});
return;
}
// 密码验证6~10位字符
if (!/^.{6,10}$/.test(password)) {
wx.showToast({
title: '请输入6到10位的密码',
icon: 'none'
});
return;
}
if (!/^\d{6}$/.test(code)) {
wx.showToast({
title: '请输入6位的邀请码',
icon: 'none'
});
return;
}
if (this.data.isAgree!=true) {
wx.showToast({
title: '请先勾选协议',
icon: 'none'
});
return;
}
console.log("sakldhasjdhja");
wx.request({
url: url + '/userInfo/register',
method: 'POST',
data: {
nickName: this.data.name,
phoneNumber: this.data.phone,
verificationCode: this.data.yanzhengma,
invitationCode: this.data.code,
userPassword: this.data.password
},
header: {
'content-type': 'application/json'
},
success(res) {
console.log('注册成功', res);
if(res.data.code==1){
wx.showToast({
title: '注册成功',
icon: 'success',
duration: 2000
});
setTimeout(() => {
wx.navigateBack({
delta: 1
})
}, 2000);
}else{
wx.showToast({
title: res.data.message,
icon: 'error',
duration: 2000
});
}
},
fail(err) {
console.error('请求失败', err);
}
});
},
// 勾选
onAgreeChange(e) {
this.setData({
isAgree: true
});
console.log("gaibianler",this.data.isAgree);
},
})