<%@ page language="java" contentType="text/html;charset=UTF-8" %> 
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ page isELIgnored="false" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>用户管理</title>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" href="<%=request.getContextPath() %>/js/bootstrap/css/bootstrap.min.css">
	<link rel="stylesheet" href="<%=request.getContextPath() %>/js/bootstrap/css/bootstrap-theme.min.css">
	<script type="text/javascript" charset="utf-8" src="<%=request.getContextPath() %>/js/jquery/jquery-1.11.2.min.js"></script>
	<script type="text/javascript" charset="utf-8" src="<%=request.getContextPath() %>/js/bootstrap/js/bootstrap.min.js"></script>
	<script type="text/javascript" charset="utf-8" src="<%=request.getContextPath() %>/js/jquery.twbsPagination/jquery.twbsPagination.js"></script>
</head>
<body>
<br/>
<div class="container-fluid">
	<form:form cssClass="form-horizontal" action="" >
	<div class="panel panel-default">
		<div class="panel-heading">
			用户管理
		</div>
		<div class="panel-body">
			<div class="form-group-sm">
				<label class="control-label col-md-1">名称:</label>
				<div class="col-md-3">
					<input type="text" name="userName" value="${param.userName}" class="form-control" placeholder="">
				</div>
			</div>
		</div>
	</div>

<div class="form-group-sm text-center padding10" >
	<a href="<%=request.getContextPath()%>/sys/preAddUser.do" class="btn btn-sm btn-info">添加</a>
	<button type="button" id="subbtn" class="btn btn-sm btn-success">查询</button>
	<button type="reset" class="btn btn-sm btn-default" id="reset">重置</button>
</div>

<div class="panel panel-default">
	<table class="table table-striped table-hover">
		<thead>
		<tr >
			<th  class="text-center order" data-field="name" data-order="asc,1" >
				姓名
			</th>
			<th data-field="telNum" class="text-center order">
				角色
			</th>
			<th data-field="telNum" class="text-center order">
				性别
			</th>
			<th data-field="" class="text-center order">
				创建时间
			</th>
			<th data-field="" class="text-center order">
				最近登陆
			</th>
			<th data-field="" class="text-center order">
				登陆次数
			</th>
			<th data-field="email" class="text-center order">
				操作
			</th>
		</tr>
		</thead>
		<tbody>
		<c:forEach var="item" items="${pageList.list}">
			<tr>
				<td class="text-center">${item.userName}</td>
				<td class="text-center">${item.role=='0'?'guest':'admin'}</td>
				<td class="text-center">${item.sex=='0'?'男':'女'}</td>
				<td class="text-center"><fmt:formatDate value="${item.createDate }" pattern="yyyy-MM-dd HH:mm:ss" /></td>
				<td class="text-center"><fmt:formatDate value="${item.lastLoginDate }" pattern="yyyy-MM-dd HH:mm:ss" /></td>
				<td class="text-center">${item.loginCount}</td>
				<td class="text-center">
					<button type="button" class="btn btn-sm btn-danger" id="deleteStaffBtn" onclick="del(${item.userId})">删除</button>
				</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
</div>
		<input type="hidden" id="pageval" name="page" class="form-control" value="${param.page==null?1:param.page}">
		<input type="hidden" name="limit" class="form-control" value="10">
<div class="text-center">
	<nav id="pagination_box"><ul class="pagination" id="pagercontent"></ul></nav>
</div>

</form:form>
</div>
<script>
	$("#subbtn").on("click",function(){
		$('#pageval').val(1);
		$("form").submit();
	})
	$('#pagercontent').twbsPagination({
		startPage: ${param.page==null?1:param.page},
		initiateStartPageClick: false,
		totalPages: ${pageList.totalCount}==0?1:Math.ceil(${pageList.totalCount}/10),
			onPageClick: function (event, page) {
		$('#pageval').val(page);
		$("form").submit();
	}
	});
	$("#reset").on("click",function(){
		window.location.href="list.do";
	})
	function del(id){
		$.ajax({
			type : "post",
			url : "delUser.do",
			data : {id:id},
			dataType : "json",
			success : function(json){
				console.log(json);
				window.location.reload();
			},
			error:function(e){
				console.log(e);
			}
		});
	}
</script>
</body>
</html>
