<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!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;
<c:if test="${orgTree!=''}">
	margin-left: 250px;
</c:if>
<c:if test="${orgTree==''}">
	margin-left: 10px;
</c:if>
	margin-right: 10px;
}
.layui-table-view .layui-table td, .layui-table-view .layui-table th {
	padding: 2.8px 0;
	border-top: none;
	border-left: none;
}
#treeDemo {
	border: 1px solid #e4e4e4;
	background: #fff;
	width: 230px;
	height: 480px;
	overflow-y: scroll;
	overflow-x: auto;
}
</style>
</head>
<body>

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

	<c:if test="${orgTree!=''}">
		<div class="zTreeDemoBackground leftPart">
			<ul id="treeDemo" class="ztree"></ul>
		</div>
	</c:if>



	<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>&nbsp&nbsp&nbsp

			<c:if test="${(jxjl ||admin) && orgTree!=''}" ><input type="checkbox"  class="layui-form-checkbox" name="orgflag" id="orgflag"  οnclick="checkOrgflag(this)"/>包含下级组织</c:if>
			<c:if test="${type eq '360person'}">
			<div class="layui-inline" style="margin-top:20px">O
			<form class="layui-form" action="">
			<div class="layui-form-item d003">
				<div class="layui-inline">
					<label class="layui-form-label">关系:</label>
					<div class="layui-input-inline" style="width:120px;">
						<select name="nodenames" id="nodenames" >
							<option value="2">上级</option>
							<option value="3">平级</option>
							<option value="4">下级</option>
						</select>
					</div>
				</div>
			</div>
			</form>
			</div>
			</c:if>
		</div>
		<table class="layui-hide" id="LAY_table_user" lay-filter="user"></table>
		<div style="text-align: right; padding: 10px" class="submitselect">

<!-- 
			<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>
        $("#orgflag").on('click',function(){   $("#searchdata").click();  })

        $("#qname").keypress(function (even) {
            if (even.which == 13) {
                $("#searchdata").click();
            }
        });
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);
	}


layui.use(['table','form'], function(){
	
	var form = layui.form;
    <c:if test="${orgTree!=''}">
		AjaxTool.XPost("/common/department?orgId="+encodeURIComponent("${orgId}"), {}, 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
			});
		});
    </c:if>

	
	
	
   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:'uname', title: '姓名_工号',width:180}
      ,{field:'fullname', title: '部门名称',width:900}
      ,{field:'id', title: '', width:0}
      ,{field:'poname', title: '', width:0}
      ,{field:'poid', title: '', width:0}
    ]]
    ,id: 'testReload'
    ,page: true
    ,limits:[10,50,500,2000,1000]
    ,height: 415
    ,
    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(); */
    		    	//$(".layui-layer-btn0",parent.document).click();
    		    	//window.parent.document.getElementByIdx_x("");
    		    	//console.log(JSON.stringify(data[item]));
    		    	//console.log(data[item]);
    		    	var d = data[item];
    		    	if($('nodenames')){
    		    	d.persontype = $('#nodenames').val();
    		    	//console.log( $('#nodenames').val());
    		    	}
    		    	
    		    	 parent.getSelectUser(d);
    		    });
    		    break;
    		    }
    		    idx++;
    	    }
        });
        }
  });
  
  var $ = layui.$, active = {
    reload: function(){
      var qname = $('#qname').val();
      var orgflag = $('#orgflag').prop("checked");
      //debugger;
      //执行重载
      table.reload('testReload', {
        page: {
          curr: 1 //重新从第 1 页开始
        }
        ,where: {
          key: {
        	  qName: qname,
              orgflag:orgflag,
        	  orgId:departmentId
          }
        }
      });
    }
  ,
  submit_data: function(){ //获取选中数据
      var checkStatus = table.checkStatus('testReload')
      ,data = checkStatus.data;
 	  if(data.length==0 ){
 			layer.msg("请没有选择数据", {
				icon : 2
			});
 		  return ;
 	  }
 	  //console.log(data);
 	 
 	  //console.log(JSON.stringify(data));
      //parent.getSelectUser(data,$("#nodenames").val());
     // layer.alert(JSON.stringify(data));
    }
  };
  
  $('.demoTable .layui-btn,.savedata_').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
  

	

});

function callBackData(){
	var checkStatus = table.checkStatus('testReload')
      ,data = checkStatus.data;
 	  if(data.length==0 ){
 			layer.msg("您没有选择数据", {
				icon : 7
			});
 		  return ;
 	  }
 	   data[0].persontype = $('#nodenames').val();
 	  return data;
}
</script>

</body>
</html>