/** 
 * 
 * ==========找回密码==========
 * 
 * */
(function (w) {
  init();

  function init() {
    cutRegsterBar();
  }
  // ========== 步骤123======
  w.nextStep = function (st) {
    var body = {
        "type": $('#find-password .fptitle').attr('data-type'),
        "phone": $('#find-password .user input').val(),
        "code": $('#find-password .code input').val(),
        "password": $('#find-password .pw1 input').val()
    }
    switch (st) {
      case 1:
        edlPhone(body)
        break;
      case 2:
        setPassword(body)
        break;
      default:
        console.log('de');
    }
  }
  // 第一步验证手机
  var forgot_flag = false;
  function edlPhone(body){
    if(forgot_flag){
      return
    }
    if(!body.phone) {
      // $('.user input').focus().css('border',{});
      w.$msg('手机号不能为空', 2)
      return
    }
    forgot_flag = true;
    if (w.phoneNumber(body.phone)) {
      var params = {};
      params.theData = {phone:body.phone,verify_type:'forgot',type:body.type};
      params.theUrl = allAPI.sms.getCode;
      doPostAjax(params, function (data) {
        setTimeout(function(){forgot_flag = false;},1200)
        if (data.code == 200) {
          $('#find-password .content-s1').hide().siblings('.content-s2').show().find('.reph span').html(body.phone);
          $('#find-password .steps .s1').removeClass('active').siblings('.s2').addClass('active')
          $msg(data.info,1)
        } else {
            $msg(data.info,2)
        }
      })
    } else {
      forgot_flag = false;
      w.$msg('手机格式不对', 2)
    }
  }
  // 第二步设置密码
  function setPassword(body){
    if(forgot_flag){
      return
    }
    if(!body.code){
      $msg('请输入验证码',2)
      return
    }
    if(!body.password){
      $msg('请设置新密码',2)
      return
    }
    forgot_flag = true;
    var params = {};
    params.theData = body;
    params.theUrl = allAPI.user.forgot;
    doPostAjax(params, function (data) {
      setTimeout(function(){forgot_flag = false;},1200)
      if (data.code == 200) {
        $('#find-password .content-s2').hide().siblings('.content-s3').show();
        $('#find-password .steps .s2').removeClass('active').siblings('.s3').addClass('active')
        $msg(data.info,1)
      } else {
        $msg(data.info,2)
      }
    })
  }
  // ==========切换广告主 媒体主==========
  function cutRegsterBar() {
    var dom = "#find-password .fptitle .pointer";
      $(dom).bind('click', function (e, i) {
        $(dom).removeClass('active');
        $(this).addClass('active');
        $(this).parent().parent().attr('data-type', $(this).attr('data-type')); //设置 类型
      })
  }
})(window)
