//logs.js const util = require('../../utils/util.js'); const app = getApp() Page({ data: { name: '',//姓名 phone: '',//手机号 code: '',//验证码 iscode: null,//用于存放验证码接口里获取到的code codename: '获取验证码', disabled: false, //按钮是否禁用 click: true }, onLoad: function () { }, getNameValue: function (e) { this.setData({ name: e.detail.value }) }, getPhoneValue: function (e) { this.setData({ phone: e.detail.value }) }, getCodeValue: function (e) { this.setData({ code: e.detail.value }) }, //判断手机号 getCode: function () { var phoneNum = this.data.phone; var that = this; var myreg = /^1[0-9]{10,11}$/; if (this.data.phone == "") { wx.showToast({ title: '手机号不能为空', icon: 'none', duration: 1000 }) return false; } else if (!myreg.test(this.data.phone)) { wx.showToast({ title: '请输入正确的手机号', icon: 'none', duration: 1000 }) return false; } else { wx.showLoading({ title: '请稍候...', mask: true }) wx.request({ url: app.globalData.serverUrl + "/cloudcard/getVcode", data: { mobile: phoneNum }, success(res) { wx.hideLoading(); // that.setData({ // iscode: res.data.data // }) var num = 61; var timer = setInterval(function () { num--; if (num <= 0) { clearInterval(timer); that.setData({ codename: '重新发送', disabled: false }) } else { that.setData({ codename: num + "s" }) } }, 1000) }, fail: function (res) { wx.hideLoading(); } }) } }, //获取验证码 getVerificationCode() { this.getCode(); var that = this that.setData({ disabled: true }) }, //提交表单信息 formSubmitHandle: function (e) { var userInfo = wx.getStorageSync("userInfo"); if (this.data.name == "") { wx.showToast({ title: '姓名不能为空', icon: 'none', duration: 1000 }) return false; } else if (this.data.phone == "") { wx.showToast({ title: '手机号不能为空', icon: 'none', duration: 1000 }) return false; } else if (this.data.code == "") { wx.showToast({ title: '验证码不能为空', icon: 'none', duration: 1000 }) return false; // } else if (this.data.code != this.data.iscode) { // wx.showToast({ // title: '验证码错误', // icon: 'none', // duration: 1000 // }) // return false; } else { if(this.data.click){ var that = this; that.setData({ click: false }) wx.request({ url: app.globalData.serverUrl + "/user/linkPhone", method: "POST", data: { userName: that.data.name, mobile: that.data.phone, id: userInfo.id, VCode: that.data.code }, header: { "Content-Type": "application/x-www-form-urlencoded" }, success: function (res) { if(res.data.code == "ok"){ wx.setStorageSync('userInfo', res.data.data); wx.showToast({ title: '提交成功!', icon: 'success', duration: 2000 }) setTimeout(function() { wx.reLaunch({ url: '../cloud/cloud' }) }, 200) } else { that.setData({ click: true }) wx.showToast({ title: res.data.msg, icon: 'none', duration: 2000 }) } }, fail: function (res) { that.setData({ click: true }) wx.showToast({ title: '提交失败!', icon: 'none', duration: 2000 }) } }) } else { wx.showToast({ title: '保存中,请勿重复提交', icon: 'none', duration: 1000 }) } } } })