// pages/reset_password/reset_password.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    phone: null,
    password: null,
    rePassword: null,
    checkPass: false,
    errorMsg: ''
  },
  resetPassword(e) {
    let that = this;
    let{
      phone : phonenumber,
      password
    } = this.data;
    wx.request({
      url: getApp().globalData.postHeadAgreement + '/restapi/wechat/resetPassword',
      data: {
        phonenumber,
        password
      },
      method: 'POST',
      success(res) {
        if (res.data.code == 1) {
          wx.showModal({
            title: '提示',
            content: res.data.msg,
            showCancel: false,
            confirmColor:'#00AADD',
          });
        } else {
          wx.navigateBack();
        }
      }
    });
  },
  inputPassword(e) {
    this.setData({
      password: e.detail.value
    });
    this.checkAll();
  },
  inputRepassword(e) {
    this.setData({
      rePassword: e.detail.value
    });
    this.checkAll();
  },
  checkPassword() {
    if (!this.data.password || !this.data.rePassword || this.data.password != this.data.rePassword) {
      return false;
    }
    return true;
  },
  checkAll() {
    if (this.data.password && (this.data.password.length < 5 || this.data.password.length > 20)) {
      this.setData({
        errorMsg: '密码长度应为5-20'
      });
      this.setData({
        checkPass: false
      });
      return;
    }
    if (!this.checkPassword()) {
      this.setData({
        errorMsg: '两次密码输入不一致,请重新输入'
      });
      this.setData({
        checkPass: false
      });
      return;
    } else {
      this.setData({
        errorMsg: ''
      });
    }
    this.setData({
      checkPass: true
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let {
      phone
    } = options;
    this.setData({
      phone: phone
    });
    //resetPassword
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})