<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>登录</title>
    <link href="adm/css/login.css" type="text/css" rel="stylesheet">
    <script type="text/javascript" src="adm/js/jquery-1.10.1.js"></script>
</head>
<script>
    function reloadCode() {
        document.getElementById("imgSignCode").src = "/yingjiziyuan/admin/autoCode.do?r=" + new Date().getTime();
    }
</script>

<body style="background-image: url('img/login-bg-3.jpg');background-size: cover;
    background-repeat: no-repeat;
    background-position: center center;padding-bottom: 0px">
<script type="text/javascript">

</script>
<div class="div_top">应急资源管理系统</div>
<div class="login">
    <div class="message" style="
"> 用户登录
    </div>
    <div id="darkbannerwrap"></div>

    <form action="" method="post">
        <input name="action" value="login" type="hidden">
        <input name="uname" required="required" type="text" id="username" placeholder="请输入您的用户名">
        <hr class="hr15">
        <input name="pwd" placeholder="请输入您的账户密码" required="required" type="password" id="userpwd">
        <hr class="hr15">
        <select name="utype" id="utype" style="height: 42px;">
            <option value="管理员">管理员</option>
            <option value="普通用户">普通用户</option>
        </select>
        <hr class="hr15">
        <div class="single-input single-input-half">
            <label>验证码：</label>
            <div style="width:50%;float:left">
                <input type="text" class="input input-big" name="imgCode" id="imgCode" style="width:120px;"
                       required="required"/>
            </div>
            <div class="Codes_region" style="width:50%;float:left">
                <img id="imgSignCode" src="/yingjiziyuan/admin/autoCode.do" onclick="reloadCode()" title="重新获取"/>
            </div>
            <div class="single-input single-input-half" id="checkcode22" style="color:#f00;"></div>
        </div>
        <hr class="hr15">
        <div id="errorInfo" style="color: red"></div>
        <hr class="hr15">
        <input value="登录" style="width:100%;" type="button" id="login_btn">
        <hr class="hr15">
        <a href="doAddReg.do" style="width:100%;" type="button" id="reg_btn">注册</a>
        <a onClick="alert('请联系管理员')">忘记密码</a>
    </form>


</div>

<div class="copyright">版权所有@<span style="color:#f77118"> </span>应急资源管理系统</div>
<script type="text/javascript" src="js/jquery.js"></script>
<script>

    $(function () {
        //触发回车键
        this.enterpress = function (data, event) {
            if (event.keyCode === 13) {
                submit();
            }
            return true;
        }

        $("#login_btn").click(function () {
            submit();
        });

        $("body").bind('keyup', function (event) {
            if (event.keyCode == 13) {
                submit();
            }
        });

        function submit() {
            $("#errorInfo").html("");
            var incode = $("#imgCode").val();
            var uname = $("#username").val();
            var pwd = $("#userpwd").val();
            var utype = $("#utype").val();
            if (uname == "" || uname.length < 1) {
                alert("用户名不能为空");
                $("#user").focus();
                $("#errorInfo").html("用户名不能为空");
                return false;
            }
            if (pwd == "" || pwd.length < 1) {
                alert("密码不能为空");
                $("#errorInfo").html("密码不能为空");
                $("#userpwd").focus();
                return false;
            }
            if (incode == "" || incode.length < 1) {
                alert("验证码不能为空");
                $("#errorInfo").html("验证码不能为空");
                $("#imgCode").focus();
                return false;
            }
            getUserDep(uname, pwd, utype, incode);
        }

        function getUserDep(uname, pwd, utype, incode) {
            $.ajax({
                type: "post",
                url: "alogin.do",
                data: {
                    "uname": uname,
                    "utype": utype,
                    "pwd": pwd,
                    "code": incode
                },
                success: function (re) {
                    res = JSON.parse(re);
                    var status = res[0].status;
                    var data = res[0].data;
                    console.log(status); //[{"status":"1","data":"验证码不正确"}]
                    if (status == 0) {
                        $("#checkLogin").html("登录成功！");
                        window.location.href = "index2.jsp";
                    } else {
                        alert(data);
                        $("#errorInfo").html(data);
                    }
                }

            });
        }
    });

</script>
</body>
</html>
