添加预定页面保存及验证码获取

This commit is contained in:
wans 2020-07-07 15:56:13 +08:00
parent a4012d1ebf
commit c5f090f002
4 changed files with 91 additions and 152 deletions

View File

@ -9,7 +9,10 @@ Page({
*/
data: {
token: '',
timer: '',
gotCode: false,
checkOrder: false,
restTime:120,
venuesInfoId: '',
selectVenuesProject:'',
venuesProjectList: [],
@ -35,11 +38,7 @@ Page({
})
return false;
}
if(self.data.phoneNumber == ''){
wx.showToast({
title: '请填写手机号',
icon: 'none',
})
if(!self.checkPhoneNumber()){
return false;
}
if(self.data.smsCode == ''){
@ -55,10 +54,19 @@ Page({
venuesProjectId : self.data.selectVenuesProject,
bookingItemList : self.data.mySelectItem
}
app.restAjax.post(app.restAjax.path('{venueUrl}/app/booking/savebookinginfo',[]), param, {headers : {token:self.data.token}}, function(code,data){
console.log(data);
app.restAjax.post(app.restAjax.path('{venueUrl}/app/booking/savebookinginfo',[app.venueUrl]), param, {headers : {token:self.data.token}}, function(code,data){
if(code == 200){
wx.showToast({
title: '预订成功',
});
setTimeout( () =>{
wx.navigateBack({
delta: 1,
})
},1500);
}
},function(code,data){
app.dialog.msg(data.msg);
});
},
@ -250,9 +258,64 @@ Page({
})
},
//获取验证码
getSmsCoce:function (){
checkPhoneNumber: function(){
if(this.data.phoneNumber == ''){
wx.showToast({
title: '请填写手机号',
icon: 'none',
})
return false;
}
if (!/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.data.phoneNumber)) {
wx.showToast({
title: '请输入正确的手机号',
icon: 'none',
duration: 1500
})
return false;
}
return true;
},
//获取验证码
getSmsCoce: function (){
var self = this;
if(!self.checkPhoneNumber()){
return false;
}
console.log('go');
app.restAjax.get(app.restAjax.path('{venueUrl}/api/sms/getverificationcode/' + self.data.phoneNumber, [app.venueUrl]), {}, 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
})
})
},
doCheckOrder: function () {

View File

@ -42,8 +42,9 @@
<view class="row">
<view class="row-title">验证码:</view>
<view class="row-input">
<input placeholder="请输入验证码" class="code-input" model:value="{{smsCode}}" bindtap="getSmsCoce"></input>
<view class="get-code">获取验证码</view>
<input placeholder="请输入验证码" class="code-input" model:value="{{smsCode}}"></input>
<view class="get-code" bindtap="getSmsCoce" wx:if="{{!gotCode}}">获取验证码</view>
<view class="got-code" wx:else>{{restTime}}</view>
</view>
</view>
</view>

View File

@ -220,4 +220,18 @@
.top{
background: #9F1512;
color: #fff;
}
.get-code, .got-code{
font-size: 28rpx;
background: rgba(159,21,18,.1);
color: #9F1512;
width: 28%;
line-height: 55rpx;
text-align: center;
border-radius: 10rpx;
}
.got-code{
background: #fff;
color: #4a4d52;
border: 1px solid #eaeaea;
}

View File

@ -4,11 +4,6 @@ Page({
* 页面的初始数据
*/
data: {
randomName: '',
showPhone: true,
gotCode: false,
restTime: 10,
timer: '',
indicatorDots: true,
autoplay: true,
token: '',
@ -31,8 +26,7 @@ Page({
live: {
liveUrl: app.liveUrl,
liveList: []
},
usercenterUrl: app.usercenterUrl
}
},
doLogin: function () {
var self = this;
@ -65,9 +59,6 @@ Page({
page: 1,
rows: 5
}, null, function(code, data) {
for(var i = 0, item; item = data.rows[i++];) {
item.cover = item.libraryCover.split(',')[0];
}
self.setData({
'library.bannerLibrary': data.rows
});
@ -127,11 +118,6 @@ Page({
app.dialog.msg(data.msg);
});
},
goCultureDetail: function(event) {
wx.navigateTo({
url: '../cultureDetail/cultureDetail?libraryId='+ event.currentTarget.dataset.libraryId,
})
},
goNewsDetail: function (event) {
wx.navigateTo({
url: '../newsDetail/newsDetail?templateRecordUrl='+ event.currentTarget.dataset.templateRecordUrl,
@ -172,130 +158,6 @@ Page({
url: '../heritage/heritage',
})
},
// 获取输入的手机号
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)
})
},
/**
* 生命周期函数--监听页面加载
*/
@ -307,7 +169,6 @@ Page({
self.doGetLiveList();
self.doGetVenueList();
self.doGetActivityList();
self.isRandomName();
},
/**