
@{
    ViewBag.Title = "Index";
}

@using System.Data;
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link href="~/layuiadmin/layui/css/layui.css" rel="stylesheet" media="all" />
    <script src="~/layuiadmin/layui/layui.js"></script>
    <link href="~/layuiadmin/style/admin.css" rel="stylesheet" media="all" />
    <link href="~/layuiadmin/style/login.css" rel="stylesheet" />
    <script src="~/Content/jquery-1.8.3.js"></script>
    <script src="~/Content/base64.js"></script>
    <script type="text/javascript">
        var Language = "";
        window.onload = function () {
            var strS = window.location.search;
            if (strS != "" && strS.indexOf('?') != -1) {
                //document.getElementById('LAY-user-login').style.display = 'none';
                var strLocation = strS.replace('?', '');
                var arrayLocation = window.atob(strLocation).split('&');
                if (arrayLocation.length = 2) {
                    $("input[name='UserName']").val(arrayLocation[0]);
                    $("input[name='PassWord']").val(arrayLocation[1]);
                }
                loginMethod();
            };

            $.ajax({
                url: "/Login/GetLanguage",
                type: "post",
                dataType: "text",
                ContentType: "applocation/json;charset=utf-8",
                success: function (res) {
                    Language = res;
                    loadPage(res);
                }
            });
        };

        document.onkeydown = function () {
            if (event.keyCode == 13) {
                loginMethod();
            }
        };
        $(document).ready(function () {
            if (window != top) {
                top.location.href = location.href;
            }
        });
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use('layer', function () {
            var layer = layui.layer;
            $("#btn_login").click(function () {
                loginMethod();
            });
        });

        function loginMethod() {
            $.ajax({
                url: "/Login/Login",
                data: {
                    UserName: $("input[name='UserName']").val(),
                    PassWord: $("input[name='PassWord']").val()
                },
                type: "post",
                dataType: "text",
                ContentType: "applocation/json;charset=utf-8",
                success: function (data) {
                    Language = data.split(',')[1];
                    data = data.split(',')[0];
                    if (data == "1") {
                        if (Language == "EN") {
                            window.location.href = "@Url.Action("IndexEN", "Home")";
                        }
                        else {
                            window.location.href = "@Url.Action("Index", "Home")";
                        }
                    } else if (data == "0") {
                        if (Language == 'EN') {
                            alert("wrong user name or password");
                        }
                        else {
                            alert("用户名或密码错误");
                        }
                    } else if (data == "-1") {
                        if (Language == 'EN') {
                            alert("The current system is not authorized, please try again after authorization");
                        }
                        else {
                            alert("当前系统未授权,请授权后重试");
                        }
                    }

                },
               error: function (data) {
                   if (Language == 'EN') {
                       alert("network timeout");
                   }
                   else {
                       alert("网络超时");
                   }
                }
            });
        };

        function loadPage(res) {
            if (res == 'EN') {
                $(document).attr('title', 'Switch Communication Management System-Query Side');
                document.getElementById("hLogin").innerText = "Query Aide";
                document.getElementById("btn_login").innerText = "Login";
                $("#LAY-user-login-username").attr('placeholder', "UserName");
                $("#LAY-user-login-password").attr('placeholder', "PassWord");
            }
            else {
                $(document).attr('title', '交换机通讯管理系统-查询统计平台');
                document.getElementById("hLogin").innerText = "查询统计平台";
                document.getElementById("btn_login").innerText = "登 录";
                $("#LAY-user-login-username").attr('placeholder', "用户名");
                $("#LAY-user-login-password").attr('placeholder', "密码");
            }
        }

    </script>
</head>
<body class="layui-layout-body">
    <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
        <div class="layadmin-user-login-main">
            <div class="layadmin-user-login-box layadmin-user-login-header">
                <h1 id="hLogin"></h1>
            </div>
            <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
                    <input type="text" name="UserName" id="LAY-user-login-username" lay-verify="required" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
                    <input type="password" name="PassWord" id="LAY-user-login-password" lay-verify="required" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit" id="btn_login"></button>
                </div>

            </div>
        </div>
    </div>
</body>
</html>