<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/context.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<meta charset="utf-8" />
		<title>部门树</title>

		<link rel="stylesheet" href="<%=path %>/common/zTree/zTreeStyle.css" />
		<link rel="stylesheet" href="<%=path %>/common/zTree/zTree.css" />
		<script src="<%=path%>/common/script/context.js" type="text/javascript"></script>
		
		<link rel="stylesheet" href="<%=path %>/common/ace/assets/css/bootstrap.min.css" />
		
		<script src="<%=path %>/common/zTree/jquery.ztree.core.js"></script>
		<script src="<%=path %>/common/zTree/jquery.ztree.excheck.js"></script>
		<script type="text/javascript">
		var api = frameElement.api, W = api.opener;
		
		 var setting = {
			view: {
				selectedMulti: false,  //是否允许同时选中多个节点
				showIcon: true
				
			},
			check: {
				 enable: true,
               	 chkStyle: "checkbox",
                 chkboxType: { "Y": "p", "N": "s" }
			},
			data: {
				simpleData: {
                          enable: true,
                          idKey: "id",
                          pIdKey: "pid",
                          rootPId: 0
                  }
			},
			async: {
				enable: true,
				dataType:"json",
				url: "viewOrganizatinos_Tree_org.action?deptId=${deptId}&orgId=${orgId}"
			},
			callback: {
				onCheck: zTreeOnClick  //选中事件件
			}
		};

		
		function zTreeOnClick(e, treeId, treeNode) {
			var zTree1 = $.fn.zTree.getZTreeObj("treeDemo");
			
			if(treeNode.isChild=="0")
			{
				var bl=treeNode.checked;
				for(var obj in treeNode.children){
				 var node = zTree1.getNodeByParam("id",treeNode.children[obj].id);
					node.checked = bl; 
					zTree1.updateNode(node);
				}
			}
		}
		
		$(document).ready(function(){
			$.fn.zTree.init($("#treeDemo"), setting);
		});
		
		$(function(){
			 //确定事件
	         $('#btn-save').on('click', function() {
	        	
	        	var checkCount;
				//获取所选择的数据
				var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
				checkCount = zTree.getCheckedNodes(true),
				mar="";
				
				if(checkCount.length==0){
	      			
	      			showMsg("alert","请选择所权限部门"); 
	       			return false;
				}
				var res = "";
				for(var i=0;i<checkCount.length;i++)
				{
					//if(checkCount[i].isChild!="0")
					//{
						if(i == checkCount.length-1){
							if(checkCount[i].id!=1)
							{//是否是顶级id
								res += checkCount[i].id +":"+checkCount[i].name;
							}
						}else{
							if(checkCount[i].id!=1)
							{
								res += checkCount[i].id +":"+checkCount[i].name + ",";
							}
						}
					//}
				}
				
				/*var result=ajaxGeneral("saveAuthorizeSysRole_menurole.action",{roleId:roleId,menus:res});
				if(result){
							showMsg("success","温馨提示:群组部门权限授权成功！");				
							api.close();
						}else{
							showMsg("error","温馨提示:群组部门权限授权失败！");
						}
				*/
				W.document.getElementById('returnValues').value=res;
				W.valuedept();
				api.close();
			});
			
			//关闭事件
			$("#btn-danger").click(function(){
				api.close();
			})
		})
		
		</script>
	</head>

	<body>
	<div style="height:480px;">
		<ul id="treeDemo" class="ztree"></ul>
	</div>
	<div align="right" style="line-height:40px;margin-bottom:0px;margin-right: 3px">
		<button class="btn btn-success" type="button"  id="btn-save" ><i class="icon-white icon-ok-sign"></i>确定</button>
		<button class="btn btn-danger" type="button" id="btn-danger" ><i class="icon-white icon-remove-sign"></i>关闭</button>
	</div>

		
		
	</body>
</html>