|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- // pages/mobileVerification/mobileVerification.js
- const app = getApp()
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- imgUrl: app.globalData.urlStatic,//图片路径
- isAgreement: true,//是否同意协议
- verificationCode: '获取验证码',//验证码文案
- sendCode: true,
- mobileText:"",//手机号
- verificationText:null,
- getMobileBtnShow:true,
- agreement:false,//是否显示协议
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- if (app.globalData.userMobile) {
- this.setData({
- getMobileBtnShow: false,
- mobileText: app.globalData.userMobile
- })
- }
- },
-
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- return app.sharePack();
- },
- agreementState: function () {//协议
- this.setData({
- isAgreement: !this.data.isAgreement
- })
- },
- getCode: function (e) {//获取验证码
- if (!app.mobileVerify(this.data.mobileText)) {
- if (this.data.mobileText) {
- wx.showToast({
- title: '请输入正确的电话',
- icon: 'none'
- })
- } else {
- wx.showToast({
- title: '请输入电话',
- icon: 'none'
- })
- }
- return;
- }
- if (!this.data.sendCode) {
- return;
- }
- this.data.sendCode = false;
- app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.mobileText }, res => {
- if (res.code == 200) {
- this.countDown();
- wx.showToast({
- title: '验证码获取成功',
- icon: "none"
- })
- this.setData({
- verificationCode: 60
- })
- } else {
- this.data.sendCode = true;
- wx.showToast({
- title: res.msg,
- icon: "none"
- })
- }
- }, this)
- },
- countDown: function () {//倒计时
- setTimeout(() => {
- this.setData({
- verificationCode: this.data.verificationCode - 1
- })
- if (this.data.verificationCode > 0) {
- this.countDown();
- } else {
- this.setData({
- verificationCode: "获取验证码"
- })
- this.data.sendCode = true;
- }
- }, 1000);
- },
- getMoblie:function(e){//获取用户输入的手机号
- this.data.mobileText = e.detail.value
- },
- getCodeText: function (e) {//获取用户输入的手机号
- this.data.verificationText = e.detail.value
- },
- submitMobile: function (){
- if (!app.mobileVerify(this.data.mobileText)) {
- if (this.data.mobileText) {
- wx.showToast({
- title: '请输入正确的电话',
- icon: 'none'
- })
- } else {
- wx.showToast({
- title: '请输入电话',
- icon: 'none'
- })
- }
- return;
- }
- if (!this.data.verificationText) {
- wx.showToast({
- title: '请输入验证码',
- icon: 'none'
- })
- return;
- }
- if (!this.data.isAgreement) {
- wx.showToast({
- title: '请同意协议',
- icon: 'none'
- })
- return;
- }
- app.wxRequest(app.globalData.urlRoot + "userInfo/getCertificationInfo", { mobile: this.data.mobileText, captcha: this.data.verificationText }, res => {
- if (res.code == 200) {
- wx.setStorageSync('userMobile', this.data.mobileText );
- app.globalData.userMobile = this.data.mobileText ;
- if (res.data != null) {
- app.globalData.certificationState = res.data.certificationState;
- wx.redirectTo({
- url: '../scout/scout'
- })
- } else {
- wx.redirectTo({
- url: '../scout/register/register'
- })
- }
- }
- }, this);
- },
- getPhone(e) {
- this.setData({
- getMobileBtnShow:false
- })
- if (e.detail.errMsg == 'getPhoneNumber:ok') {
- app.getMobile(e.detail.encryptedData, e.detail.iv, res => {
- if (res.code == 200) {
- if (res.data.result == 0) {
- this.setData({
- mobileText: res.data.decodeData.phoneNumber
- })
- }
- }
- }, this)
- }
- },
- agreementControl:function(){
- this.setData({
- agreement: !this.data.agreement
- })
- }
- })
|