From c5f090f002420b3e9df7d2f1752c2da99494002d Mon Sep 17 00:00:00 2001 From: wans <747101512@qq.com> Date: Tue, 7 Jul 2020 15:56:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A2=84=E5=AE=9A=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E4=BF=9D=E5=AD=98=E5=8F=8A=E9=AA=8C=E8=AF=81=E7=A0=81?= =?UTF-8?q?=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/book/book.js | 83 ++++++++++++++++++++++--- pages/book/book.wxml | 5 +- pages/book/book.wxss | 14 +++++ pages/index/index.js | 141 +------------------------------------------ 4 files changed, 91 insertions(+), 152 deletions(-) diff --git a/pages/book/book.js b/pages/book/book.js index 514ef5c..e6dc48f 100644 --- a/pages/book/book.js +++ b/pages/book/book.js @@ -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 () { diff --git a/pages/book/book.wxml b/pages/book/book.wxml index d4b1bee..92ec643 100644 --- a/pages/book/book.wxml +++ b/pages/book/book.wxml @@ -42,8 +42,9 @@ 验证码: - - 获取验证码 + + 获取验证码 + {{restTime}} diff --git a/pages/book/book.wxss b/pages/book/book.wxss index 88da7cc..aa0b16d 100644 --- a/pages/book/book.wxss +++ b/pages/book/book.wxss @@ -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; } \ No newline at end of file diff --git a/pages/index/index.js b/pages/index/index.js index f1f0e99..c3a68b2 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -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(); }, /**