enteryanzheng.js 3.6 KB
// pages/enteryanzheng/enteryanzheng.js
let interval = null;
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    Length: 6, //输入框个数
    isFocus: true, //聚焦
    Value: "", //输入的内容
    ispassword: true,
    currentTime: 60,
    time: '',
    phonenum: ''

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options.phonenum)
    this.setData({
      phonenum: options.phonenum,
      type:options.type,
      id:options.id
    })

    this.getcode()
  },

  //获取验证码
  getcode() {
    let that = this;
    let currentTime = that.data.currentTime;
    that.setData({
      disable: true
    })
    interval = setInterval(function() {
      currentTime--;
      that.setData({
        time: currentTime + 's后再次发送',

      })
      if (currentTime <= 0) {
        clearInterval(interval)
        that.setData({
          time: '重新发送',
          currentTime: 61,
          disable: false
        })
      }
    }, 1000)


    var url = '/user/Profile/getCode';
    var params = {
      mobile: that.data.phonenum,

    }

    app.post(url, params).then((res) => {
      console.log(res);
      if (res.code) {

      }

    }).catch((err) => {
      console.log(err)
      wx.showToast({
        title: err.ResultMsg,
        icon: "none"
      })
    })
  },

  entercode() {
    if (this.data.time == '重新发送') {
      this.getcode()
    }
  },

  Focus(e) {
    var that = this;
    let arr = that.data.arr;
    console.log(e.detail.value.length);

    // arr.push(e.detail.value);
    // console.log(arr.length)
    var inputValue = e.detail.value;
    that.setData({
      Value: inputValue,
      len: e.detail.value.length
    })

    if (that.data.Value.length == 6) {
      that.yanzhenglogin()
    }


  },

  yanzhenglogin() {
    let that = this;
    var url = '/user/Profile/bind_mobile';
    var params = {
      mobile: that.data.phonenum,
      verification_code: that.data.Value
    }

    app.post(url, params).then((res) => {
      console.log(res);
      wx.setStorageSync('token', res.token)
      if (res.is_password == 0) {
        wx.navigateTo({
          url: '/pages/setmima/setmima',
        })
      } else {
        if(that.data.type==1){
          let url = wx.getStorageSync("url")
          wx.navigateTo({
            url: url+'?id=' + that.data.id,
          })
        } else if (that.data.type == 2){
          let url = wx.getStorageSync("url")
          wx.navigateTo({
            url: url + '?id=' + that.data.id,
          })
        }else{
          wx.switchTab({
            url: '/pages/homapage/homepage',
          })
        }
      
      }


    }).catch((err) => {
      console.log(err)

      wx.showToast({
        title: err.data.msg,
        icon: "none"
      })
    })
  },
  Tap() {
    var that = this;
    that.setData({
      isFocus: true,
    })
  },
  formSubmit(e) {
    console.log(e.detail.value.password);
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})