/*2017-07-31 add by yb
 * describe:服务包信息管理
 * 
 */
var zTreeObj = null;
var organizationTree=null;
var setting = {
	view : {
		dblClickExpand : false,
		showLine : false,
		showIcon: false
	},
	check : {
		enable : true
	},
	data : {
		simpleData : {
			enable : true
		}
	},
	callback : {
	}
};



//初始化组织树
function initOrganizationTree(){
	var contextPath=$("#contextPath").val();
	var serviceTypeId=$("#serviceTypeId").val();
	var currentStatus=$("#currentStatus").val();
	$.ajax({
		url :contextPath+"/service/type/organizationTree",
		type : "POST",
		data : {serviceTypeId:serviceTypeId,status:currentStatus},
		dataType:"json",
		success : function(data) {
			$.fn.zTree.init($("#organizationTree"), setting, data);
			organizationTree=$.fn.zTree.getZTreeObj("organizationTree");
			organizationTree.expandAll(true);
		},
		error : function(data) {
		}
	});
}

$(function() {
	//初始化组织树
	initOrganizationTree();
	
	//编辑提交
	$("#btn-save").bind("click", function() {
		//管辖的组织
		var organizationNodes=organizationTree.getCheckedNodes(true);
		var organizationIds="";
		$.each(organizationNodes,function(index,organizationNode){
			if(organizationNode.level=="1"){
				organizationIds+=organizationNode.id+";";
			}
		});
		if($.trim(organizationIds)==""){
			alert("请在右侧选择项目");
			return;
		}
		$("#organizationIds").val(organizationIds);
		
		var orderNo=$("#orderNo").val();
		if($.trim(orderNo)==""){
			alert("请输入序号");
			$("#orderNo").focus();
			return;
		}
		
		var roleGroup="";
		$('input[name="roleGroup"]:checked').each(function(){ 
			roleGroup+=($(this).val())+","; 
		}); 
		/*if($.trim(roleGroup)==""){
			alert('请选择权限分组');
			return;
		}*/
		$("#roleGroups").val(roleGroup);
		
		showBlock();
		$("#conditionform").submit();
	});
	
});
