
//菜单树选中该节点，该节点与子节点的方法区全选中
function childNodeTrue(menuId){
	var treeObj=$.fn.zTree.getZTreeObj("ztree1");
	var treeNode = treeObj.getNodeByParam("menuId",menuId);
	var isChecked = treeNode.checked;
	if(isChecked == true){
		$("#methodDiv"+menuId+" input[type='checkbox']").each(function(){
			$(this).prop("checked",true);
		});
	}else{
	   $("#methodDiv"+menuId+" input[type='checkbox']").each(function(){
			$(this).prop("checked",false);
		});
	}
	var isParent = treeNode.isParent;
	if(isParent == true){
		var childTreeNode = treeNode.children;
		for(var i = 0; i < childTreeNode.length; i++) {
			childNodeTrue(childTreeNode[i].menuId);
		}
	}
}

//组合动态添加的html
function appendHtmlTotal(data){
	var base,document,sale,html1,html2,html3;
		for(var i = 0; i < data.length; i++) {
			if(data[i].methodType == '基本类'){
				base = 1;
			}
			if(data[i].methodType == '文档类'){
				document = 1;
			}
			if(data[i].methodType == '业务类'){
				sale = 1;
			}
		}
		var isCheck = true;
		//初始化添加是否选中参数
		html1 = appendHtml(data,base,'基本类',isCheck);
		html2 = appendHtml(data,document,'文档类',isCheck);
		html3 = appendHtml(data,sale,'业务类',isCheck);
		var html = '<div id="methodDiv'+data[0].parentId+'" style="display:none">'+
					html1 + html2 + html3
					+'</div>';
		return html;
}
//动态添加元素
function appendHtml(data,fieldName,type){
	var html = '';
	if(fieldName != null && fieldName == 1){
		html = '<div class="col-sm-12"><h1 style="float:left">'+type+':</h1></div><div class="col-sm-12">';
		for(var i = 0; i < data.length; i++) {
			if(data[i].methodType == type){
				if(data[i].checked == 'true'){
					html += '<div class="col-sm-4"><label><input type="checkbox" value="'+data[i].menuId+'" name="methodId" class="methodCheckBox" checked onclick="checkboxOnclick()">'+data[i].menuName+"</label></div>";
				}else{
					html += '<div class="col-sm-4"><label><input type="checkbox" value="'+data[i].menuId+'" name="methodId" class="methodCheckBox"  onclick="checkboxOnclick()">'+data[i].menuName+"</label></div>";
				}
			}
		}
		html+='</div>';
	}
	return html;
}
//方法区复选框选中取消事件
function checkboxOnclick(){
	var divIndex = $("#divIndex").val();
	var allCheckNum = $("#methodDiv"+divIndex+" input[type='checkbox']").length;
	var checkedNum = $("#methodDiv"+divIndex+" input[type='checkbox']:checked").length;
	var node = ztree.getNodeByParam("menuId",divIndex);
	if(checkedNum != 0){
		//判断父节点是否选中，否则选中，该menuId赋值到menus隐藏域
		//全选，父节点选中
		if(node.checked == false){
			ztree.checkNode(node, true, true);
		}

	}
	if(checkedNum == 0){
		//全不选，父节点不选中
		ztree.checkNode(node, false, true);
	}
}

//加载菜单树
function initSysMenuTree(){
	if(sysZnodes != null){
		sysZnodes[0].open = true;
	}
	ztree = $.fn.zTree.init($("#ztree1"),setting, sysZnodes);
	var nodes = ztree.getNodes();
	ztree.expandNode(nodes[0], true, false, true);
	fuzzySearch('ztree1','#key1',null,true,setting,sysZnodes); //初始化模糊搜索方法
}

//去重
function array_remove_repeat(a) { // 去重
	var r = [];
	for(var i = 0; i < a.length; i ++) {
		var flag = true;
		var temp = a[i];
		for(var j = 0; j < r.length; j ++) {
			if(temp === r[j]) {
				flag = false;
				break;
			}
		}
		if(flag) {
			r.push(temp);
		}
	}
	return r;
}

//左侧树全部展开
function expandAll(){
	var treeObj=$.fn.zTree.getZTreeObj("ztree");
	treeObj.expandAll(true);
}
//左侧树全部关闭
function collapseAll(){
	var treeObj=$.fn.zTree.getZTreeObj("ztree");
	treeObj.expandAll(false);
}
//中间树全部展开
function expandAll1(){
	var treeObj=$.fn.zTree.getZTreeObj("ztree1");
	if(null != treeObj){
		treeObj.expandAll(true);
	}
}

//中间树全部关闭
function collapseAll1(){
	var treeObj=$.fn.zTree.getZTreeObj("ztree1");
	if(null != treeObj){
		treeObj.expandAll(false);
	}
}