<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/layui/css/layui.css"
	  media="all">
<link rel="stylesheet" href="/com/com.css" media="all">
<script src="/jquery/jquery.min-1.12.3.js" charset="utf-8"></script>
<script src="/com/com.js" charset="utf-8"></script>
<link rel="stylesheet"
	href="/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">

<script type="text/javascript"
	src="/ztree/js/jquery.ztree.core.js"></script>

<meta charset="utf-8">
<title>layui</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<style type="text/css">
.leftPart {
	float: left;
	width: 250px;
}

.rightPart {
	postion: absuloted;
	margin-left: 200px;
}

#treeDemo {
	border: 1px solid #e4e4e4;
	background: #fff;
	width: 230px;
	height: 600px;
	overflow-y: scroll;
	overflow-x: auto;
}
</style>
</head>
<body>

	<div style="height: 5px;"></div>

	<div class="zTreeDemoBackground leftPart">



		<ul id="treeDemo" class="ztree"></ul>

	</div>

	<div class="rightPart">
		<div class="demoTable">
			搜索工号或姓名：
			<div class="layui-inline">
				<input class="layui-input" name="qname" id="qname" plete="off">
			</div>
			<button class="layui-btn" data-type="reload" id="searchdata">搜索</button>
		</div>
		<table class="layui-hide" id="LAY_table_user" lay-filter="user"></table>
		<div style="text-align: right; padding: 10px" class="submitselect">

<!-- <form class="layui-form" action="">

			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">节点名称</label>
					<div class="layui-input-inline">
						<select name="nodenames" id="nodenames" >
							<option value="">选择节点名称</option>
							
						</select>
					</div>
				</div>
			</div>
			</form> -->
			<input type="text" hidden="true" value="${id}" id = "syscodeId"></input>
			<button class="layui-btn layui-btn-lg savedata_"
				data-type="submit_data">确定</button>
		</div>
	</div>


	<script src="/layui/layui.all.js" charset="utf-8"></script>
	<script>
var setting = {
		data : {
			key : {
				title : "t"
			},
			simpleData : {
				enable : true
			}
		},
		callback : {
			beforeClick : beforeClick,
			onClick : onClick
		}
	};

	
	var log, className = "dark";
	function beforeClick(treeId, treeNode, clickFlag) {
		className = (className === "dark" ? "" : "dark");
		return (treeNode.click != false);
	}
	var departmentId = "";
	function onClick(event, treeId, treeNode, clickFlag) {
		departmentId = treeNode.id;
		console.log(departmentId);
		$('#qname').val('');
		$("#searchdata").click();
		
	}
	function getTime() {
		var now = new Date(), h = now.getHours(), m = now.getMinutes(), s = now
				.getSeconds();
		return (h + ":" + m + ":" + s);
	}
	
	
	
	/* function nodeNames(){
		
		AjaxTool.XPost("/common/getNodeNames", {}, function(data) {
			var treeData = data.data;
			var html = "";
			for(var i=0;i<treeData.length;i++){
				html+='<option value="'+treeData[i].syscode_name+'">'+treeData[i].syscode_name+'</option>';
			}
			$("#nodenames").append(html);
			debugger;
		}, function(err) {
			layer.msg("err", {
				icon : 2
			});
		});
		
	} */



layui.use(['table','form'], function(){
	
	var form = layui.form;
	
	AjaxTool.XPost("/common/department", {}, function(data) {
		var treeData = data.data;
		
		var treeObj = $.fn.zTree.init($("#treeDemo"), setting, treeData);
		treeObj.expandAll(true);
		
		//layer.msg(JSON.stringify(data),{icon:1});
	}, function(err) {
		layer.msg("err", {
			icon : 2
		});
	});
	
	
	
  var table = layui.table;
  //方法级渲染
  table.render({
    elem: '#LAY_table_user'
  //  ,url: 'http://www.layui.com/demo/table/user'
    	,url:'/common/searchUser'
    ,cols: [[
      {checkbox: true, fixed: true}
      ,{field:'id', title: 'ID', width:80, sort: true, fixed: true}
      ,{field:'fnumber', title: '工号', sort: true,width:120}
      ,{field:'uname', title: '用户名',width:100}
      ,{field:'fullname', title: '部门名称'}
    ]]
    ,id: 'testReload'
    ,page: true
    ,height: 315
    ,
    done:function(res,curr,count){
    
    	
    	
    	
        var data=res.data;
        $('.layui-table-body tr').each(function(){
    	    var dataindex=$(this).attr('data-index');
    	    var idx=0;
    	    for(var item in data){
    		    if(dataindex==idx){
    		    $(this).dblclick(function(){
    		    	// alert("*******");
    		    	var pa = [];
    		    	pa.push(data[item]); 
    		    	//$(".layui-layer-btn0",parent.document).click();
    		    	//window.parent.document.getElementByIdx_x("");
    		    	//console.log(JSON.stringify(data[item]));
    		    	 parent.getSelectUser(pa,$("#syscodeId").val());
    		    });
    		    break;
    		    }
    		    idx++;
    	    }
        });
        }
  });
  
  var $ = layui.$, active = {
    reload: function(){
      var qname = $('#qname');
      //debugger;
      //执行重载
      table.reload('testReload', {
        page: {
          curr: 1 //重新从第 1 页开始
        }
        ,where: {
          key: {
        	  qName: qname.val(),
        	  orgId:departmentId
          }
        }
      });
    }
  ,
  submit_data: function(){ //获取选中数据
      var checkStatus = table.checkStatus('testReload')
      ,data = checkStatus.data;
 	  if(data.length==0 || data.length>1){
 			layer.msg("请选择一条数据", {
				icon : 2
			});
 		  return ;
 	  }
 	 /*  if($("#nodenames").val()==""){
 		 layer.msg("请选择节点名称", {
				icon : 2
			});
 		  return ;
 	  } */
      parent.getSelectUser(data,$("#syscodeId").val());
     // layer.alert(JSON.stringify(data));
    }
  };
  
  $('.demoTable .layui-btn,.savedata_').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
  
	/* AjaxTool.XPost("/apprsetting/getNodeNames", {}, function(data) {
		var treeData = data.data.data;
		var html = "";
		if(data.data.code==0){
		for(var i=0;i<treeData.length;i++){
			html+='<option value="'+treeData[i].syscode_name+'">'+treeData[i].syscode_name+'</option>';
		}
		$("#nodenames").append(html);
		form.render();
		}
	}, function(err) {
		layer.msg("err", {
			icon : 2
		});
	}); */
});
</script>

</body>
</html>