<%@ page language="java" contentType="text/html;charset=UTF-8" trimDirectiveWhitespaces="true"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fastboot" prefix="fb"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<fb:ui src="base/main">

	<fb:property name="title"><spring:message code="user.title"/></fb:property>

	<fb:script type="text/javascript">
		<script>
			layui.use([ 'tool', 'form' ], function() {
				//
				var table_obj;
				//
				var tool = layui.tool, form = layui.form, $ = layui.jquery;
				//
				var options = {
					url : '${base}/user/page',
					toolbar : '#toolbar',
					limit : 20,
					cols : [ [ {
						type : 'checkbox',
					}, {
						field : 'id',
						title : 'ID',
						align : 'center',
					}, {
						field : 'nickname',
						title : '<spring:message code="nickname"/>',
						templet : '#name'
					}, {
						field : 'username',
						title : '<spring:message code="username"/>'
					},{
						field : 'organName',
						title : '<spring:message code="organ"/>'
					}, {
						field : 'roleName',
						title : '<spring:message code="role"/>',
						align : 'center'
					}, {
						field : 'isEnable',
						title : '<spring:message code="enable"/>',
						align : 'center',
						templet : '#isEnable'
					}, {
						field : 'createDate',
						title : '<spring:message code="dir.createDate"/>',
						align : 'center'
					}, {
						field : 'updateDate',
						title : '<spring:message code="image.updateDate"/>',
						align : 'center'
					}, {
						toolbar : '#tool',
						title : '<spring:message code="dir.tool"/>',
						align : 'center',
						width : 120
					} ] ],
					search : function() {
						var keyword = $('#keyword').val();
						//执行重载
						table_obj.reload({
							where : {
								keyword : keyword
							}
						});
					},
					add : function() {
						tool.dialog('${base}/user/form?id=-1', '78%');
					},
					info : function(data) {
						tool.dialog('${base}/user/form?id=' + data.id, '70%');
					}
				};
				// 分页
				table_obj = tool.page(options);
				// 切换
				form.on('checkbox(isEnable)', function(obj) {
					var data = new Object();
					data.isEnable = obj.elem.checked ? "0" : "1";
					data.id = $(this).attr('mid');
					tool.post("${base}/user/updateEnable", data);
				});
			});
		</script>
	</fb:script>

	<fb:layout>


		<script type="text/html" id="isEnable">
			<input type="checkbox" name = "isEnable" value = {{d.isEnable}} lay-skin="primary" mid={{d.id}}  lay-filter="isEnable" {{ d.isEnable == '0' ? 'checked' : '' }}>
		</script>

		<script type="text/html" id="tool">
			<a class="layui-btn layui-btn-xs" lay-event="info"><spring:message code="dir.edit"/></a>
		</script>

		<script type="text/html" id="toolbar">
 		 	<div class="layui-btn-container">
				<div class="layui-inline" title="<spring:message code="dir.search"/>" lay-event="search"><i class="layui-icon layui-icon-search"></i></div>
				<div class="layui-inline" title="<spring:message code="taglib.addnew"/>" lay-event="add"><i class="layui-icon layui-icon-addition"></i></div>
  			</div>
		</script>


		<div class="layui-form">
			<div class="layui-inline">
				<div class="layui-input-inline" style="width: 300px;">
					<input type="text" id="keyword" placeholder="ID、<spring:message code="account"/>、<spring:message code="nickname"/>" autocomplete="off" class="layui-input">
				</div>
			</div>
		</div>

		<div class="layui-card">
			<table id="table" class="layui-hide" lay-filter="table" />
		</div>
	</fb:layout>
</fb:ui>