<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <title>超级蚂蚁---SuperAnt</title>
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="/favicon.ico">
    <link rel="stylesheet" href="<?php echo base_url();?>public/css/vendor/bootstrap/dist/bootstrap.css">
    <link rel="stylesheet" href="<?php echo base_url();?>public/css/vendor/Animate.css">
    <link rel="stylesheet" href="<?php echo base_url();?>public/css/basic.css">
    <link rel="stylesheet" href="<?php echo base_url();?>public/css/vendor/font_awesome/css/font-awesome.css">
    <!--[if lt IE 9]>
    <script src="<?php echo base_url();?>public/js/vendor/html5shiv.min.js"></script>
    <script src="<?php echo base_url();?>public/js/vendor/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="container">
    <form class="form-signin" method="post" action="">
        <h3 style="font-size: 38px;">SuperAnt---CMS</h3>
        <div class="form-group">
            <!--[if lte IE 9]><label>用户名</label><![endif]-->
            <input type="text" id="usernameInput" class="form-control" name='username' placeholder="用户名" required="required" autofocus="autofocus">
        </div>
        <div class="form-group">
            <input type="text" class="form-control" name='pwd' placeholder="密码" required="required" style="width: 57%;display: inline-block;">
            <button class="btn btn-lg btn-primary" onclick="sendAuth()" type="button">发送验证码</button>
        </div>
<!--        <div class="form-group" style="position:relative;">-->
            <!--[if lte IE 9]><label>验证码</label><![endif]-->
            <!--[if lte IE 9]><style type="text/css">.J_verify_code{top:33px !important;}</style><![endif]-->
            <!-- <input type="text" class="form-control" placeholder="验证码" name="captcha" required="required">
            <div class="J_verify_code" style="cursor:pointer;position:absolute;top:8px;right:6px;">
            </div> -->
<!--        </div>-->
        <button class="btn btn-lg btn-primary btn-block subBtn" type="submit">登录</button>
    </form>
</div>


<script src="<?php echo base_url();?>public/js/vendor/jquery.min.js"></script>
<script src="<?php echo base_url();?>public/js/vendor/bootstrap/dist/bootstrap.js"></script>
<script src="<?php echo base_url();?>public/js/vendor/ie10-viewport-bug-workaround.js"></script>
</body>
<script type="text/javascript">
    function getcaptcha() {
        $.get(
            "<?php echo base_url('login/captcha');?>",
            function(data) {
                $('.J_verify_code').html(data);
            }
        );
    }
    getcaptcha();

    $('.J_verify_code').click(function(){
        getcaptcha();
    });

    /**
    * 登陆AJAX
    */
    $(".subBtn").click(function(){
        var formData = $("form").serialize();
        $.ajax({
            type: "POST",
            url:"<?php echo base_url('login/actionlogin');?>",
            dataType: 'json',
            data: formData,
            success: function(e){
                if( e.code == -1 ){
                    alert('验证码错误');
                }else if( e.code == -2 ){
                    alert('用户名错误');
                }else if( e.code == -3 ){
                    alert('验证码错误');
                }else if( e.code == -4) {
                    alert('用户权限错误');
                }else {
                    window.location = "<?php echo base_url('#welcome/dashboard');?>";
                }
            },
        });
        return false;
    });

    function sendAuth() {
        var name = $('#usernameInput').val();
        if(name == ""){
            alert('用户名不能为空');
        }
        $.post("<?php echo base_url('login/wechat');?>",{
            username:name
        },function (e) {
            e = JSON.parse(e);
            if( e.code == -2 ){
                alert('用户名错误');
            }else if( e.code == -3 ){
                alert('请跟管理联系');
            }else{
                alert('发送成功');
            }
        })
    }

</script>
</html>