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

  /**
   * 页面的初始数据
   */
  data: {
    first:true,
    second:false,
    url:'',
    phone:'',
    forgetshow:true,
    currentTime:60,
    time: '60秒后再次发送',
    disabled:false,
    yanzhengcode:'',
    newpassword:'',
    dengshow:false,
    newmima:true,
   
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that=this;
    setTimeout(function(){
      that.setData({
        url: app.globalData.url
      })
    },1000) 
  },

  enterphone(e){
    this.setData({
      phone:e.detail.value
    })
    this.yanhzengphone();
    
  },

  yanhzengphone(){
    let value = this.data.phone
    if (value.length == 11) {
      this.setData({
        forgetshow: false
      })
    }else{
      this.setData({
        forgetshow: true
      })
    }
  },
  showmima(){
    this.setData({
      newmima:false
    })
  },
  hidemima(){
    this.setData({
      newmima: true
    })
  },
  clearphone(){
    console.log(342)
    this.setData({
      phone:''
    })
  },

  next(){
    let that = this;
    let reg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
    if(!reg.test(this.data.phone)){
      wx.showToast({
        title: '请输入正确的手机号',
        icon:'none'
      })
    }else{

      
      let url = 'user/Profile/forget_password', params = {
        mobile: that.data.phone,

      }
      app.post(url, params).then((res) => {
        console.log(res);
        that.setData({
          first: false,
          second: true
        })
        that.getcode()


      }).catch((err) => {

      })
      
    }

  },


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

      })

      
      if (currentTime <= 0) {
        clearInterval(interval)
        that.setData({
          time: '60秒后再次发送',
          currentTime: 60,
          disabled: false
        })
      }
    }, 1000)


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

    }

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

      }

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

  chongxin(){
    console.log(34378478)
    this.getcode();
  },

  yanzheng(){
    if (this.data.yanzhengcode.length > 0 && this.data.newpassword.length>0){
      this.setData({
        dengshow:true
      })
    }else{
      this.setData({
        dengshow:false
      })
    }
  },

  shuruyanzheng(e){
    this.setData({
      yanzhengcode:e.detail.value
    })
    this.yanzheng()
  },

  setnewmima(e){
    this.setData({
      newpassword:e.detail.value
    })
    this.yanzheng()
  },

  //登陆
  denglu(){
    console.log(47832342789);
    let that = this;
    console.log(that.data.newpassword.length)
    if (that.data.newpassword.length < 6 || that.data.newpassword.length>20){
      wx.showToast({
        title: '请输入6-20位的密码',
        icon:'none'
      })
    }else{
      let url = 'user/Profile/reset_password', params = {
        mobile: that.data.phone,
        verification_code: that.data.yanzhengcode,
        password: that.data.newpassword

      }
      app.post(url, params).then((res) => {
        console.log(res);
        // wx.switchTab({
        //   url: '/pages/homapage/homepage',
        // })
        wx.navigateTo({
          url: '/pages/login/login',
        })



      }).catch((err) => {
        wx.showToast({
          title: err.data.msg,
          icon: "none"
        })
      })
    }
   

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})