123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- //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
- })
- }
- }
- }
- })
|