//角色树操作
var zNodes;
var menu = {
	setting: {
		view:{
			fontCss : {"font-family": "微软雅黑","color":"blue"}
		},
		data:{
			simpleData: {
				enable: true,
				idKey: "id",
				pIdKey: "parentId",

			},
		},
		callback: { //回调函数
			onClick: zTreeOnClick }
	},
	loadMenuTree:function(){
		var powerCtx = $("#powerCtx").val();
		var userId = $("#userId").val();
		$.ajax({
			type: "post",
			url:powerCtx+"/font/getRolePowerTreeBySysFlag",
			data:{sysFlag:'emr_record',userId:userId},
			dataType:"json",
			success:function(data){
				$.fn.zTree.init($("#ztree"), menu.setting, data);
				zTree = $.fn.zTree.getZTreeObj("ztree");
				var nodes = zTree.getNodes();
				for (var i = 0; i < nodes.length; i++) { //设置节点展开
					zTree.expandNode(nodes[i], true, false, true);
				}
				//第一字节点
				if(data.length>2) {
					var selfId = data[2].selfId;
					//选中该节点
					var node = zTree.getNodeByParam("selfId", selfId);
					zTree.selectNode(node);
					zTree.expandNode(node, true, false, true);
					if (null != selfId) {
						$("#iframe").prop("src", path + "/distribution/distributionManageIframe?roleId=" + selfId);
					}
				}
				zNodes = data;
				$('#loadingModal').modal('hide');
			}
		})
	}
};
//加载角色树
$().ready(function(data){
	menu.loadMenuTree();
	fuzzySearch('ztree','#key',null,true,menu.setting,zNodes); //初始化模糊搜索方法
});

//角色树点击事件
var sysZnodes;
function zTreeOnClick(event, treeId, treeNode) {
	//角色id
	var selfId = treeNode.selfId;
	if(selfId != null){
		$("#iframe").prop("src",path+"/distribution/distributionManageIframe?roleId="+selfId);
	}else{
		toastr.warning("请选中角色!");
	}
};