<%@include file="/WEB-INF/common/layouts/common.jsp" %>
<%@ page language="java" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>全链条精准导购系统 - 登录</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <link rel="icon" href="${static_common}/img/favicon.ico" type="image/x-icon"/>
</head>
<body class="login_bg">
<div class="login_wap">
    <div class="logo"></div>
    <div class="login_form">
        <!--错误提示-->
        <div class="msg" style="display: none"></div>
        <!--错误提示-->
        <div class="tab clearfix">
            <div class="tab_slc tab_con fl">
                用户登录
                <div class="tab_on"></div>
            </div>
        </div>
        <form action="${ctx}/doLogin" method="post" id="loginForm">
            <div class="login_list">
                <div class="login_con">
                    <div class="pre input_nor">
                        <span class="iconfont">&#xe608;</span>
                        <input type="text" id="account" name="account" placeholder="请输入用户名" maxlength="12"
                               style="text-indent:10px;"/>
                    </div>
                    <div class="pre input_nor mt25">
                        <span class="iconfont">&#xe635;</span>
                        <input type="password" id="password" name="password" placeholder="请输入密码"
                               style="text-indent:10px;"/>
                    </div>
                    <div class="clearfix mt20">
                        <div class="fl clearfix">
                            <input type="checkbox" class="fl check" id="autoLogin" name="autoLogin"/><span class="fl">记住密码</span>
                        </div>
                        <a class="fr pass" onclick="forgetPwd()">忘记密码？</a>
                    </div>
                    <button class="login_btn mt20" type="button" id="btn" onclick="login()">登录</button>
                    <input type="hidden" id="md5Flag" value="0">
                    <input type="hidden" id="errorMSG" value="${errorMessge}">
                </div>
            </div>
        </form>
    </div>
    <div class="footer" align="center">
        <p class="link"><a href="http://www.house365.com/about/aboutus.php" target="_blank" rel="nofollow">关于我们</a> | <a
                href="http://www.house365.com/about/contactus.php?city=wx" target="_blank" rel="nofollow">联系我们</a> | <a
                href="http://www.house365.com/about/joinus.php?pid=1&amp;city=wx" target="_blank"
                rel="nofollow">招聘信息</a> | <a href="http://www.house365.com/about/friendlink.php?city=wx" target="_blank"
                                             rel="nofollow">友情链接</a> | <a
                href="http://www.house365.com/about/partner.php?city=wx" target="_blank" rel="nofollow">合作伙伴</a> | <a
                href="http://www.house365.com/about/statement.php" target="_blank" rel="nofollow">法律声明</a> | <a
                href="http://wx.house365.com/sitemap.html" target="_blank" rel="nofollow">网站地图</a></p>
        © 2006-2015 365淘房 江苏三六五网络股份有限公司<br/>
        苏ICP证编号 B2-20110162 信息网络传播视听节目许可证 1009365 号
    </div>
</div>

<link rel="stylesheet" href="${ctx}/resources/login/css/reset.css">
<link rel="stylesheet" href="${ctx}/resources/login/iconfont/iconfont.css">
<link rel="stylesheet" href="${ctx}/resources/login/css/yz_login.css">
<script src="${ctx}/resources/login/js/jquery-1.11.1.min.js"></script>
<script src="${ctx}/resources/login/js/jQuery.md5.js"></script>
<script>
    $(function () {
        //超时后，iframe页，顶层window跳转至登陆页
        if (window.top != window) {
            window.top.location = window.location;
        }

        $(".input_nor input").focus(function () {
            $(this).parent("div").addClass("input_hover");
        });
        $(".input_nor input").blur(function () {
            $(this).parent("div").removeClass("input_hover");
        });

        tabChange("tab .tab_con");

        var account = '${account2}';
        var password = '${password2}';
        if (account != '' && password != '') {
            $("#account").val(account);
            $("#password").val(password);
            $("input[name='autoLogin']").attr("checked", "checked");
            //auto login
//            setTime(2);

        }
        $("#password").change(function () {
            $("#md5Flag").val(1);
        })

        if ($("#errorMSG").val() != '') {
            $(".msg").attr("style", "display: block");
            $(".msg").html($("#errorMSG").val());
        }
    });

    function tabChange(tabChange) {
        $("." + tabChange).click(function () {
            var l = $(this).prevAll("div").size();
            var len = l;
            $(this).addClass("tab_slc");
            $(this).nextAll("div").removeClass("tab_slc");
            $(this).prevAll("div").removeClass("tab_slc");
            $(".login_list").children(".login_con").hide();
            $(".login_list").children(".login_con").eq(len).show();
        });
    }

    /* $("input[name='autoLogin']").bind("click", function () {
     if(document.getElementById("autoLogin").checked){
     document.getElementById("autoLogin").value = true;
     }else{
     document.getElementById("autoLogin").value = false;
     }
     }); */

    function setTime(i) {
        $("input[name='account']").attr("readonly", "readonly");
        $("input[name='password']").attr("readonly", "readonly");
        var btn = document.getElementById("btn")
        btn.disabled = true
        i--;
        $("#btn").html("<img src='${ctx}/resources/house365/login/images/spinner.gif'/>&nbsp;登陆");
        if (i == 0) {
            autologin();
        } else {
            setTimeout("setTime(" + i + ")", 1000)
        }

    }

    var login = function () {
        // 生产环境只允许通过 OA 登录，测试和开发环境依然允许登录页登录
        if ("${env}" == "production") {
            alert("抱歉，只允许通过OA登录！");
            return;
        }
        if ($("#account").val() == "") {
            $(".msg").attr("style", "display: block");
            $(".msg").html("请填写用户名");
            return;
        }
        var s = $("#account").val();
        var a = s.split("");
//        if (a.length != 11 && s != 'admin') {
//            $(".msg").attr("style", "display: block");
//            $(".msg").html("请填写正确的用户名");
//            return;
//        }
        if ($("#password").val() == "") {
            $(".msg").attr("style", "display: block");
            $(".msg").html("请填写密码");
            return;
        }
        var pd = $("#password").val();
        var account = '${account2}';
        var password2 = '${password2}';
        //浏览器记住密码时会覆盖，重置一次
        //if(password2 && password2!=pd){
        //$("#password").val(password2);
        // }
        //切换用户登录，重新md5
        /*  if (!password2 || (account && account != $("#account").val())) {
         $("#password").val($.md5(pd));
         } */
        if ($("#md5Flag").val() == 1) {
            $("#password").val($.md5(pd));
        }
        $("#btn").text("登录中...");
        var $form = $("#loginForm");
        $.ajax({
            url: $form.attr("action") + "?s=" + Math.random(),
            type: "POST",
            data: $form.serialize(),
            success: function (data) {
                if (data != null) {
                    if (data === "limit_error") {
                        alert("在公司外登录请联系主管授权,授权通过后请在3分钟内完成登录")
                        return false;
                    }
                    if (data === "limit_error1") {
                        alert("请求超过10分钟未授权,请联系主管授权")
                        return false;
                    }
                    if (data === "limit_error2") {
                        alert("授权超过3分钟未登陆,请重新联系主管授权")
                        return false;
                    }
                    if (data === "limit_error3") {
                        alert("授权失效请重新联系主管授权")
                        return false;
                    }
                    if (data === "success") {
                        window.location.href = "${ctx}/index";
                    }
                    if (data === "all_error") {
                        $(".msg").attr("style", "display: block");
                        $(".msg").html("用户名和密码不能为空！");
                        $("#btn").text("登录");
                    }
                    if (data === "account_error") {
                        $(".msg").attr("style", "display: block");
                        $(".msg").html("账户不存在！");
                        $("#btn").text("登录");
                    }
                    if (data === "password_error") {
                        $(".msg").attr("style", "display: block");
                        $(".msg").html("密码不正确！请重新输入！");
                        $("#password").val("");
                        $("#btn").text("登录");
                    }
                    if (data === "login_error") {
                        $(".msg").attr("style", "display: block");
                        $(".msg").html("用户名或密码错误，请重新登录");
                        $("#btn").text("登录");
                    }
                    if (data === "account_disabled") {
                        $(".msg").attr("style", "display: block");
                        $(".msg").html("该账户已被锁定，禁止登录");
                        $("#btn").text("登录");
                    }

                }
            }
        });

    };

    var autologin = function () {
        if ($("#account").val() == "") {
            $(".msg").attr("style", "display: block");
            $(".msg").html("请填写用户名");
            return;
        }
        var s = $("#account").val();
        var a = s.split("");
        if (a.length != 11 && s != 'admin') {
            $(".msg").attr("style", "display: block");
            $(".msg").html("请填写正确的用户名");
            return;
        }
        if ($("#password").val() == "") {
            $(".msg").attr("style", "display: block");
            $(".msg").html("请填写密码");
            return;
        }
        var $form = $("#loginForm");
        $.ajax({
            url: $form.attr("action") + "?s=" + Math.random(),
            type: "GET",
            data: $form.serialize(),
            success: function (data) {
                if (data != null) {
                    if (data === "limit_error") {
                        alert("在公司外登录请联系主管授权,授权通过后请在3分钟内完成登录")
                        return false;
                    }
                    if (data === "limit_error1") {
                        alert("请求超过10分钟未授权,请联系主管授权")
                        return false;
                    }
                    if (data === "limit_error2") {
                        alert("授权超过3分钟未登陆,请重新联系主管授权")
                        return false;
                    }
                    if (data === "limit_error3") {
                        alert("授权失效请重新联系主管授权")
                        return false;
                    }

                    if (data === "success") {
                        window.location.href = "${ctx}/index";
                    }
                    if (data === "all_error") {
                        $(".msg").attr("style", "display: block");
                        $(".msg").html("用户名和密码不能为空！");
                    }
                    if (data === "account_error") {
                        $(".msg").attr("style", "display: block");
                        $(".msg").html("账户不存在！");
                    }
                    if (data === "password_error") {
                        $(".msg").attr("style", "display: block");
                        $(".msg").html("密码不正确！请重新输入！");
                        $("#password").val("");
                    }
                    if (data === "login_error") {
                        $(".msg").attr("style", "display: block");
                        $(".msg").html("登陆异常！请与管理员联系！");
                    }

                }
            }
        });

    };


    var forgetPwd = function () {
        window.location.href = "${ctx}/klftobackpwd";
    }

    //按Enter键登录
    document.onkeydown = function (e) {
        var theEvent = window.event || e;
        var code = theEvent.keyCode || theEvent.which;
        if (code == 13) {
            login();
        }
    }

</script>
<style>
    input:-webkit-autofill {
        -webkit-box-shadow: 0 0 0 1000px white inset;
        border: 1px solid #d9d9d9 !important;
        border-left: none !important;
        height: 38px !important;
        line-height: 38px !important;
    }
</style>
</body>
</html>
