<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<%@ taglib prefix="webpath" uri="/WEB-INF/tlds/path.tld"%>
<%@ taglib prefix="webpage" uri="/WEB-INF/tlds/pageview.tld"%>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>后台系统</title>
<link href="<webpath:path/>/resources/frame/style/authority/login_css.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<webpath:path/>/resources/frame/scripts/jquery/jquery-1.7.1.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
		$("#login_sub").click(function(){
			$("#submitForm").attr("action", "index.html").submit();
		});
	});
	
	/*回车事件*/
	function EnterPress(e){ //传入 event 
		var e = e || window.event; 
		if(e.keyCode == 13){ 
			$("#submitForm").attr("action", "index.html").submit();
		} 
	} 
</script>
</head>
<body>
	<div id="login_center">
		<div id="login_area">
			<div id="login_box">
				<div id="login_form">
					<form id="submitForm" action="" method="post">
						<div id="login_tip">
							<span id="login_err" class="sty_txt2"></span>
						</div>
						<div>
							 用户名：<input type="text" name="userName" class="username" id="name">
						</div>
						<div>
							密&nbsp;&nbsp;&nbsp;&nbsp;码：<input type="password" name="pwd" class="pwd" id="pwd">
						</div>
						<div id="btn_area">
							<input type="button" class="login_btn" id="login_sub"  value="登  录">
							<input type="reset" class="login_btn" id="login_ret" value="重 置">
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
	<script type="text/javascript">
		$().ready(function() {
			
			$("#login_form").validate({
				rules:{
					userName:{
						required: true
				      	},
				    pwd:{
						required:true
					    }
					},
				messages:{
					userName:{
						required:"请填写用户名!"
				      	},
				    pwd:{
						required:"请填写密码!"
				      	}
					},
				submitHandler:function(form){
					var userName=$('#userName').val();
					var pwd=$('#pwd').val();
					$.ajax({
						  type: 'POST',
						  url: '/api/signin',
						  dataType:'json',
						  data: {
							  userName:userName,
							  pwd:pwd
						  },
						  success: function(data){
							  var status = data.status;
								if(status == 1)
									window.location.href = webPath + "/default";
								}else if(status == 0){
									bootbox.dialog({
										message:"请核对用户名或密码是否正确！",
										buttons:{
											"success":{
												"label":"OK",
												"className":"btn-sm btn-primary"
												}
											}
										});
								} else if (status == 2){
									window.location.href = webPath + "/api/user/list";
								}
							  }
						});
				}
			});
			
		});
		
	</script>
</body>
</html>