MutiDepartmentBrowser.jsp 26 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778
<%@ page language="java" contentType="text/html; charset=UTF-8" %> 
<%@ page import="java.util.List"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import="weaver.general.Util"%>
<%@ page import="weaver.hrm.company.SubCompanyComInfo"%>
<jsp:useBean id="RecordSet" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="CompanyVirtualComInfo" class="weaver.hrm.companyvirtual.CompanyVirtualComInfo" scope="page" />
<jsp:useBean id="SubCompanyComInfo" class="weaver.hrm.company.SubCompanyComInfo" scope="page" />
<jsp:useBean id="SubCompanyVirtualComInfo" class="weaver.hrm.companyvirtual.SubCompanyVirtualComInfo" scope="page" />
<jsp:useBean id="CompanyComInfo" class="weaver.hrm.company.CompanyComInfo" scope="page" />
<jsp:useBean id="DepartmentComInfo" class="weaver.hrm.company.DepartmentComInfo" scope="page" />
<jsp:useBean id="DepartmentVirtualComInfo" class="weaver.hrm.companyvirtual.DepartmentVirtualComInfo" scope="page" />
<jsp:useBean id="xssUtil" class="weaver.filter.XssUtil" scope="page" />
<%@ include file="/systeminfo/init_wev8.jsp" %>
<%@ taglib uri="/WEB-INF/weaver.tld" prefix="wea"%>
<HTML>
<HEAD>
  <LINK REL=stylesheet type=text/css HREF=/css/Weaver_wev8.css>
	<link rel="stylesheet" href="/wui/common/jquery/plugin/zTree/css/zTreeStyle/zTreeStyle_wev8.css" type="text/css">
	<script type="text/javascript" src="/wui/common/jquery/plugin/zTree/js/jquery.ztree.core_wev8.js"></script>
	<script type="text/javascript" src="/wui/common/jquery/plugin/zTree/js/jquery.ztree.excheck-3.0_wev8.js"></script>
	<LINK href="/js/ecology8/customSelect/customSelect_wev8.css" type=text/css rel=STYLESHEET></LINK>
	<script src="/js/ecology8/customSelect/customSelect_wev8.js" type="text/javascript"></script>
	<script type="text/javascript">
	try{
		parent.setTabObjName("<%=SystemEnv.getHtmlLabelNames("124",user.getLanguage())%>");
	}catch(e){
		if(window.console)console.log(e+"-->MutiDepartmentBrowser.jsp");
	}
	var dialog = null;
	try{
		dialog = parent.parent.getDialog(parent);
	}
	catch(e){}
	
	function changeShowType(obj,showtype){
		var title = jQuery(obj).find(".e8text").html();
		var title1 = jQuery(obj).find(".e8text").attr("title");
		jQuery("#optionSpan").html(title);
		jQuery("#virtualtype").val(showtype);
		jQuery("#leftTree").css("background-color",jQuery(".leftTypeSearch").css("background-color"));
		jQuery("span[id^='showspan']").each(function(){
			jQuery(this).addClass("e8imgSel");
		});
		jQuery("#showspan"+showtype).removeClass("e8imgSel");
		showE8TypeOption();
		onSaveJavaScript("doChange");
		initTree();
	}

	function showE8TypeOption(closed){
		if(closed){
			jQuery("#e8TypeOption").hide();
		}else{
			jQuery("#e8TypeOption").toggle();
		}
		if(jQuery("#e8TypeOption").css("display")=="none"){
			jQuery("span.leftType").removeClass("leftTypeSel");
			var src = jQuery("#currentImg").attr("src");
			if(src){
				jQuery("#currentImg").attr("src",src);
			}
			jQuery("#e8typeImg").attr("src","/images/ecology8/doc/down_wev8.png");
		}else{
			jQuery("span.leftType").addClass("leftTypeSel");
			jQuery("#e8TypeOption").width(jQuery("span.leftType").width()+10);
			var src = jQuery("#currentImg").attr("src");
			if(src){
				jQuery("#currentImg").attr("src",src);
			}
			jQuery("#e8typeImg").attr("src","/images/ecology8/doc/down_sel_wev8.png");
		}
		return;
	}
</script>
</HEAD>

<%
String show_virtual_org = Util.null2String(request.getParameter("show_virtual_org"));
boolean showvirtual = false;
CompanyVirtualComInfo.setUser(user);
if(!show_virtual_org.equals("-1")&&CompanyVirtualComInfo.getCompanyNum()>0){
	showvirtual = true;
}
String imagefilename = "/images/hdMaintenance_wev8.gif";
String titlename = SystemEnv.getHtmlLabelName(124,user.getLanguage());
String needfav ="1";
String needhelp ="";
int uid=user.getUID();

String type=Util.null2String(request.getParameter("type"));
String id=Util.null2String(request.getParameter("id"));
String nodename=Util.null2String(request.getParameter("nodename"));
String level=Util.null2String(request.getParameter("level"));
String subid=Util.null2String(request.getParameter("subid"));
String selectedDepartmentIds = Util.null2String(request.getParameter("selectedDepartmentIds"));
String passedDepartmentIds = Util.null2String(request.getParameter("passedDepartmentIds"));
String resourceids=Util.null2String(request.getParameter("resourceids"));
String sqlwhere = Util.null2String(request.getParameter("sqlwhere"));
String selectedids = Util.null2String(request.getParameter("selectedids"));
String selectednames = DepartmentComInfo.getDepartmentNames(selectedids);

String[] selecteds = selectedids.split("[,]");
int deptlevel = 0;
int maxnum=0;
if(!"".equals(selectedids)&&!"0".equals(selectedids)){
	for(int i=0;i<selecteds.length;i++){
		if(!"".equals(selecteds[i])&&!"0".equals(selecteds[i])){
			if(Util.getIntValue(selecteds[i])<-1){
				maxnum = DepartmentVirtualComInfo.getLevelByDepId(selecteds[i]);
			}else{
				maxnum = DepartmentComInfo.getLevelByDepId(selecteds[i]);
			}
			if(deptlevel<maxnum){
				deptlevel = maxnum;
			}
		}
	}
}
String selectnode = "";
String supcompanyid = "";
if(!"".equals(selectedids)&&!"0".equals(selectedids)){
	for(int i=0;i<selecteds.length;i++){
		if(!"".equals(selecteds[i])&&!"0".equals(selecteds[i])){
			if(Util.getIntValue(selecteds[i])<-1){
				supcompanyid = DepartmentVirtualComInfo.getSubcompanyid1(selecteds[i]);
			}else{
				supcompanyid = DepartmentComInfo.getSubcompanyid1(selecteds[i]);
			}
			selectnode = ",dept_"+supcompanyid+"_"+selecteds[i]+selectnode;
		}
	}
}
if(selectnode.startsWith(",")){
	selectnode = selectnode.substring(1);
}
String nodeid=null;
String nodeids=null;
Cookie[] cks= request.getCookies();
String rem="";        
for(int i=0;i<cks.length;i++){
//System.out.println("ck:"+cks[i].getName()+":"+cks[i].getValue());
if(cks[i].getName().equals("departmentmulti"+uid)){
  rem=cks[i].getValue();
  break;
}
}
if(resourceids.equals("")) resourceids=selectedDepartmentIds;
ArrayList selectids=Util.TokenizerString(resourceids,",");
for(int i=0;i<selectids.size();i++){
    String tempdeptid=(String)selectids.get(i);
    String tempsubcomid="";
    if(Util.getIntValue(tempdeptid)<-1){
    	tempsubcomid = DepartmentVirtualComInfo.getSubcompanyid1(tempdeptid);
    }else{
    	tempsubcomid = DepartmentComInfo.getSubcompanyid1(tempdeptid);
    }
    
    tempdeptid="|dept_"+tempsubcomid+"_"+tempdeptid;
    if((rem+"|").indexOf(tempdeptid+"|")==-1)   rem+=tempdeptid;
}
if(rem!=null&&rem.length()>1)
nodeids=rem.substring(1);
if(nodeids!=null){
 if(nodeids.indexOf("|")>-1)
  nodeid=nodeids.substring(nodeids.lastIndexOf("|")+1);
 else
  nodeid=nodeids;
}
boolean exist=false;
if(nodeid!=null&&nodeid.indexOf("dept")>-1){
    String deptname="";
    String subcom="";
    if(Util.getIntValue(nodeid.substring(nodeid.lastIndexOf("_")+1))<-1){
    	deptname = DepartmentVirtualComInfo.getDepartmentname(nodeid.substring(nodeid.lastIndexOf("_")+1));
    	subcom = DepartmentVirtualComInfo.getSubcompanyid1(nodeid.substring(nodeid.lastIndexOf("_")+1));
    }else{
    	deptname = DepartmentComInfo.getDepartmentname(nodeid.substring(nodeid.lastIndexOf("_")+1));
    	subcom = DepartmentComInfo.getSubcompanyid1(nodeid.substring(nodeid.lastIndexOf("_")+1));
    }
    if(!deptname.equals("")&&subcom.equals(nodeid.substring(nodeid.indexOf("_")+1,nodeid.lastIndexOf("_"))))
       exist=true;
    else
      exist=false;
}
if(!exist)
nodeid=null;

String[] ids=Util.TokenizerString2(nodeids,"|");
%>


<BODY>
<div class="zDialog_div_content">
	<table id="topTitle" cellpadding="0" cellspacing="0">
		<tr>
			<td>
			</td>
			<td class="rightSearchSpan" style="text-align:right;">
				<span title="<%=SystemEnv.getHtmlLabelName(23036,user.getLanguage()) %>" class="cornerMenu"></span>
			</td>
		</tr>
	</table>
    <DIV align=right>
	<%@ include file="/systeminfo/TopTitle_wev8.jsp" %>
	<%@ include file="/systeminfo/leftMenuCommon.jsp" %>
	<%@ include file="/systeminfo/RightClickMenuConent_wev8.jsp" %>
    <%
    BaseBean baseBean_self = new BaseBean();
    int userightmenu_self = 1;
    try{
    	userightmenu_self = Util.getIntValue(baseBean_self.getPropValue("systemmenu", "userightmenu"), 1);
    }catch(Exception e){}
    if(userightmenu_self == 1){
        RCMenu += "{"+SystemEnv.getHtmlLabelName(826,user.getLanguage())+",javascript:onSave(),_self} " ;
        RCMenuHeight += RCMenuHeightStep ;
        RCMenu += "{"+SystemEnv.getHtmlLabelName(311,user.getLanguage())+",javascript:onClear(),_self} " ;
        RCMenuHeight += RCMenuHeightStep ;
       
        RCMenu += "{"+SystemEnv.getHtmlLabelName(201,user.getLanguage())+",javascript:btncancel_onclick(),_self} " ;
        RCMenuHeight += RCMenuHeightStep ;
        
    }
    RCMenu += "{"+SystemEnv.getHtmlLabelName(19323,user.getLanguage())+",javascript:needSelectAll(!parent.selectallflag,this),_self} " ;
    RCMenuHeight += RCMenuHeightStep ;
    %>	
    <%@ include file="/systeminfo/RightClickMenu_wev8.jsp" %>
<%if(userightmenu_self == 1){%>
    <script>
     rightMenu.style.visibility='hidden'
    </script>
<%}%>
    </DIV>

<FORM NAME=select STYLE="margin-bottom:0" action="MutiDepartmentBrowser.jsp" method=post>
   <input class=inputstyle type=hidden name=sqlwhere value="<%=xssUtil.put(sqlwhere)%>">
   <input class=inputstyle type=hidden name=type value="<%=type%>">
   <input class=inputstyle type=hidden name=id value="<%=id%>">
   <input class=inputstyle type=hidden name=level value="<%=level%>">
   <input class=inputstyle type=hidden name=subid value="<%=subid%>">
   <input class=inputstyle type=hidden name=nodename value="<%=nodename%>">
   <textarea style="display:none" name=passedDepartmentIds ><%=passedDepartmentIds%></textarea>
   <textarea style="display:none" name=selectedDepartmentIds ><%=selectedDepartmentIds%></textarea>
	 <input class=inputstyle type=hidden name=canceledDepartmentIds value="">
	 <input class=inputstyle type=hidden id=virtualtype name=virtualtype value="">
	 <input class=inputstyle type=hidden id=selectallflag name=selectallflag value="">
   <input class=inputstyle type=hidden id=selectedids name=selectedids value="<%=selectedids%>">
   <input class=inputstyle type=hidden id=selectednames name=selectednames value="<%=selectednames %>">
	 <%if(showvirtual){ %>
		<table cellspacing="0" cellpadding="0" style="width:100%;">
			<tr>
				<td class="leftTypeSearch">
					<div class="topMenuTitle" style="border-bottom:none;height: 0px">
						<span class="leftType" style="width: 564px;height: 0px">
							<span><img id="currentImg" src="/images/ecology8/doc/org_wev8.png" width="16"/></span>
							<span>
								<div  id="e8typeDiv" style="width:auto;height:auto;position:relative;line-height: 0px">
									<span id="optionSpan" style="width: 515px;line-height: 30px" onclick="showE8TypeOption();" ><%=CompanyComInfo.getCompanyname("1")%></span>
									<%if(CompanyVirtualComInfo.getCompanyNum()>0){ %>
									<span style="width:16px;height:16px;cursor:pointer;" onclick="showE8TypeOption();">
										<img id="e8typeImg" src="/images/ecology8/doc/down_wev8.png"/>
									</span>
									<%} %>
								</div>
							</span>
					</div>
				</td>
			</tr>
		</table>
		<%} %>
    <TABLE ID=BrowseTable class="BroswerStyle"  cellspacing="1" STYLE="margin-top:0" width="100%">
         <TR class=Line1><TH colspan="4" ></TH></TR>
          <TR>
              <TD id="tddeeptree" colspan="4" WIDTH="100%">
                 <div id="deeptree" style="height:100%;width:100%;overflow:scroll;">
                 	<ul id="ztreedeep" class="ztree"></ul>
                 </div>
               
              </TD>
          </TR>
    </TABLE>
</FORM>
</div>
	<%	if(CompanyVirtualComInfo.getCompanyNum()>0){ %>
	<ul id="e8TypeOption" class="e8TypeOption">
	<%
	if(CompanyComInfo.getCompanyNum()>0){
		CompanyComInfo.setTofirstRow();
		while(CompanyComInfo.next()){
	%>
		<li onclick="changeShowType(this,<%=CompanyComInfo.getCompanyid() %>);">
			<span id="showspan<%=CompanyComInfo.getCompanyid() %>" class="e8img"><img src="/images/ecology8/doc/current_wev8.png"/></span>
			<span class="e8img"><img src="/images/ecology8/doc/org_sel_wev8.png"/></span>
			<span class="e8text"><%=CompanyComInfo.getCompanyname()%></span>
		</li>
	<%}}
	if(CompanyVirtualComInfo.getCompanyNum()>0){
		CompanyVirtualComInfo.setTofirstRow();
		while(CompanyVirtualComInfo.next()){
		%>
		<li onclick="changeShowType(this,<%=CompanyVirtualComInfo.getCompanyid() %>);">
			<span id="showspan<%=CompanyVirtualComInfo.getCompanyid() %>" class="e8img e8imgSel"><img src="/images/ecology8/doc/current_wev8.png"/></span>
			<span class="e8img"><img src="/images/ecology8/doc/org_sel_wev8.png"/></span>
			<span class="e8text" title="<%=CompanyVirtualComInfo.getVirtualType() %>"><%=CompanyVirtualComInfo.getVirtualType().length()>4?CompanyVirtualComInfo.getVirtualType():CompanyVirtualComInfo.getVirtualType()%></span>
		</li>
		<%} %>
	</ul>
<%} %>
<%} %>
<div id="zDialog_div_bottom" class="zDialog_div_bottom">
  <wea:layout needImportDefaultJsAndCss="false">
		<wea:group context=""  attributes="{\"groupDisplay\":\"none\"}">
			<wea:item type="toolbar">
					<input type="button" class=zd_btn_submit accessKey=O  id=btnok onclick="onSave()" value="<%=SystemEnv.getHtmlLabelName(826,user.getLanguage())%>">
					<input type="button" class=zd_btn_submit accessKey=2  id=btnclear onclick="onClear()" value="<%=SystemEnv.getHtmlLabelName(311,user.getLanguage())%>">
        	<input type="button" class=zd_btn_submit accessKey=T  id=btncancel onclick="btncancel_onclick();" value="<%=SystemEnv.getHtmlLabelName(201,user.getLanguage())%>">
			</wea:item>
		</wea:group>
	</wea:layout>
		<script type="text/javascript">
		jQuery(document).ready(function(){
			//resizeDialog(document);
		});
	</script>
	</div>
</BODY>
<script type="text/javascript">

	
	//<!--
	var selectallflag=false;
	var appendimg = 'subCopany_Colse';
	var appendname = 'selObj';
	var allselect = "all";
	var typename = "checkbox";
	var selectreview = "openall";
	var selectedids = "<%=selectedids%>";
	var cxtree_id = "";
	var cxtree_ids = [];
	var deptlevel = <%=deptlevel%>;
	if(selectedids!="0"&&selectedids!=""){
		cxtree_id = "<%=selectnode%>";
		cxtree_ids = cxtree_id.split(',');
		cxtree_id = cxtree_ids[0];
	} 
	
	/**
	 * 获取url(alax方式获得子节点时使用)
	 */
	function getAsyncUrl(treeId, treeNode) {
		//获取子节点时
		var virtualtype = jQuery("#virtualtype").val();
		if(virtualtype<0){
			if (treeNode != undefined && treeNode.isParent != undefined && treeNode.isParent != null) {
	    	return "/hrm/companyvirtual/DepartmentMultiXML.jsp?virtualtype="+virtualtype+"&" + treeNode.ajaxParam + "&" + new Date().getTime() + "=" + new Date().getTime();
	    } else {
	    	//初始化时
	    	return "/hrm/companyvirtual/DepartmentMultiXML.jsp?deptlevel="+deptlevel+"&virtualtype="+virtualtype+"<%if(nodeids!=null){%>&nodeids=<%=nodeids%><%}%>" + "&" + new Date().getTime() + "=" + new Date().getTime();
	    }
	  }else{  
	    if (treeNode != undefined && treeNode.isParent != undefined && treeNode.isParent != null) {
	    	return "/hrm/tree/DepartmentMultiXML.jsp?" + treeNode.ajaxParam + "&" + new Date().getTime() + "=" + new Date().getTime();
	    } else {
	    	//初始化时
	    	return "/hrm/tree/DepartmentMultiXML.jsp?deptlevel="+deptlevel+"<%if(nodeids!=null){%>&nodeids=<%=nodeids%><%}%>" + "&" + new Date().getTime() + "=" + new Date().getTime();
	    }
	  }
	};
	//zTree配置信息
	var setting = {
		async: {
			enable: true,       //启用异步加载
			dataType: "text",   //ajax数据类型
			url: getAsyncUrl    //ajax的url
		},
		check: {
			enable: true,       //启用checkbox或者radio
			chkStyle: "checkbox",  //check类型为checkbox
			chkboxType: { "Y" : "", "N" : "" }
		},
		view: {
			expandSpeed: ""     //效果
		},
		callback: {
			onClick: zTreeOnClick,   //节点点击事件
			onCheck: zTreeOnCheck,
			onAsyncSuccess: zTreeOnAsyncSuccess  //ajax成功事件
		}
	};

	var zNodes =[
	];
	
	<%if(showvirtual){%>
	window.E8EXCEPTHEIGHT = 30;
	<%}%>
	$(document).ready(function(){
		//初始化zTree
		var obj =$.fn.zTree.init($("#ztreedeep"), setting, zNodes);
	});
	
	function initTree(){
		jQuery("#tddeeptree").empty().html("<div id='deeptree' style='height:100%;width:100%;overflow:hidden;'><ul id='ztreedeep' class='ztree'></ul></div>");
		var obj =$.fn.zTree.init($("#ztreedeep"), setting, zNodes);
	}
	
	/**
	 * 点击树节点时触发
	 */
	function zTreeOnClick(event, treeId, treeNode) {
	    var treeObj = $.fn.zTree.getZTreeObj(treeId);
	    if (treeNode.isParent) {
			treeObj.expandNode(treeNode);
		}
	};

	/**
	 * ajax成功后触发
	 */
	function zTreeOnAsyncSuccess(event, treeId, treeNode, msg) {
		var treeObj = $.fn.zTree.getZTreeObj(treeId);
		if (!selectallflag) {
			var rootnodes = treeObj.getNodesByParamFuzzy("icon", "global", null);
			var homenodes = treeObj.getNodesByParamFuzzy("icon", "Home", null);
			var nodes = treeObj.getNodesByParamFuzzy("icon", appendimg, null);
			setIsExistsCheckbox(treeObj, rootnodes, true);
			setIsExistsCheckbox(treeObj, homenodes, true);
			setIsExistsCheckbox(treeObj, nodes, false);
		} else {
			if (treeNode != undefined && treeNode != null) {
			    if (treeNode.checked) {
				    var childrenNodes = treeNode.childs;
			    	for (var i=0; i<childrenNodes.length; i++) {
			    		childrenNodes[i].isInitAttr = false;
						treeObj.updateNode(childrenNodes[i]);
			    		treeObj.checkNode(childrenNodes[i], true, true);
					}
			    }
		    }
		}

		var node = null;
		if (cxtree_ids != undefined && cxtree_ids != null) {
		    for (var z=0; z<cxtree_ids.length; z++) {
				node = treeObj.getNodeByParam("id", cxtree_ids[z], null);
			    if (node != undefined && node != null ) {
			    	treeObj.selectNode(node);
			    	treeObj.checkNode(node, true, false);
			    }
		    }
		}
		//默认展开第一级
		try{
			var root = jQuery("button.root_close");
			root.click();
		}catch(e){}
		
		try{
			if(jQuery("#selectallflag").val()=="true"){
				//如果开启全选
				needSelectAll(true,null);
			}
		}catch(e){}
	}


	/**
	 * checkbox选中时触发
	 */
	function zTreeOnCheck(event, treeId, treeNode) {
		var treeObj = $.fn.zTree.getZTreeObj(treeId);
		/*
		var colorstr = "";
		if (treeNode.checked) {
			colorstr = "red";
		}
		treeObj.setting.view.fontCss = {};
		treeObj.setting.view.fontCss["color"] = colorstr;
		treeObj.updateNode(treeNode);
		*/
		if (treeNode.isInitAttr == false) {
			return;
		}
		
		var nodes = treeNode.childs;
		if (nodes == null || nodes == undefined) {
			treeObj.reAsyncChildNodes(treeNode, "refresh");
		}
		//取消勾选时,去除selectedids
		var selectedids=jQuery("#selectedids").val();
		var selectednames=jQuery("#selectednames").val();
		var arrselectedids = selectedids.split(",");
		var arrselectednames = selectednames.split(",");
		var tmpselectedids = "";
		var tmpselectednames = "";
		var allchildnodes=treeObj.transformToArray(treeNode);
		for(var i=0;arrselectedids!=null&&i<arrselectedids.length;i++){
			var canceled = false;
			for(var j=0;allchildnodes!=null&&j<allchildnodes.length;j++){
				if(!allchildnodes[j].checked && arrselectedids[i]==allchildnodes[j].value){
					canceled=true;
					break;
				}
			}
			if(canceled)continue;
			if(tmpselectedids.length>0)tmpselectedids+=",";
			tmpselectedids+=arrselectedids[i];
			
			if(tmpselectednames.length>0)tmpselectednames+=",";
			tmpselectednames+=arrselectednames[i];
		}
		jQuery("#selectedids").val(tmpselectedids);
		jQuery("#selectednames").val(tmpselectednames);
	}
	
	/**
	 * 设置某些节点集合是否显示checkbox
	 */
	function setIsExistsCheckbox(treeObj, nodes, flag) {
		if (nodes != undefined && nodes != null) {
			for (var i=0; i<nodes.length; i++) {

				if (nodes[i].nocheck == flag) {
					continue;
				}
				
				nodes[i].nocheck = flag;
				treeObj.updateNode(nodes[i]);
			}
		}
	}

	/**
	 * 开启关闭全选
	 */
	function needSelectAll(flag, obj){
		selectallflag = flag;
		jQuery("#selectallflag").val(selectallflag);//记录是否开启全选
	   	var treeObj = $.fn.zTree.getZTreeObj("ztreedeep");
	   	var type = { "Y":"", "N": ""};
	   	if(selectallflag){
	   		type = { "Y":"s", "N": "s"};
	   	}
	   	treeObj.setting.check.chkboxType = type;

	   	if (!selectallflag) {
			var rootnodes = treeObj.getNodesByParamFuzzy("icon", "global", null);
			var homenodes = treeObj.getNodesByParamFuzzy("icon", "Home", null);
			var nodes = treeObj.getNodesByParamFuzzy("icon", appendimg, null);
			setIsExistsCheckbox(treeObj, rootnodes, true);
			setIsExistsCheckbox(treeObj, homenodes, true);
			setIsExistsCheckbox(treeObj, nodes, false);
		} else {
			var nodes = treeObj.getNodesByParamFuzzy("icon", "images", null);
			setIsExistsCheckbox(treeObj, nodes, false);
		}
		
		if(obj!=null){
	   	var i = $(obj).html().indexOf('>');
	   	if(selectallflag){
	        a = $(obj).html().substring(0,i+1)+' <%=SystemEnv.getHtmlLabelName(19324,user.getLanguage())%>';
	    } else{
	    	a = $(obj).html().substring(0,i+1)+' <%=SystemEnv.getHtmlLabelName(19323,user.getLanguage())%>';
	    }
			$(obj).html(a);
		}
	}
	
	function jsContain(ids, id){
		var contain = false;
		var arrids = ids.split(",");
		for(var i=0;arrids!=null&&i<arrids.length;i++){
			if(arrids[i]==id){
				contain = true;
				break;
			}
		}
		return contain;
	}
	
	function jsHasNode(cxtree_ids, nodeid){
		var hasnode = false;
		for(var i=0;cxtree_ids!=null&&i<cxtree_ids.length;i++){
			if(cxtree_ids[i]==nodeid){
				hasnode = true;
				break;
			}
		}
		return hasnode;
	}
	
	function onSaveJavaScript(cmd){
		var treeObj = $.fn.zTree.getZTreeObj("ztreedeep");
		
	    var idstr = "";
	    var namestr = "";
	    
		var nodes = treeObj.getCheckedNodes(true);
		if (nodes == undefined || nodes == "" || nodes.length < 1) {
			//return "";
		}
		
		var agceVal = ""; 
		var nuloadnode = "";
		for (var i=0; i<nodes.length; i++) {
			//开启全选 && 是一个父元素 && 被选中
			if (selectallflag && nodes[i].isParent && nodes[i].checked) {
				//子节点
				var childNodes = nodes[i].childs;
				//子节点为空,说明子节点还未ajax加载
				if (childNodes == undefined) {
					if (nodes[i].icon.indexOf(appendimg) != -1) {
						 //agceVal += ajaxGetChildEleValue(nodes[i].value, "dep");
						 if(nuloadnode!="")nuloadnode+=",";
						 nuloadnode+="dep_"+nodes[i].value;
					} else {
						 //agceVal += ajaxGetChildEleValue(nodes[i].value, "com");
						 if(nuloadnode!="")nuloadnode+=",";
						 nuloadnode+="com_"+nodes[i].value;
					}
				}
			}
			if (nodes[i].icon.indexOf(appendimg) != -1) {		
				var tmpids = jQuery("#selectedids").val();
				if(tmpids=null|| !jsContain(tmpids,nodes[i].value)){
					if(idstr!="")idstr += ",";
					idstr += nodes[i].value;
					if(namestr!="")namestr += ",";
					namestr +=  nodes[i].name.replace(",",",");
				}
			}	
			if(!jsHasNode(cxtree_ids,nodes[i].nodeid)){
				cxtree_ids.push(nodes[i].nodeid);
				if((nodes[i].level+1)>deptlevel)deptlevel=nodes[i].level+1;
			}
		}
		
		var url = "MutiDepartmentAjax.jsp";
		if(jQuery("#virtualtype").val()<0)url = "/hrm/companyvirtual/MutiDepartmentAjax.jsp";
		$.ajax({
			type : "post",
			url : url,
			data:{
				cmd:"getnuloadnode",
				nuloadnode:nuloadnode
			},
			async : true,
			success : function(data){
				agceVal = $.trim(data);
				var agceValArray = agceVal.split(",");
				var agceArray = null;
				var agceId = "";
				var agceName = "";
				for (var i=0; i<agceValArray.length; i++) {
					agceArray = agceValArray[i].split("_");
					
					if (agceArray != null && agceArray != undefined && agceArray.length > 2) {
						var tmpids = jQuery("#selectedids").val();
						if(tmpids=null|| !jsContain(tmpids,agceArray[agceArray.length - 2])){
							agceId += ",";
							agceId += agceArray[agceArray.length - 2];
							agceName += ",";
							agceName += agceArray[agceArray.length - 1].replace(",",",");;
						}
					}
				}
				idstr += agceId;
				namestr += agceName;

				if(!!cmd&&cmd=="doChange"){
						//切换组织
						if(!!idstr){
							selectedids=jQuery("#selectedids").val();
							if(selectedids.length>0)selectedids+=",";
							selectedids+=idstr;
							selectednames=jQuery("#selectednames").val();
							if(selectednames.length>0)selectednames+=",";
							selectednames+=namestr;
							
							jQuery("#selectedids").val(selectedids);
							jQuery("#selectednames").val(selectednames);
							/*
							if(!!selectedids){
								var arrSelectedids = selectedids.split(",");
								cxtree_ids = [];
								for (var i=0; i<arrSelectedids.length; i++) {
									cxtree_ids.push("com_"+arrSelectedids[i]);
								}
							}*/
						}
						return false;
					}else{
						selectedids=jQuery("#selectedids").val();
						selectednames=jQuery("#selectednames").val();
						if(!!idstr){
							if(selectedids.length>0)selectedids+=",";
							selectedids+=idstr;
							
							if(selectednames.length>0)selectednames+=",";
							selectednames+=namestr;
						}
						jQuery("#selectedids").val(selectedids);
						jQuery("#selectednames").val(selectednames);
					}
				idstr = jQuery("#selectedids").val();
				namestr = jQuery("#selectednames").val();

				var returnjson = {id:idstr, name:namestr};
		    if(dialog){
					try{
		      	dialog.callback(returnjson);
		     	}catch(e){}
					try{
		     		dialog.close(returnjson);
		 			}catch(e){}
				}else{
					window.parent.parent.returnValue = returnjson;
				  window.parent.parent.close();
				}
			}
		});
	}
	
	function onSave() {
  	onSaveJavaScript();
	}
    
    function onClear() {
      var returnjson = {id:"",name:""};
			if(dialog){
				try{
					dialog.callback(returnjson);
				}catch(e){}
				
				try{
				     dialog.close(returnjson);
				 }catch(e){}
			}else{
				window.parent.parent.returnValue = returnjson;
		  	window.parent.parent.close();
			}
	}

    
    function ajaxGetChildEleValue(subId, suptype){
    	var ajaxvalue = "";
		$.ajax({
			type : "get",
			url : "MutiDepartmentAjax.jsp?subId=" + subId + "&suptype=" + suptype,
			async : false,
			success : function(data){
				ajaxvalue = $.trim(data);
			}
		});
		
		if (ajaxvalue == undefined && ajaxvalue == null ) {
			ajaxvalue = "";
		}
		return ajaxvalue;
    }
    
    
   function btncancel_onclick(){
		if(dialog){
			dialog.close();
		}else{
	  	window.parent.parent.close();
		}
	}
	
	jQuery(document).ready(function(){
		jQuery(".leftTypeSearch").show();
		jQuery(".leftTypeSearch").height(30);
		jQuery(".leftTypeSearch").height(30);
	})
	//-->
</SCRIPT>
</HTML>