修复绑定手机号

This commit is contained in:
wans 2020-07-16 16:29:47 +08:00
parent fbea281f16
commit 4d9ec42cdc

View File

@ -4,6 +4,11 @@ Page({
* 页面的初始数据 * 页面的初始数据
*/ */
data: { data: {
randomName: '',
showPhone: true,
gotCode: false,
restTime: 10,
timer: '',
indicatorDots: true, indicatorDots: true,
autoplay: true, autoplay: true,
token: '', token: '',
@ -23,7 +28,8 @@ Page({
live: { live: {
liveUrl: app.liveUrl, liveUrl: app.liveUrl,
liveList: [] liveList: []
} },
usercenterUrl: app.usercenterUrl
}, },
doLogin: function () { doLogin: function () {
var self = this; var self = this;
@ -178,6 +184,130 @@ Page({
url: '../cultureDetail/cultureDetail?libraryId='+ event.currentTarget.dataset.libraryId, url: '../cultureDetail/cultureDetail?libraryId='+ event.currentTarget.dataset.libraryId,
}) })
}, },
// 获取输入的手机号
phoneNum: function (res) {
this.setData({
phone: res.detail.value
})
console.log(this.data.phone)
},
// 校验手机号
testPhone: function () {
var self = this
if (self.data.phone) {
if (!/^1(3|4|5|6|7|8|9)\d{9}$/.test(self.data.phone)) {
wx.showToast({
title: '请输入正确的手机号',
icon: 'none',
duration: 1500
})
} else {
self.getCode()
}
} else {
wx.showToast({
title: '手机号不能为空',
icon: 'none',
duration: 1500
})
}
},
// 获取验证码
getCode: function () {
var self = this
app.restAjax.get(app.restAjax.path('{usercenterUrl}/api/sms/getverificationcode/' + self.data.phone, [app.usercenterUrl]), {}, null,
function (code, data) {
if (code == 200) {
console.log(data)
self.setData({
gotCode: true
})
self.data.timer = setInterval(function () {
var cur = self.data.restTime - 1
console.log(cur)
if (cur == 0) {
clearInterval(self.data.timer)
self.setData({
restTime: 120,
gotCode: false
})
} else {
self.setData({
restTime: cur
})
}
}, 1000)
}
},
function (code, data) {
console.log(data)
wx.showToast({
title: data.msg,
icon: 'none',
duration: 1500
})
} )
},
// 提交绑定手机
submitPhone: function () {
var self = this
app.restAjax.put(app.restAjax.path('{usercenterUrl}/app/user/updateminiappdefaultusername', [app.usercenterUrl]), {
phone: self.data.phone,
verificationCode: self.data.code
}, {
headers: {
token: self.data.token
}
}, function (code, data) {
console.log(data)
wx.setStorageSync('token', data.data);
wx.setStorageSync('isRandomUsername', 0)
clearInterval(self.data.timer)
self.setData({
showPhone: false,
restTime: 120
})
self.getUserInfo()
}, function (code, data) {
console.log(data)
})
},
// 验证码
inputCode: function (e) {
this.setData({
code: e.detail.value
})
},
// 判断用户是否为随机名称
isRandomName: function () {
var self = this
wx.getStorage({
key: 'isRandomUsername',
success: function (res) {
if (res.data == 1) {
wx.hideTabBar()
self.setData({
randomName: true
})
}
}
})
},
// 获取用户信息
getUserInfo: function () {
var self = this
app.restAjax.get(app.restAjax.path('{usercenterUrl}/app/user/getappuser', [app.usercenterUrl]), {}, {
headers: {
token: self.data.token
}
}, function (code, data) {
self.setData({
userInfo: data
})
}, function (code, data) {
console.log(data)
})
},
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
@ -189,6 +319,7 @@ Page({
self.doGetLiveList(); self.doGetLiveList();
self.doGetVenueList(); self.doGetVenueList();
self.doGetActivityList(); self.doGetActivityList();
self.isRandomName();
}, },
/** /**