<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/commons/taglibs.jsp" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<hred>
<link rel="stylesheet"
	href="${ctx}/resource/js/plugins/zTree/css/demo.css"
	type="text/css">
<link rel="stylesheet"
	href="${ctx}/resource/js/plugins/zTree/css/zTreeStyle/zTreeStyle.css"
	type="text/css">
<script type="text/javascript"
	src="${ctx}/resource/js/plugins/zTree/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript"
	src="${ctx}/resource/js/plugins/zTree/js/jquery.ztree.core-3.4.js"></script>
<script type="text/javascript"
	src="${ctx}/resource/js/plugins/zTree/js/jquery.ztree.excheck-3.4.js"></script>
<script type="text/javascript"
	src="${ctx}/resource/js/plugins/zTree/js/jquery.ztree.exedit-3.4.js"></script>
<link rel="stylesheet"
	href="${ctx}/resource/js/plugins/userSelect/css/usStyle/button.css" type="text/css">
<script type="text/javascript">
	//必须jquery多版本冲突的方法
         var jQuery_1_4_4= $.noConflict(true);
    </script> <SCRIPT type="text/javascript">
		var inputObj;
		var initParams1="";
		var initParams2="";
		var initParams3="";
		var initParams4=false;
		function createOrgSetting(){
			var setting = {
					view: {
						dblClickExpand: false,
						expandSpeed: "slow",
						selectedMulti: false
					},
					data: {  
				        simpleData: {  
				            enable : true,  
				            idKey : "id",  
				            pIdKey : "pId" ,
				            DIY:"isAccessTopMenu"
				        }  
				    },async: {
						enable: true,
						url:"${ctx}/pages/user/getUserOrgTree.do",
						autoParam:["id", "name=n","level=lv"],
				    	otherParam:{"id":0,"assignTreeId":initParams1,"treeLevel":initParams2,"showTreeType":initParams3}
					},
					callback: {
						//onDbClick: onUserOrgDbClick,
						onClick:onUserOrgDbClick
					}
				};
			return setting;
		}

		function beforeUserOrgClick(treeId, treeNode) {
			var zTree = jQuery_1_4_4.fn.zTree.getZTreeObj("treeObj");
			zTree.checkNode(treeNode, !treeNode.checked, null, true);
			return false;
		}
		
		function onUserOrgCheck(e, treeId, treeNode) {
			var zTree = jQuery_1_4_4.fn.zTree.getZTreeObj("treeObj"),
			nodes = zTree.getCheckedNodes(true),
			name = "",
			id="";
			
			//nodes.sort(function compare(a,b){return a.id-b.id;});
			for (var i=0, l=nodes.length; i<l; i++) {
				if(nodes[i].level<=0||nodes[i].level<=initParams3)
					continue;
				name += nodes[i].name + ",";
				id += nodes[i].id + ",";
			}
			
			if (id.length > 0 ) id = id.substring(0, id.length-1);
			if (name.length > 0 ) name = name.substring(0, name.length-1);
			try{
				var fun=inputObj+"OnDbClick";
				eval(fun+"('"+name +"','"+id+"')");    
			}catch(e){}
		}

		
		function onUserOrgDbClick(e, treeId, treeNode) {
			var zTree = jQuery_1_4_4.fn.zTree.getZTreeObj("treeObj"),
			nodes = zTree.getSelectedNodes(),
			name = "",
			id="";
			for (var i=0, l=nodes.length; i<l; i++) {
				name += nodes[i].name + ",";
				id += nodes[i].id + ",";
			}
			if (id.length > 0 ) id = id.substring(0, id.length-1);
			if (name.length > 0 ) name = name.substring(0, name.length-1);
			try{
				//alert(inputObj);
				var fun=inputObj+"OnDbClick";			
				eval(fun+"('"+name +"','"+id+"')");    
			}catch(e){}
			hideMenuUserOrg();
		}
		
		function showUserOrg(inputName,params1,params2,params3) {
			initParams1=params1;
			initParams2=params2;
			initParams3=params3;
			jQuery_1_4_4.fn.zTree.init(jQuery_1_4_4("#treeObj"), createOrgSetting());
			inputObj=inputName;
			var cityObj = jQuery_1_4_4("#"+inputName);
			var cityOffset = cityObj.offset();
			jQuery_1_4_4("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
			jQuery_1_4_4("body").bind("mousedown", onBodyDownUserOrg);
			
		}
		
		function hideMenuUserOrg() {
			jQuery_1_4_4("#menuContent").fadeOut("fast");
			jQuery_1_4_4("body").unbind("mousedown", onBodyDownUserOrg);
		}
		function onBodyDownUserOrg(event) {			
			if (!(event.target.id == "menuBtn" || event.target.id == "menuContent" || jQuery_1_4_4(event.target).parents("#menuContent").length>0)) {
				hideMenuUserOrg();
			}
		}

		jQuery_1_4_4(document).ready(function(){
			//
		});
		function query(){
			var queryVal = $("#queryVal").val();
			
				if(queryVal==""){
// 					$.fn.zTree.init(jQuery_1_4_4("#treeObj"), createOrgSetting());
					jQuery_1_4_4.fn.zTree.init(jQuery_1_4_4("#treeObj"), createOrgSetting());
					return;
				}else{
					var data={"queryVal":queryVal,"showTreeType":"USER","id":"${param.orgId}"};					
					$.ajax({
					  type: "POST",
					  url:"${ctx}/pages/user/getUserOrgTree.do",
					  data: data,
					  dataType: "json",
					  success: function(data){
// 						 $.fn.zTree.init(jQuery_1_4_4("#treeObj"), createOrgSetting(),data);	
						 jQuery_1_4_4.fn.zTree.init(jQuery_1_4_4("#treeObj"), createOrgSetting(),data);
						}
					});
				}
	
		}
	</SCRIPT>
</HEAD>
<BODY>

	<div id="menuContent" class="menuContent" style="z-index: 999; display: none; position: absolute;">
		
		<div style="background: rgb(240, 246, 228) none repeat scroll 0% 0%; border-top: 1px solid rgb(97, 119, 117); border-left: 1px solid rgb(97, 119, 117); border-right: 1px solid rgb(97, 119, 117);padding-top:5px;">
		&nbsp;&nbsp;姓名:<input type="text" value="" id="queryVal" style="width:100px;font-size:12px;height: 18px;" onkeydown="if(event.keyCode==13) query();"/>
		<input type="button" class="queryButtonStyle" title="根据用户名或工号查询" onclick="query();"/>
		</div>
		<ul id="treeObj" class="ztree" style="margin-top: 0; width: 230px;height: auto;max-height: 250px;border-top:none;"></ul>
	</div>
</BODY>
</HTML>