@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta lang="ch-Zn">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>BLV RCU | 登录</title>
    <link rel="stylesheet" href="/OT/toastr.min.css" />

    <!-- 离线 Google 字体: Source Sans Pro -->
    <link rel="stylesheet" href="/OT/google.css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="/OT/all.min.css">
    <!-- icheck bootstrap -->
    <link rel="stylesheet" href="/OT/icheck-bootstrap.min.css">
    <!-- 主题样式 -->
    <link rel="stylesheet" href="/OT/adminlte.min.css">
</head>
<body>
    <div class="hold-transition login-page">
        <div class="login-box">
            <div class="login-logo">
                <span><b>宝来威</b>RCU</span>
            </div>

            <!-- /.login-logo -->
            <div class="card">
                <div class="card-body login-card-body">
                    <p class="login-box-msg">帐户登录</p>

                    <div id="data">
                        <div class="input-group mb-3">
                            <input type="text" name="userName" id="userName" class="form-control" placeholder="账号">
                            <div class="input-group-append">
                                <div class="input-group-text">
                                    <span class="fa fa-user"></span>
                                </div>
                            </div>
                        </div>
                        <div class="input-group mb-3">
                            <input type="text" onfocus="this.type='password'" id="pwd" name="pwd" class="form-control" placeholder="密码">
                            <div class="input-group-append">
                                <div class="input-group-text">
                                    <span class="fas fa-lock"></span>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-8">
                                <div class="icheck-primary">
                                    <input type="checkbox" checked id="remember">
                                    <label for="remember">
                                        记住我
                                    </label>
                                </div>
                            </div>
                            <!-- /.col -->
                            <div class="col-4">
                                <button id="btnlog" onclick="Logo();" class="btn btn-primary btn-block">登录</button>
                            </div>
                            <!-- /.col -->
                        </div>
                    </div>


                </div>
                <!-- /.login-card-body -->
            </div>

        </div>
    </div>
    <!-- /.login-box -->
    <script src="/OT/sweetalert2@8.js"></script>

    <!-- jQuery -->
    <script src="/OT/jquery.min.js"></script>
    <!-- Bootstrap 4 -->
    <script src="/OT/bootstrap.bundle.min.js"></script>
    <!-- AdminLTE App -->
    <script src="/OT/adminlte.js"></script>
    <script src="~/js_custom/MyPost.js"></script>
    <script src="/OT/toastr.min.js"></script>
    <script src="~/js/js.cookie.min.js"></script>

    <script>
            $(function(){
        document.onkeydown = function (event) {
            var e = event || window.event;
            if (e && e.keyCode == 13) { //回车键的键值为13
                Logo();
            }
        };
             let rem = Cookies.get('remember');
             console.log(rem)
             if (rem == "true") {
                    $("#remember").prop("checked", rem);
                    $("#userName").val(Cookies.get("userName"));
                    $("#pwd").focus();
                    $("#pwd").val(Cookies.get("pwd"));
                }
            })
            function Logo(){
               $('#btnlog').attr("disabled","true");
                      MyPost("/Login/Logon",{
                          data:{
                              pwd: $("#pwd").val(),
                              userName:$("#userName").val(),
                          },
                          title:"登陆中..."
                          },
                          function(res){
                              if(!res.IsSuccess){
                                  toastr.error(res.Result||'账号或密码有误~')
                                    $('#btnlog').removeAttr("disabled");

                              }else{
                                  Cookies.set('remember', $("#remember").prop("checked"), { path: "/Login" ,expires: 7 });
                                  if($("#remember").prop("checked")){
                                      Cookies.set('pwd', $("#pwd").val(), { expires: 7, path: "/Login" });
                                      Cookies.set('userName', $("#userName").val(), { expires: 7, path: "/Login" });
                                  }else{
                                      Cookies.set('pwd', null, { expires: 7, path: "/Login" });
                                      Cookies.set('userName', null, { expires: 7, path: "/Login" });
                                  }

                                  let old_host = Number( Cookies.get('old_host_'+$("#userName").val()) || -1);

                                  if(old_host > 0 && Number.isFinite(old_host)){
                                          MyPost("/api/Sel/", { data: { id: old_host }, isSwal: false, title: "切换中.." }, (res) => {
                        if (res.IsSuccess) {
                            toastr.error('切换历史酒店失败~')
                        }
                      location.href =  "@(ViewBag.ReURL==string.Empty?"/":ViewBag.ReURL) "
                    })
                                  }else{
                                 location.href =  "@(ViewBag.ReURL==string.Empty?"/":ViewBag.ReURL) "
                                  }
                              }
                          },
                          function(res){
                          $('#btnlog').removeAttr("disabled");
                          console.log(res)
                          toastr.error('网络繁忙~')
                          }
                      );
                  }
    </script>
</body>
</html>
