{extend name="./main"}

{block name="CSS"}
<style>
    .span_check_tip,#newusernameTip,#password1Tip,#password2Tip,#newqqTip,#newemailTip {
        color: orangered;
        position: absolute;
        bottom:-36px;
        left:0;
    }
    .user_input {
        position: relative;
    }
</style>
{/block}

{block name="content"}
<div class="user_form">
    <form role="form" method="post" action="/index/user/doForgetPassword">
        <input type="hidden" name="__token__" value="{$Request.token}" />
        <div class="user_tab"><ul><li><a href="#">忘记密码</a></li></ul></div>
        <div class="clear"></div>
        <div class="user_input"><i class="iconfont icon-gerenzhongxin"></i><input type="text" name="mobile" id="mobile" placeholder="输入手机号"></div>
        <div class="user_input"><i class="iconfont icon-mima"></i><input type="password" name="password" placeholder="输入新密码"></div>
        <div class="user_input"><i class="iconfont icon-mima"></i><input type="password" name="password_confirm" placeholder="确认新密码"></div>
        <div class="user_input">
        	<i class="iconfont icon-mima"></i><input type="text" name="code" placeholder="手机验证码" class="lxfs">
        </div>
        <button type="button" id="click_checkcode" style="background: #d9ee97 !important;">获取验证码</button>
        <button type="submit">修改密码</button>
    </form>
</div>

<script type="text/javascript">
    $(function(){
        $('#click_checkcode').on('click',getCode);
    });
    var token = "{$sms_token}";
    function getCode(){
        var phone=$('#mobile').val();
        //var name=$('#mobile').val();
        var reg=/\d{11}/;
        if(phone=='' || !reg.test(phone)){
            alert('请填写正确的手机号码！');
            $('#mobile').focus();
            return false;
        }
        layer.prompt({
            title: '请输入验证码',
            formType: 3
        }, function (chkcode) {
            $('.getcode .code').off('click');
            $.post('/forget/sms',{chkcode: chkcode,token:token,phone:phone,t:new Date().getTime()},function(ret){
//                        console.log(ret);
                if(ret.status===1){
                    layer.closeAll();
                    alert(ret.msg);
                    token = ret.data.token;
                    $('.getcode a i.t').html('<i class="times">80</i>秒后重发');
                    timeC(80);
                } else {
                    alert(ret.msg);
                    $('.getcode .code').on('click',getCode);
                }
            },'json');
        })
        $('.layui-layer-prompt .layui-layer-content').prepend($(
            '<img style="cursor:pointer;height: 60px;" id="chkcode_img" src="/chkcode" onclick="javascript:this.src=\'/chkcode\'+\'?time=\'+Math.random()">'
        ))
    }

    function timeC(t){
        if(t==0){
            $('.getcode .code').on('click',getCode);
            $('.getcode a i.t').text('获取验证码');
        } else {
            t=t-1;
            $('.getcode a i.times').text(t);
            setTimeout('timeC('+t+')',1000);
        }
    }
</script>
{/block}
