<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/commons/taglibs.jsp" %>
<%@ include file="/commons/meta.jsp"%>
<html>
<head>
	<title>组织用户</title>
	<!--<script type="text/javascript" src="${ctx_js_plugins}/zTree/js/jquery-1.4.4.min.js"></script>-->
	<script type="text/javascript" src="${ctx_js_plugins}/zTree/js/jquery.ztree.core-3.4.min.js"></script>
	<script type="text/javascript" src="${ctx_js_plugins}/zTree/js/jquery.ztree.exhide-3.4.min.js"></script>
	<script type="text/javascript" src="${ctx_js_plugins}/userSelect/js/application.js"></script>
	<link rel="stylesheet" type="text/css" href="${ctx_js_plugins}/zTree/css/zTreeStyle/zTreeStyle.css" />
	<link rel="stylesheet" type="text/css" href="${ctx_js_plugins}/userSelect/css/usStyle/usStyle.css" />
	<link href="${ctx}/resource/js/plugins/loadmask/jquery.loadmask.css" rel="stylesheet" type="text/css" />
	<script type='text/javascript' src='${ctx}/resource/js/plugins/loadmask/jquery.loadmask.js'></script>
	<!-- 全局初始化变量定义 -->
	<script type="text/javascript">
		var isShowGroup = false;//是否需要分组（不需要：false，需要：true）
		var isShowBodyBackgroundImg = false;//是否需要设置背景图片（不需要：false，需要：true ）
		var getUserTreeAjaxURL = "${ctx}/pages/user/getUserOrgTree.do";//初始化用户树url
		//var queryUserInfoByUserIdsAjaxURL = "../../pages/User/queryUserInfoByUserIdsAjax.do";//根据用户id集合获取用户信息url
		//var queryUserInfoByUserIdsAjaxURL = "${ctx}/pages/user/queryUserByUserIdsAjax.do";//根据用户id集合获取用户信息url
		var queryUserInfoByUserIdsAjaxURL = "${ctx}/role/queryUserByRoleIdsAjax.do";//根据用户id集合获取用户信息url
		var getGroupTreeAjaxURL = "../../pages/Group/getGroupTreeAjax.action";//初始化用户自定义分组树url
		var bodyBackgroundImgPath = "${ctx_js_plugins}/userSelect/css/usStyle/img/bg_damo_fsdx.jpg";//全局背景图片路径
		var loadImgPath = "${ctx_js_plugins}/userSelect/css/usStyle/img/load.gif";//加载图标路径
		var orgImgPath = "${ctx_js_plugins}/zTree/css/zTreeStyle/img/diy/1_open.png";//组织图标路径
		var groupImgPath = "${ctx_js_plugins}/zTree/css/zTreeStyle/img/diy/1_openGroup.png";//自定义组图标路径
		var userImgPath = "${ctx_js_plugins}/zTree/css/zTreeStyle/img/diy/1_openUser.png";//用户图标路径
		var roleId = "${param.roleId}";
		function func_submit(){
			setMask("maindiv");
			var retValus = "";
			var retNames = "";
			$("#lstUsr").each(
					function()
					{
						for(var i = 0; i < this.options.length; i++){
							var optionTextArr = this.options[i].text;
							var optionValueArr=this.options[i].value;
							if("" == optionValueArr[0]){
								continue;
							}
							if(retValus.length == 0){
								retNames += optionTextArr.split(":")[0];
								retValus += optionValueArr;
							}else{
								retNames += ";"+ optionTextArr.split(":")[0];
								retValus += ";"+ optionValueArr;
							}
						}
					}
			);
			/*
             * 写入用户角色关联表
             */
			jQuery.ajax({
				type : "POST",
				url : "${ctx}/role/saveUser2role.do",
				data : {userIds:retValus,roleId:roleId},
				success : function(result) {
					alert(result);
					art.dialog.close();
				}, error : function(){
					alert('操作异常，请联系管理员！');
					$("#maindiv").unmask();
				}
			});

		}
	</script>
	<script type="text/javascript">
		var asyncStatus = false;//是否为异步加载
		/*
		//原来的setting
		var setting = {
				view: {
					dblClickExpand : false,
					selectedMulti: false
				},
				data: {  
			        simpleData: {  
			            enable : true,  
			            idKey : "id",  
			            pIdKey : "PId"  
			        }  
			    },  
			async: {
				enable: true,
				url:getUserTreeAjaxURL,
				autoParam:["id", "name=n", "level=lv"],
				otherParam:{"otherParam":"userTreeAsync"}
			},
			callback: {
				onDblClick:  onDblClick,
				onAsyncSuccess: zTreeOnAsyncSuccess
			}
		};
		*/

		var groupsetting = {
			view: {
				dblClickExpand : false,
				selectedMulti: false
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
				onDblClick:  onDblClick
			}
		};

		/**用于捕获 zTree 上鼠标双击之前的事件回调函数，并且根据返回值确定触发 onDblClick 事件回调函数*/
		function onDblClick(event, treeId, treeNode) {
			add();
			setUserCount();
			return true;
		}
		/**用于捕获异步加载正常结束的事件回调函数*/
		function zTreeOnAsyncSuccess(event, treeId, treeNode, msg) {
			//hideSelectedUserTreeNode();
			var treetype=$('input:radio[name="treetype"]:checked').val();
			if(treetype==1 && getElementById("usertree").style.display=="none"){//如果选择的是用户树并且用户树为隐藏状态
				getElementById("loadDIV").style.display="none";
				getElementById("usertree").style.display="block";
			}

			if(asyncStatus){
				var zTree = $.fn.zTree.getZTreeObj(treeId);
				childrenNodesToUserTable(zTree,treeNode);
				asyncStatus=false;
				setUserCount();
			}
		}

		//从userOrgTree里面移植过来的setting
		var setting = {
			view: {
				dblClickExpand : false,
				selectedMulti: false
			},
			edit: {
				enable: false,
				drag:{isMove:false}

			},
			data: {
				simpleData: {
					enable : true,
					idKey : "id",
					pIdKey : "pId" ,
					DIY:"isAccessTopMenu"
				}
			},async: {
				enable: true,
				url:getUserTreeAjaxURL,
				autoParam:["id", "name=n","level=lv"],
				otherParam:{"filterNodeIdsStr":"${filterNodeIdsStr }","showTreeType":"${param.showTreeType}","otherParam":"userTreeAsync"},
				dataFilter: filter
			},callback: {
				onDblClick:  onDblClick,
				onAsyncSuccess: zTreeOnAsyncSuccess
			}
		};

		function filter(treeId, parentNode, childNodes) {
			return childNodes;
		}

		$(document).ready(function(){

			//测试
			//$.fn.zTree.init($("#userOrgTree"), setting);

			//$.fn.zTree.init($("#usertreeDemo"), setting);
			if(!isShowGroup){//如果不需要分组
				$("#groupRadio").hide();//隐藏自定义组按钮
				$("#addressBook").hide();//隐藏自定义分组按钮
				$("#groupRadioText").hide();
			}else{
				initGroupTree();
			}

			//选择一项
			$("#addOne").click(function() {
				add();
				setUserCount();
			});
			//移除一项
			$("#removeOne").click(function() {
				if(trSelectedObj!=null){
					removeOptionToTable(trSelectedObj.id);
					setUserCount();
				}
			});
			//上移
			$("#upOne").click(function() {
				if(trSelectedObj!=null){
					upOptionToTable(trSelectedObj.id);
				}
			});
			//下移
			$("#downOne").click(function() {
				if(trSelectedObj!=null){
					downOptionToTable(trSelectedObj.id);
				}
			});

			//选中项置顶
			$("#topOne").click(function() {
				if(trSelectedObj!=null){
					topOptionToTable(trSelectedObj.id,true);
				}
			});
			//选中项置底
			$("#bottomOne").click(function() {
				if(trSelectedObj!=null){
					bottomOptionToTable(trSelectedObj.id);
				}
			});

			//移除全部
			$("#removeAll").click(function() {
				for(var i=tableIndex-1;i>=1;i--){
					removeOptionToTable("tr"+i);
					setUserCount();
				}
			});

			$("input[name='treetype']").click(function() {
				var treetype = this.value;
				if(treetype == 1){
					$("#grouptree").hide();
					$("#usertree").show();
				}else if(treetype == 2){
					$("#grouptree").show();
					$("#usertree").hide();
				}
			});

		});

		/**初始化已选用户*/
		function init(){
			if(isShowBodyBackgroundImg){
				document.body.style.backgroundImage="url("+bodyBackgroundImgPath+")";//设置背景图片
			}
			getElementById("loadIMG").src=loadImgPath;
			getElementById("listLoadIMG").src=loadImgPath;

			var data = {"roleId":roleId};
			$.ajax({
				type: "POST",
				url: queryUserInfoByUserIdsAjaxURL,
				data:data,
				dataType: "json",
				success: function(data){
					for(var i=0;i<data.length;i++){
						var userName = "";
						var orgName = "";
						var userId = "";
						if("${param.showTreeType}"=="USER"){
							userName = data[i].userName;
							orgName = data[i].orgId;
							userId = data[i].userId;
						}else{
							//这里为了方便没有改变变量名
							userName = data[i].orgName;
							orgName = data[i].orgFullName;
							userId = data[i].orgId;
						}
						addOptionToTable(userName,orgName,userId,"USER");
						addItemToSelect(getElementById("lstUsr"),userName+":"+orgName,userId);
					}
					//用户初始化列表完成后隐藏加载图片，显示已选用户列表
					getElementById("listLoadDIV").style.display="none";
					getElementById("resultList").style.display="block";
					setUserCount();
					$.fn.zTree.init($("#usertreeDemo"), setting);
				}
			});
		}

		function initGroupTree(queryVal){
			var data={"queryVal":queryVal};
			$.ajax({
				type: "POST",
				url:getGroupTreeAjaxURL,
				data: data,
				dataType: "json",
				success: function(data){
					$.fn.zTree.init($("#grouptreeDemo"), groupsetting,data);
					hideSelectedGroupTreeNode();
				}
			});
		}
	</script>

	<script type="text/javascript">
		/**将选中节点添加到右边列表*/
		function add(){
			var treetype=$('input:radio[name="treetype"]:checked').val();
			if(1 == treetype){
				var zTree = $.fn.zTree.getZTreeObj("usertreeDemo");
				var treeNode = zTree.getSelectedNodes()[0];//获取当前选中节点
				if(treeNode==null){
					return;
				}
				var isTopNode = (treeNode.pId=="-1");
				if (isTopNode){
					alert("无法选取顶级节点！");
					return ;
				}

				if(treeNode.type=="USER"){
					//hideTreeNode(treeNode.id);//隐藏节点
					var userId = treeNode.id;
					var userName = treeNode.name;
					var orgName = treeNode.getParentNode().name;
					var result = addItemToSelect(getElementById("lstUsr"),userName+":"+orgName,userId);
					if(result){
						addOptionToTable(userName,orgName,userId,"USER");
					}
				}else if(treeNode.type=="ORG"){
					if("${param.showTreeType}"!='USER'){
						var parentNode = treeNode.getParentNode();
						var userId = treeNode.id;
						var userName = treeNode.name;
						var orgName = parentNode.name;
						var result = addItemToSelect(getElementById("lstUsr"),userName+":"+orgName,userId);
						if(result){
							addOptionToTable(userName,orgName,userId,"ORG");
						}
					}

					//if(!treeNode.zAsync){//如果该节点没有进行过异步加载
					//	asyncStatus=true;
					//	zTree.reAsyncChildNodes(treeNode, "refresh");//强行进行异步加载(加载完成后用回调函数进行处理)
					//}else{
					//	childrenNodesToUserTable(zTree,treeNode);
					//}

				}
			}else if(2 == treetype){
				var zTree = $.fn.zTree.getZTreeObj("grouptreeDemo");
				var treeNode = zTree.getSelectedNodes()[0];//获取当前选中节点
				if(treeNode==null){
					return;
				}
				var isTopNode = (treeNode.pId=="-1");
				if (isTopNode){
					alert("无法选取顶级节点！");
					return ;
				}

				if(treeNode.type=="USER"){
					//hideTreeNode(treeNode.id);//隐藏节点
					var userId = treeNode.id;
					var userName = treeNode.name;
					var orgName = treeNode.pName;
					var result = addItemToSelect(getElementById("lstUsr"),userName+":"+orgName,userId);
					if(result){
						addOptionToTable(userName,orgName,userId,"USER");
					}
				}else if(treeNode.type=="GROUP"){
					childrenNodesToUserTable(zTree,treeNode);
				}

			}
		}


		/**将指定节点下的所有子节点添加到用户表*/
		function childrenNodesToUserTable(zTree,treeNode){
			var childrenNodes = treeNode.children;
			//hideChildrenNodes(childrenNodes);//隐藏所有子节点
			if (childrenNodes) {
				for (var i = 0; i < childrenNodes.length; i++) {
					var userId = childrenNodes[i].id;
					var userName = childrenNodes[i].name;
					var orgName = childrenNodes[i].pName;
					var result = addItemToSelect(getElementById("lstUsr"),userName+":"+orgName,userId);
					if(result){
						addOptionToTable(userName,orgName,userId,"USER");
					}
				}
			}
		}

		/**隐藏指定节点下面所有子节点*/
		function hideChildrenNodes(childrenNodes){
			for (var i = 0; i < childrenNodes.length; i++) {
				hideTreeNode(childrenNodes[i].id);
			}
		}

		/**隐藏指定节点*/
		function hideTreeNode(userId){
			//处理用户树
			var zTree = $.fn.zTree.getZTreeObj("usertreeDemo");
			var node = zTree.getNodeByParam("id",userId,null);
			if (node) {
				zTree.hideNode(node);
			}
			if(!isShowGroup){//如果不需要用户自定义组功能则直接返回不用处理自定义组树
				return;
			}
			//处理组织树
			var groupTree = $.fn.zTree.getZTreeObj("grouptreeDemo");
			var node = groupTree.getNodeByParam("id",userId,null);
			if (node) {
				groupTree.hideNode(node);
			}
		}

		/**设置已选择用户数量*/
		function setUserCount(){
			var number = getElementById("lstUsr").options.length;
			getElementById("userCount").innerHTML=number;
		}
	</script>

	<script type="text/javascript">
		//已选择列表显示表达控制----start
		var tableIndex=1;//下一行可插入列位置（选择人数=tableIndex-1）
		var trSelectedObj;//被选中行
		var trSelectedBackgroundColor;

		/**向已选择列表中插入一行数据*/
		function addOptionToTable(name,orgName,userId,type){
			var firstTD = getElementById("name"+tableIndex);//第一列存放用户名
			var secondTD = getElementById("orgName"+tableIndex);//第二列存放组织名
			var thirdTD = getElementById("userId"+tableIndex);//第三列存放用户id（隐藏）
			if(type=="ORG"){
				firstTD.innerHTML="<img src='"+orgImgPath+"' style='vertical-align:middle;margin-left:5px;hight:20px;'/>&nbsp;"+name;
			}else if(type=="GROUP"){
				firstTD.innerHTML="<img src='"+groupImgPath+"' style='vertical-align:middle;margin-left:5px;hight:20px;'/>&nbsp;"+name;
			}else{
				firstTD.innerHTML="<img src='"+userImgPath+"' style='vertical-align:middle;margin-left:5px;hight:20px;'/>&nbsp;"+name;
			}
			var name = getFullPath(userId);
			secondTD.innerHTML= name=="" ? orgName : name; //
			thirdTD.innerHTML=userId;
			tableIndex++;
			if(tableIndex>=14){
				insertRow();
			}
			getElementById('resultList').scrollTop = getElementById('resultList').scrollHeight;//滚动条置底
		}

		/**从列表中删除一项*/
		function removeOptionToTable(trId){
			var trIndex = parseInt(trId.substring(2));
			//showTreeNode(getElementById("userId"+trIndex).innerHTML);//显示隐藏节点
			if(getElementById("userId"+trIndex).innerHTML==""){
				return;
			}
			selectItemByValue(getElementById("lstUsr"),getElementById("userId"+trIndex).innerHTML);
			removeOp();
			for(var a=trIndex;a<tableIndex;a++){
				getElementById("name"+a).innerHTML=getElementById("name"+(a+1)).innerHTML;
				getElementById("orgName"+a).innerHTML=getElementById("orgName"+(a+1)).innerHTML;
				getElementById("userId"+a).innerHTML=getElementById("userId"+(a+1)).innerHTML;
			}
			getElementById("name"+tableIndex).innerHTML="";
			getElementById("orgName"+tableIndex).innerHTML="";
			getElementById("userId"+tableIndex).innerHTML="";

			if(tableIndex!=1){
				tableIndex--;
			}
			if(tableIndex>=13){
				deleteLastRow();
			}
		}

		/**选中行上移*/
		function upOptionToTable(trId){
			var trIndex = parseInt(trId.substring(2));
			if(trIndex==1||trIndex>(tableIndex-1)){
				return;
			}
			beforeIndex = trIndex-1;
			var backName = getElementById("name"+beforeIndex).innerHTML;
			var backOrgName = getElementById("orgName"+beforeIndex).innerHTML;
			var backUserId = getElementById("userId"+beforeIndex).innerHTML;

			getElementById("name"+beforeIndex).innerHTML=getElementById("name"+trIndex).innerHTML;
			getElementById("orgName"+beforeIndex).innerHTML=getElementById("orgName"+trIndex).innerHTML;
			getElementById("userId"+beforeIndex).innerHTML=getElementById("userId"+trIndex).innerHTML;

			getElementById("name"+trIndex).innerHTML=backName;
			getElementById("orgName"+trIndex).innerHTML=backOrgName;
			getElementById("userId"+trIndex).innerHTML=backUserId;

			var trObj = getElementById("tr"+beforeIndex);
			chooseTr(trObj);

			selectItemToUpOne(getElementById("lstUsr"),getElementById("userId"+beforeIndex).innerHTML);

		}

		/**选中行下移*/
		function downOptionToTable(trId){
			var trIndex = parseInt(trId.substring(2));
			if(trIndex>=(tableIndex-1)){
				return;
			}
			afterIndex = trIndex+1;
			var userId = getElementById("userId"+trIndex).innerHTML;;

			var backName = getElementById("name"+afterIndex).innerHTML;
			var backOrgName = getElementById("orgName"+afterIndex).innerHTML;
			var backUserId = getElementById("userId"+afterIndex).innerHTML;

			getElementById("name"+afterIndex).innerHTML=getElementById("name"+trIndex).innerHTML;
			getElementById("orgName"+afterIndex).innerHTML=getElementById("orgName"+trIndex).innerHTML;
			getElementById("userId"+afterIndex).innerHTML=getElementById("userId"+trIndex).innerHTML;

			getElementById("name"+trIndex).innerHTML=backName;
			getElementById("orgName"+trIndex).innerHTML=backOrgName;
			getElementById("userId"+trIndex).innerHTML=backUserId;

			var trObj = getElementById("tr"+afterIndex);
			chooseTr(trObj);

			selectItemToDownOne(getElementById("lstUsr"),userId);

		}

		/**选中行置顶*/
		function topOptionToTable(trId,falg){
			//alert(trId);
			var trIndex = parseInt(trId.substring(2));
			if(falg&&(trIndex==1||trIndex>(tableIndex-1))){
				return;
			}
			beforeIndex = 1;
			var backName = getElementById("name"+trIndex).innerHTML;
			var backOrgName = getElementById("orgName"+trIndex).innerHTML;
			var backUserId = getElementById("userId"+trIndex).innerHTML;

			for(var a=trIndex;a>1;a--){
				getElementById("name"+a).innerHTML=getElementById("name"+(a-1)).innerHTML;
				getElementById("orgName"+a).innerHTML=getElementById("orgName"+(a-1)).innerHTML;
				getElementById("userId"+a).innerHTML=getElementById("userId"+(a-1)).innerHTML;
			}

			getElementById("name"+beforeIndex).innerHTML=backName;
			getElementById("orgName"+beforeIndex).innerHTML=backOrgName;
			getElementById("userId"+beforeIndex).innerHTML=backUserId;

			var trObj = getElementById("tr"+beforeIndex);
			chooseTr(trObj);
			getElementById('resultList').scrollTop = 0;//滚动条置顶

			selectItemToTop(getElementById("lstUsr"),backUserId);

		}

		/**选中行置底*/
		function bottomOptionToTable(trId){
			var trIndex = parseInt(trId.substring(2));
			if(trIndex>(tableIndex-1)){
				return;
			}
			afterIndex = tableIndex-1;
			var backName = getElementById("name"+trIndex).innerHTML;
			var backOrgName = getElementById("orgName"+trIndex).innerHTML;
			var backUserId = getElementById("userId"+trIndex).innerHTML;

			for(var a=trIndex;a<tableIndex;a++){
				getElementById("name"+a).innerHTML=getElementById("name"+(a+1)).innerHTML;
				getElementById("orgName"+a).innerHTML=getElementById("orgName"+(a+1)).innerHTML;
				getElementById("userId"+a).innerHTML=getElementById("userId"+(a+1)).innerHTML;
			}

			getElementById("name"+afterIndex).innerHTML=backName;
			getElementById("orgName"+afterIndex).innerHTML=backOrgName;
			getElementById("userId"+afterIndex).innerHTML=backUserId;

			var trObj = getElementById("tr"+afterIndex);
			chooseTr(trObj);
			getElementById('resultList').scrollTop = getElementById('resultList').scrollHeight;//滚动条置底

			selectItemToBottom(getElementById("lstUsr"),backUserId);

			/* var objSelect = getElementById("lstUsr");
            for (var i = 0; i < objSelect.options.length; i++) {
                alert(objSelect.options[i].text+" "+objSelect.options[i].value);
            } */
		}

		/**删除用来保存数据的隐藏下拉列表已选中项目*/
		function removeOp(){
			var opVal = $("#lstUsr option:selected").val();
			if("undefined"==typeof(opVal)){
				return ;
			}
			$("#lstUsr option:selected").remove();

			setUserCount();
		}

		/**选中一行*/
		function chooseTr(trObj){
			if(trSelectedObj!=null){
				trSelectedObj.style.backgroundColor=trSelectedBackgroundColor;//还原背景色
			}
			trSelectedObj=trObj;
			trSelectedBackgroundColor=trObj.style.backgroundColor;
			trObj.style.backgroundColor="#BFCEE7";
		}

		/**用户列表插入一行*/
		function insertRow(){
			var obj=getElementById("userList");
			var objTR=obj.insertRow(-1);
			if(tableIndex%2==0){
				objTR.className="trEven";
			}else{
				objTR.className="trOdd";
			}
			var trId = "tr"+(tableIndex+1);
			objTR.id=trId;
			objTR.ondblclick=Function("removeOptionToTable('"+trId+"')");
			objTR.onclick=Function("chooseTr(this)");

			var objTD1 = document.createElement("td");
			objTD1.id="name"+(tableIndex+1);
			objTD1.className="tdcss";
			objTR.appendChild(objTD1);

			var objTD2 = document.createElement("td");
			objTD2.id="orgName"+(tableIndex+1);
			objTD2.className="tdcss";
			objTR.appendChild(objTD2);

			var objTD3 = document.createElement("td");
			objTD3.id="userId"+(tableIndex+1);
			objTD3.style.display="none";
			objTR.appendChild(objTD3);

		}

		/**删除用户列表最后一行*/
		function deleteLastRow(){
			var obj=getElementById("userList");
			obj.deleteRow(obj.childNodes[0].childNodes.length-1);
		}

		/**获取节点全路径*/
		function getFullPath(id){
			var zTree = $.fn.zTree.getZTreeObj("usertreeDemo");
			if(zTree == null)
				return "";
			var node = zTree.getNodeByParam("id", id,null);
			if(node == null)
				return "";

			if(node.type == "USER")
				node = node.getParentNode();

			var path = "";
			while (node.level>=1){
				path = node.name + "/" + path;
				node = node.getParentNode();
			}
			return path;
		}
		//已选择列表显示表达控制----end

	</script>
	<script type="text/javascript">


		/**如果父页面是用户自定义分组页面则用该方法提交*/
		function group_submit(){
			var userids = "";
			var userNames = "";
			var orgNames = "";
			$("#lstUsr").each(
					function()
					{
						for(var i = 0; i < this.options.length; i++){
							var userId=this.options[i].value;
							var text=this.options[i].text;
							var textArr = text.split(":");
							var userName = textArr[0];
							var orgName = textArr[1];
							if(userids.length == 0){
								userids += userId;
								userNames += userName;
								orgNames += orgName;
							}else{
								userids += ";"+ userId;
								userNames += ";"+ userName;
								orgNames += ";"+ orgName;
							}
						}
					}
			);
			window.returnValue=userids+":"+userNames+":"+orgNames;
			window.close();
		}

		/**跳转到用户自定义分组页面*/
		function toUserGroupPage(){
			var data = "";
			var returnValue = window.showModalDialog(
					"../system/group/direct.action?number=" + Math.random(),
					data,"dialogWidth:800px;dialogHeight:500px;scroll:no;status:no;");
			if(returnValue==1){
				initGroupTree();//自定义分组后重新加载用户组树
			}
		}

		/**根据姓名或工号查询*/
		function query(){
			var queryVal = getElementById("queryVal").value;
			var treetype=$('input:radio[name="treetype"]:checked').val();
			if(treetype==1){
				if(queryVal==""){
					$.fn.zTree.init($("#usertreeDemo"), setting);
					return;
				}else{
					var data={"queryVal":queryVal,"showTreeType":"USER","id":"${param.orgId}"};
					getElementById("loadDIV").style.display="";
					$.ajax({
						type: "POST",
						url:getUserTreeAjaxURL,
						data: data,
						dataType: "json",
						success: function(data){
							$.fn.zTree.init($("#usertreeDemo"), setting,data);
							getElementById("loadDIV").style.display="none";
						}
					});
				}
			}
			/*
            var queryVal = getElementById("queryVal").value;
            var treetype=$('input:radio[name="treetype"]:checked').val();
            if(treetype==1){
                if(queryVal==""){
                    $.fn.zTree.init($("#usertreeDemo"), setting);
                    return;
                }else{
                    var data={"queryVal":queryVal};
                    $.ajax({
                      type: "POST",
                      url:getUserTreeAjaxURL,
                      data: data,
                      dataType: "json",
                      success: function(data){
                           $.fn.zTree.init($("#usertreeDemo"), groupsetting,data);
                              //hideSelectedUserTreeNode();
                        }
                    });
                }
            }else if(treetype==2){
                initGroupTree(queryVal);
            }*/
		}
		function query2(){
			var queryVal = getElementById("queryVal2").value;

			if(queryVal != ""){
				$("#userList tr").each(function() {
					var text = $(this).children().eq(0).text();

					if(text.trim()==queryVal.trim()){
						//alert(text);
						topOptionToTable($(this).attr("id"),false);
					}
				});
			}
		}
	</script>
</head>
<!-- 
隐藏对象lstUsr用来保存用户选人数据（格式：text=用户名:组织名,value=用户id）
 -->
<body onload="init();" style="overflow: auto;">

<%
	String roleErrorMsg=(String)request.getParameter("roleErrorMsg");
	if(roleErrorMsg!=null&&!"".equals(roleErrorMsg)){
%>
<div class="alert alert-block alert-info">
	<button type="button" class="close" data-dismiss="alert">
		<i class="ace-icon fa fa-times"></i>
	</button>
	需重新绑定失效的角色资源如下所示：<br/><%=roleErrorMsg%>
</div>
<%} %>
<select id="lstUsr" name="lstUsr" style="display:none"></select>


<div id="maindiv" class="contentPanel_sms" style="height: 490px;width: 760px;overflow: hidden;margin:0px auto; padding:5px 0 5px 0; background-color:#fff;">
	<div class="navPanel_sms" style="height: 524px">
		<div class="accordion">
			<h1 class="caption on">添加方式：
				<input type="radio" name="treetype" value="1" checked="checked"/>部门
				<input type="radio" name="treetype" value="2" id="groupRadio"/><span id="groupRadioText">自定义组</span>
			</h1>
			<div>
				&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>
			<div class="content on" style="background-color:#fff;">
				<div>
					<div id="loadDIV" align="center" style="width: 230px;height:420px;">
						<img src="" id="loadIMG" style="margin-top:130px;"/>&nbsp;</br>用户树加载中...
					</div>
					<div id="usertree" class="zTreeDemoBackground left" style="width: 230px;height:100%;display: none;">
						<ul id="usertreeDemo" class="ztree" style="width: 240px;overflow: auto;height: 410px;"></ul>
					</div>
					<div id="grouptree" class="zTreeDemoBackground left" style="width: 230px;height: 100%;display: none;">
						<ul id="grouptreeDemo" class="ztree" style="width: 240px;overflow: auto;height: 410px;"></ul>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div style="float: left; width:80px; margin:0px; padding:0px 10px; background-color: #fff;height: 100%;vertical-align: middle;padding-top: 100px;">
		<input type="button" id="addOne" class="buttonStyle" value="添加" />
		<br/><br/>
		<input type="button" id="removeOne" class="buttonStyle" value="删除" name="removeOne"/>
		<br/><br/>
		<input type="button" id="upOne" class="buttonStyle" value="上移" name="upOne"/>
		<br/><br/>
		<input type="button" id="downOne" class="buttonStyle" value="下移" name="downOne"/>
		<br/><br/>
		<input type="button" id="topOne" class="buttonStyle" value="置顶" name="topOne"/>
		<br/><br/>
		<input type="button" id="bottomOne" class="buttonStyle" value="置底" name="bottomOne"/>
		<br/><br/>
		<input type="button" id="removeAll" class="buttonStyle" value="全部删除" name="removeAll"/>
	</div>
	<div class="workPanel_sms" style="padding:0px; margin:0px; overflow: auto; width:420px; float:left;height: 490px">
		<div class="tabs_sms"  style="width:413px; margin:0px; padding:0px;height: 490px">
			<!--
                <div class="move previous"></div>
              <div class="move next"></div> -->
			<div class="tabs-nav_sms" >
				<ul>
					<li class="on first"><span>已选列表</span></li>
				</ul>
			</div>
			<div class="tabs-content" style="overflow: no; height:440px;">
				<div class="box on" style="padding:0px 8px;overflow: auto;">
<%--					<div>--%>
<%--						&nbsp;姓名:<input type="text" value="" id="queryVal2" style="width:100px;font-size:12px;height: 18px;" onkeydown="if(event.keyCode==13) query2();"/>--%>
<%--						<input type="button" class="queryButtonStyle" title="根据用户名或工号查询" onclick="query2();"/>--%>
<%--					</div>--%>
					<div style="overflow: no; height:36px;padding-top:4px;">
						<table style="WIDTH: 100%; HEIGHT: 20px;align:left;display: table;table-layout:fixed;border:#C0C0C0 solid 1px;"  cellpadding="0" cellspacing="0">
							<tr style="height:20px;">
								<th  style="border-right:#C0C0C0 solid 1px;"width="120px" align="center">姓名</th><th class="" align="center">所属组织</th>
							</tr>
						</table>
					</div>
					<div id="listLoadDIV" align="center" style="overFlow-x:hidden;overFlow-x:auto; height:310px;">
						<img src="" id="listLoadIMG" style="margin-top:120px;"/>&nbsp;</br>用户列表加载中...
					</div>
					<div style="overFlow-x:hidden;overFlow-x:auto; height:310px;display:none" id="resultList" >
						<table id="userList" style="WIDTH: 100%; HEIGHT: 300px;align:left;display: table;table-layout:fixed;border:#C0C0C0 solid 1px;" border="1px" cellpadding="0" cellspacing="0">
							<c:forEach varStatus="st"  begin="1"  end="14"  var="x">
								<c:choose>
									<c:when test="${x%2==0}">
										<tr id="tr${x}" ondblclick="removeOptionToTable('tr${x}');" onclick="chooseTr(this)" class="trOdd">
									</c:when>
									<c:otherwise>
										<tr id="tr${x}" ondblclick="removeOptionToTable('tr${x}');" onclick="chooseTr(this)" class="trEven">
									</c:otherwise>
								</c:choose>
								<td class="tdcss" id="name${x}" width="120px"  nowrap></td>
								<td class="tdcss" id="orgName${x}" nowrap></td>
								<td id="userId${x}" style="display:none" nowrap></td>
								</tr>
							</c:forEach>
						</table>
					</div>
					<div style="padding:4px 0px;">
						<font color="#0080FF">共计</font><font color="red" id="userCount">0</font><font color="#0080FF">条记录</font>
					</div>
					<div style="padding:10px 0px;">
						<input type="button" value="确定" class="buttonStyle" onclick="func_submit();" id="subButton"/>
						<!-- <input type="button" value="取消" class="buttonStyle" onclick="window.parent.hideUserSelectDiv();"/>  -->
						<input type="button" value="取消" class="buttonStyle" onclick="art.dialog.close();"/>
						<input type="button" value="自定义组" class="buttonStyle" onclick="toUserGroupPage();" id="addressBook"/>
					</div>

				</div>
			</div>
		</div>

	</div>
</div>

</body>
</html>