var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
	$(document).ready(function(){
		var parentId=parent.$("#findex").val();
		$.ajax({
			type:"POST",
			url:"/pqs9900/permission/destributePermission",
			data:{
				roleIndex:parentId
			},
			success:function(data){
				//没有权限的请求
				if(data==300){
					location.href='/pqs9900/auth/unauthorized';
				//没有登陆的请求
				}else if(data==301){
					location.href='/pqs9900';
				}else{
					$.fn.zTree.init($("#permission"), setting,data.body);
				}
			}
		});
	});
	$("#cancleD").click(function(){
		parent.layer.close(index);
	});
	//根据用户的选择去分配角色
	$("#disPer").click(function(){
		var permissionIndex="";
		var parentId=parent.$("#findex").val();
		var treeObj=$.fn.zTree.getZTreeObj("permission"),
        nodes=treeObj.getCheckedNodes(true);
		if(nodes.length==0){
			layer.msg('请至少选中一个资源', {icon: 5});
		}else{
			  var v="";
			  for(var i=0;i<nodes.length;i++){
				  	if(nodes[i].index!="noIndex"){
				  		v+=nodes[i].index + ",";
				  	}
		        }
			  //重新给该角色分配资源
	 			$.ajax({
				type:"POST",
				url:"/pqs9900/permission/disPer",
				data:{
					roleIndex:parentId,
					permissionIndex:v
				},
				success:function(data){
					//没有权限的请求
					if(data==300){
						location.href='/pqs9900/auth/unauthorized';
					//没有登陆的请求
					}else if(data==301){
						location.href='/pqs9900';
					}else{
						if(data.code!=200){
							layer.msg(data.message, {icon: 5});
						}else{
							layer.msg(data.message, {
								  icon:6,
								  time: 1000 
								}, function(){
									parent.refresh();
									parent.layer.close(index);
								}); 
						}
					}
				}
			});
			  
		}
	});