<extend name="Public/bases" />
<block name="body">
  <script src="__JS__/jquery-1.11.3.min.js"></script>
  <script type="text/javascript" src="__JS__/getRem.js"></script>
  <link rel="stylesheet" type="text/css" href="__CSS__/reset.css">
  <link rel="stylesheet" type="text/css" href="__CSS__/forgetPass.css">
  <style>
    body {
      background: white;
    }
    input,button{
      padding: 0;
    }
  </style>
  <div class="loginPhTwo">
    <!-- 子页公共头部 -->
    <div class="subpage-heard">忘记密码
      <a href="javascript:window.history.go(-1);" class="arrows"></a>
    </div>
    <form action="">
      <div class="login-box">
        <div class="login-input">
          <img src="__IMG__/shouji.png" alt="">
          <input type="text" placeholder="请输入手机号" name="mobile" id="mobile" value="{$user['phone']}">
        </div>
        <div class="login-input">
          <img src="__IMG__/suo.png" alt="">
          <input type="password" placeholder="请输入密码" name="new_pwd" id="new_pwd" value="">
        </div>
        <div class="login-input">
          <img src="__IMG__/suo.png" alt="">
          <input type="password" placeholder="请输入确认密码" name="new_pwd_confirm" id="new_pwd_confirm" value="">
        </div>
        <div class="login-code">
          <input type="text" placeholder="输入验证码" id="code" name="code" value="">
          <div class="code g-btn jsgetcode" id="sendSafeCode">获取验证码</div>
        </div>
        <div class="login-btn submit">保存修改</div>
        <div class="forget-text">
          <div>通过手机号找回密码只适用于手机号注册的账号</div>
          <div>用户名注册的账号可<a href="mqqwpa://im/chat?chat_type=wpa&uin={:C('PC_SET_SERVER_QQ')}&version=1&src_type=web&web_src=oicqzone.com">联系客服</a></div>
        </div>
      </div>
    </form>
  </div>

  <div class="popmsg pop-dialog"></div>
  <script src="__JS__/pop.lwx.min.js"></script>
  <script src="__JS__/common.js"></script>
  <script>
    $(function() {
      var pmsg = $('.popmsg').pop();

      $('.jsgetcode').click(function() {
        var tis = this,that = $(tis);
        if (that.hasClass('disabled')) {return false;}
        var mobile = $.trim($('#mobile').val());
        if (mobile) {
          var is_true = true;
          if (/^1[0-9]{10}$/.test(mobile)) {
            $.ajax({
              url:"{:U('forget_send_msg')}",
              type:"POST",
              dataType:"json",
              async: false,
              data:{account:mobile},
              success:function(result){
                if(result.status == 0){
                  is_true = false;
                }
                pmsg.msg(result.msg);
              },
              error:function(){
                alert('服务器异常');
              }
            })
            if(is_true){
              clock(tis);
            }
          } else {
            pmsg.msg('请输入正确的手机号码');
          }
        } else {
          pmsg.msg('请输入手机号码');
        }
        return false;
      });

      $(".submit").click(function(){
        var mobile = $.trim($("#mobile").val());
        var code = $.trim($("#code").val());
        var new_pwd = $.trim($("#new_pwd").val());
        var new_pwd_confirm = $.trim($("#new_pwd_confirm").val());
        if(mobile.length == 0){
          pmsg.msg('请输入手机号码');
          return false;
        }
        if(new_pwd.length == 0){
          pmsg.msg('请输入密码');
          return false;
        }
        if(new_pwd_confirm.length == 0){
          pmsg.msg('请输入确认密码');
          return false;
        }
        if(code.length == 0){
          pmsg.msg('请输入验证码');
          return false;
        }
        if(new_pwd.length < 6 || new_pwd.length > 12){
          pmsg.msg('密码长度6-12个字符');
          return false;
        }
        if(new_pwd != new_pwd_confirm){
          pmsg.msg('两次密码输入不一致');
          return false;
        }
        $.ajax({
          url:"{:U('forget1')}",
          type:"POST",
          dataType:"json",
          data:{
            phone:$.trim($('#mobile').val()),
            code:$("#code").val(),
            new_pwd:new_pwd
          },
          success:function(result) {
            if(result.status == 1){
              pmsg.msg("修改成功");
              setTimeout(function () {
                window.location.href = result.url;
              }, 2000);
            } else {
              pmsg.msg(result.info ? result.info : result.msg);
            }
          },
          error:function(){
            alert("服务器异常");
          }
        })
      })
    });
  </script>
</block>