123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- const app = getApp()
- Page({
-
- data: {
- times:60,
- isTimes:false,
- tips:'获取验证码',
- myTime: null
- },
-
- onLoad: function (options) {
- this.setData(options)
- console.log(options)
- },
-
- onReady: function () {
- },
-
- onShow: function () {
- },
-
- onHide: function () {
- clearInterval(this.myTime);
- },
-
- onUnload: function () {
- },
-
- onPullDownRefresh: function () {
- },
-
- onReachBottom: function () {
- },
-
- onShareAppMessage: function () {
- },
-
- redirectCtl: app.redirectCtl,
-
- navigateCtl: app.navigateCtl,
-
-
- inputCtl: function (e) {
- const mobileExp = /^1[0-9]{10}$/;
- const { temp = {}, type } = e.currentTarget.dataset
- const { value } = e.detail
- temp[type] = value;
- const { phone, verificationCode } = temp;
- if (type == 'phone') {
- this.setData({ phone })
-
-
-
-
-
-
-
-
-
-
-
-
-
- } else if (type == 'verificationCode') {
- return this.setData({ verificationCode })
- }
-
- },
-
- setStime:function(){
- const mobileExp = /^1[0-9]{10}$/;
- const { times, phone}=this.data;
- if (!phone) {
- wx.showToast({
- title: '手机号码不能为空',
- icon: 'none'
- })
- return
- } else if (!mobileExp.test(phone)) {
- wx.showToast({
- title: '手机号码位数不对',
- icon: 'none',
- duration: 1000
- })
- return
- }
- if (times == 60 || times ==0){
- this.getNumber()
- }
- if(times>0){
- this.startSetInter()
- }else if(times==0){
- this.setData({times:60})
- this.startSetInter()
- }
- },
-
- startSetInter: function () {
- var that = this;
- const {phone, tips, times} = that.data;
-
-
- if (times == 0) {
- that.setData({ tips: "获取验证码"});
- return ;
- } else {
- var numVal =that.data.times--;
- that.setData({ tips: "重新发送(" + numVal + ")"});
- }
- this.myTime=setTimeout(function () {
- that.startSetInter();
- }, 1000);
-
- },
-
- getNumber:function(){
- const { phone} = this.data;
- const postData = { fn: this.getNumber, param: { ...arguments } }
- app.post('/api/parents/parents/V2/getVerificationCode', { phone, type: 2 }, 0, postData).then(res => {
- wx.showToast({
- title: '已发送',
- icon: 'none',
- duration: 1000
- });
- })
- },
-
- sureSumbit:function(){
- const mobileExp = /^1[0-9]{10}$/;
- const { phone, verificationCode, vipId, isFrist, derver}=this.data;
- console.log(phone, verificationCode, vipId, isFrist, derver)
- const postData = { fn: this.sureSumbit, param: { ...arguments } }
- if (!phone) {
- wx.showToast({
- title: '手机号码不能为空',
- icon: 'none'
- })
- return
- } else if (!mobileExp.test(phone)) {
- wx.showToast({
- title: '手机号码位数不对',
- icon: 'none',
- duration: 1000
- })
- return
- }
- if (!verificationCode) {
- wx.showToast({
- title: '请输入验证码',
- icon: 'none'
- })
- return
- }
- clearInterval(this.myTime);
- this.setData({ times: 0, tips: "重新验证码"})
- app.post('/api/parents/parents/V2/bindPhone', { phone, verificationCode }, 0, postData).then(res => {
- clearInterval(this.myTime);
- wx.showToast({
- title: '绑定成功',
- icon: 'none',
- duration: 1000
- });
- if (isFrist == 1) {
- app.redirectCtl({ url: 'homework_list', method: { vipId } }, true)
- } else {
- app.redirectCtl({ url: 'wechat_addchild', method: { derver } }, true)
- }
- })
- }
- })
|