<%@ 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="taglib.title"/></fb:property>

	<fb:script type="text/javascript">
		<script>
			var tool,table_obj;
			layui.use([ 'tool', 'trta' ], function() {
				tool = layui.tool, trta = layui.trta,form = layui.form, $ = layui.jquery;
				//
				table_obj = trta.render({
					elem : '#treeTable',
					url : '${base}/user/tree',
					tree : {
						iconIndex : 1, // 折叠图标显示在第几列
						idName : 'id', // 自定义id字段的名称
						pidName : 'parent', // 自定义标识是否还有子节点的字段名称
						isPidData : true, // 是否是pid形式数据
					},
					cols : [ [ {
						type : 'numbers'
					}, {
						title : '<spring:message code="dir.company"/>',
						templet:'#company',
						width: 300
					},
					{
						title : '<spring:message code="username"/>',
						templet:'#name',
						width : 200
					} ,
						{
							title : '<spring:message code="role"/>',
							templet:'#roleName',
							width : 200
						},
						{
							title : '<spring:message code="enable"/>',
							align : 'center',
							templet : '#isEnable',
							width : 100
						}
						,
						{
							title : '<spring:message code="dir.createDate"/>',
							templet:'#createDate',
							width : 200
						}
						,{
							title : 'id',
							templet:'#id',
						}] ]
				});

				$("#refresh").on("click",function(){
					table_obj.reload()
				})

				$("#add").on("click",function(){
					tool.dialog('${base}/user/form?id=-1', '78%', function(){
						table_obj.reload()
					});
				})

				// 切换
				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);
				});

			});



			function edit(id) {
				tool.dialog('${base}/user/form?id=' + id, '70%', function(){
					table_obj.reload()
				});
			}



		</script>

	</fb:script>

	<fb:layout>

		<script type="text/html" id="id">
			{{#  if(d.id.indexOf("o_") > -1){ }}
					{{d.id.substr(2, d.id.length)}}
			{{#  } else { }}
					{{d.id}}
			{{#  } }}
		</script>
		<script type="text/html" id="name">
			{{#  if(d.id.indexOf("o_") > -1){ }}
			{{#  } else { }}
			{{d.name}}
			{{#  } }}
		</script>

		<script type="text/html" id="roleName">
			{{#  if(d.id.indexOf("o_") > -1){ }}
			{{#  } else { }}
			{{d.roleName}}
			{{#  } }}
		</script>

		<script type="text/html" id="createDate">
			{{#  if(d.id.indexOf("o_") > -1){ }}
			{{#  } else { }}
			{{d.createDate}}
			{{#  } }}
		</script>

		<script type="text/html" id="company">
			{{#  if(d.id.indexOf("o_") > -1){ }}
			{{d.company}}
			{{#  } else { }}
			<a onclick="edit('{{d.id}}')" href="#" ><spring:message code="dir.edit"/><spring:message code="userInfo"/></a>
			{{#  } }}
		</script>

		<script type="text/html" id="isEnable">
			{{#  if(d.id.indexOf("o_") > -1){ }}
			{{#  } else { }}
			<input type="checkbox" name = "isEnable" value = {{d.isEnable}} lay-skin="primary" mid={{d.id}}  lay-filter="isEnable" {{ d.isEnable == '0' ? 'checked' : '' }}>
			{{#  } }}
		</script>


		<div class="layui-card">
			<button id="refresh" type="button" class="layui-btn layui-btn-primary layui-btn-sm refresh"><spring:message code="refresh"/></button>
			<button id="add" type="button" class="layui-btn layui-btn-primary layui-btn-sm refresh"><spring:message code="add"/></button>
			<table id="treeTable" class="layui-hide" lay-filter="table" />
		</div>

	</fb:layout>
</fb:ui>