<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="utf-8"%>
<%@include file="/WEB-INF/ehr/commons/jsp/commonInclude.jsp" %>

<script>
    var loginPage = {
        init:function(){
            var me = this;
            $('#txtPassword').keydown(function(event){
                if(event.which == "13")
                    me.login();
            });

            $("#btnLogin").click(function(){
                me.login();
            });

        },
        login:function(){
            var user = $("#txtUser").val();
            var password = $("#txtPassword").val();
            if(user.length == 0 || password.length ==0)
            {
                $.ligerDialog.error("用户名或密码不能为空！");
                return;
            }
            $.ajax({ //获取表的字段列表
                type: "POST",
                url : "${contextRoot}/system/loginAction",
                dataType : "json",
                data:{user:user,password:password},
                cache:false,
                success :function(data){
                    if(data.successFlg) {
                        var tenantSession = data.data;
                        localStorage.setItem("userRole",tenantSession.role);
                        location.href = "${contextRoot}/indexPage";
                    }
                    else{
                        $.ligerDialog.error(data.message);
                    }
                },
                error :function(data){
                    $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");
                }
            });
        }
    };

    $(function(){
        var urlType = "${urlType}";
        if(urlType != ''){
            location.href = "${contextRoot}/"+urlType+"/loginPage";
        }
        //session过期
        if(location.href.indexOf('loginPage')<0)
        {
            location.href = "${contextRoot}/loginPage";
        }
        //内嵌页面
        if(self.location!=top.location)
        {
            <%--top.location.href = "${contextRoot}/loginPage";--%>
            top.location.href = window.location;
        }
        loginPage.init();
    });

</script>

