diff --git a/pages/home/me/indexx.js b/pages/home/me/indexx.js
index 0510c15..a6effe3 100644
--- a/pages/home/me/indexx.js
+++ b/pages/home/me/indexx.js
@@ -12,15 +12,64 @@ Page({
isCxHq:false,
bdsjhVisible:false,
avatar:"",
+ countdown:60,
userInfo:{
avatar:"",
nick:"",
isChatVip:false,//是否会员
- phone:'',
+ phone:'123',
hasPhone:false
-
+ },
+ phone:'',
+ phoneVerificationCode:''
+ },
+ // 手机号码校验
+ getPhone(e){
+ const phone = e.detail.value;
+ if (!/^1[3456789]\d{9}$/.test(phone)) {
+ wx.showToast({
+ title: '手机号码格式不正确',
+ icon: 'none'
+ });
+ return;
+ }
+ },
+ getVerificationCode(e){
+ const VerificationCode = e.detail.value;
+ if (VerificationCode.length !== 6) {
+ wx.showToast({
+ title: '验证码格式不正确',
+ icon: 'none'
+ });
+ return;
+ }
+ },
+ getCode(){
+ console.log(this.data.phone);
+ if(this.data.countdown === 60 || this.data.countdown === '重新获取'){
+ req.postRequest('/api/user/send-authentication-code',{phone:this.data.phone}).then((res)=>{
+ console.log(res);
+ if (res.data.code !== 200) {
+ return wx.showToast({
+ title: res.data.msg,
+ icon: 'none'
+ });
+ }
+ if (this.data.countdown === '重新获取') {
+ this.setData({countdown: 60})
+ }
+ // 验证码倒计时
+ this.setData({isCxHq:true})
+ const timerId = setInterval(()=>{
+ this.setData({countdown:this.data.countdown-1})
+ if (this.data.countdown === 0) {
+ clearTimeout(timerId);
+ this.setData({countdown:'重新获取'})
+ }
+ },1000)
+ console.log('获取验证码');
+ })
}
-
},
doBdsjh(){
console.log('绑定手机号')
@@ -30,7 +79,30 @@ Page({
this.setData({bdsjhVisible:false})
},
doEXecSjh(){
- this.setData({bdsjhVisible:false})
+ req.patchRequest('/api/user/curt',{
+ phone:this.data.phone,
+ phoneVerificationCode:this.data.phoneVerificationCode
+ }).then((res)=>{
+ console.log(res);
+ if(res.data.code !== 200){
+ wx.showToast({
+ title:res.data.msg,
+ icon:'none'
+ })
+ return
+ }else {
+ this.setData({bdsjhVisible:false})
+ this.getUserInfo()
+ wx.showToast({
+ title:'绑定成功',
+ icon:'none'
+ })
+ }
+ })
+ this.setData({
+ phoneVerificationCode:'',
+ isCxHq:false
+ })
},
go2Grzl(){
wx.navigateTo({
@@ -91,7 +163,10 @@ Page({
getUserInfo(){
req.getRequest('/api/user/curt',{}).then((res)=>{
if(res.data.code==200){
- this.setData({userInfo:res.data.data})
+ this.setData({
+ userInfo:res.data.data,
+ phone:res.data.data.phone
+ })
}
console.log(this.userInfo);
}).catch((err)=>{
diff --git a/pages/home/me/indexx.wxml b/pages/home/me/indexx.wxml
index 86da8ac..45c1005 100644
--- a/pages/home/me/indexx.wxml
+++ b/pages/home/me/indexx.wxml
@@ -24,31 +24,31 @@