/*过滤*/
var filterFlag = false;
$("#filter ul li").click(function(d){		
	var isShow = $(this).data("show");
	$(this).data("show",!isShow);
	if(isShow){
		$(this).addClass("fil");
	}else{
		$(this).removeClass("fil");
	}
	//计算需要显示的类型
	var typeArr = [];
	$("#filter ul li").each(function(){
		if(!$(this).data("show")){
			typeArr.push($(this).data("type"));
		}
	});	
	filterType(typeArr);		
});
//默认隐藏
function defaultF(){
	var defaultType=["I"];
	var isShow = '';
	$("#filter ul li").each(function(){
		for(var i=0;i<defaultType.length;i++){
			if($(this).data("type")==defaultType[i]){
				var isShow = $(this).data("show");
				$(this).data("show",false);
				$(this).addClass("fil");
			}	
		}
	});	
	//计算需要显示的类型
	var typeArr = [];
	$("#filter ul li").each(function(){
		if(!$(this).data("show")){
			typeArr.push($(this).data("type"));
		}
	});	
	filterType(typeArr);
}
//过滤类型
function filterType(typeArr){
	//graph.clearType();
	graph.filterSameType(typeArr);
	graph.para.filterType = typeArr;
	
	_.MessageManager.fire("getStatic");
	graph.refreshInfoDetail(false);
	graph.mouseoutNode();
}
/*function cancelType(){
	clearType();
	_.MessageManager.fire("getStatic");
	graph.refreshInfoDetail(false);
	graph.mouseoutNode();
}
function clearType(){
	graph.para.clearType();
	graph.para.filterType = [];
}*/

$("#filter [data-switch]").click(function(){
	if(filterFlag){
		return;
	}
	filterFlag = true;
	if(!$(this).data("switch")){
		$("#filter").css("background-color","#2F4056");
		$("#filter").css("padding","10px 0");
		$("#filter").animate({width:"150px"},500,function(){
			$(this).find("ul").show();
			filterFlag = false;
		});
		$(this).data("switch",true);
	}else{
		$("#filter ul").hide();
		$("#filter").css("padding","0");
		$("#filter").animate({width:"36px"},500,function(){
			filterFlag = false;
			$("#filter").css("background-color","#4059b4");
		});
		$(this).data("switch",false);
	}
});
function resetFilter(){
	$("#filter ul li").data("show",true).removeClass("fil");
	graph.para.filterType.splice(0,graph.para.filterType.length);
	if($("#filter [data-switch]").data("switch")){
		$("#filter [data-switch]").click();
	}
};

//筛选的js部分  
//全选
$(".check_all").click(function(){
	if(this.checked){
		$(".check_box").prop("checked",true);
	}else{
		$(".check_box").prop("checked",false);
	}		
});
//判断是否全选
$("#filterCon").delegate(".check_box","click",function(){
	var n=0;
	$(".check_box").each(function(){
		if(this.checked){
			n++;
		}
	});
	if(n==$(".check_box").size()){
		$(".check_all").prop("checked",true);
	}else{
		$(".check_all").prop("checked",false);
	}
});
$("#filterExtend .confirm_btn").click(function(){
    var checked=[];
	$(".check_box").each(function(){
	   if(this.checked){
		  checked.push($(this).data("linkid"));	   
		}
	})
	if(checked.length==0){
		if(!confirm("是否不选择！")){
			return;
		}
	}
	var graphData = $("#filterExtend").data("data");
	var newNodes = [], newLinks = [], newNodeIds = [];
	for(var i=0;i<graphData.links.length;i++){
		if(checked.indexOf(graphData.links[i].id)>=0){
			newLinks.push(graphData.links[i]);
			if(newNodeIds.indexOf(graphData.links[i].source)<0){
				newNodeIds.push(graphData.links[i].source);
			}
			if(newNodeIds.indexOf(graphData.links[i].target)<0){
				newNodeIds.push(graphData.links[i].target);
			}
		}
	}
	for(var i=0;i<graphData.nodes.length;i++){
		if(newNodeIds.indexOf(graphData.nodes[i].id)>=0){
			newNodes.push(graphData.nodes[i]);
		}
	}
	graph.processExtendNodes({nodes:newNodes,links:newLinks});
	$("#filterExtend").hide();
});
$("#filterExtend .delete_btn").click(function(){
	$("#filterExtend").hide();
});
_.MessageManager.on("showFilter",function($ev,result){
	//构建node的id和name映射
	var id2obj = new Object();
	var data = result.data;
	var thisNode = result.thisNode;
	var oldData = result.oldData;
	
	for(var i=0;i<data.nodes.length;i++){
		id2obj[data.nodes[i].id] = data.nodes[i];
	}
	for(var i=0;i<oldData.nodes.length;i++){
		id2obj[oldData.nodes[i].id] = oldData.nodes[i];
	}
	id2obj[thisNode.id] = thisNode;
	var copyLink = graph.clone(data.links); 
	for(var i=0;i<copyLink.length;i++){
		copyLink[i].srcName = id2obj[copyLink[i].source].name;
		copyLink[i].tarName = id2obj[copyLink[i].target].name;
		copyLink[i].thisNode = thisNode;
		copyLink[i].otherType = thisNode.id==copyLink[i].source?id2obj[copyLink[i].target].type:id2obj[copyLink[i].source].type;
		for(var j=0;j<copyLink[i].rel.length;j++){
			copyLink[i].rel[j] = linkNameMap[copyLink[i].rel[j]]!=undefined?linkNameMap[copyLink[i].rel[j]].cnName:"未知";
		}
	}
	var ht = baidu.template("filterCon_template",{link:copyLink});	
	$("#filterCon").html(ht);
	$("#filterExtend .filter_titleCon").html(thisNode.name);
	$("#filterExtend .check_all").prop("checked",false);
	$("#filterExtend").show().data("data",result.data);
});

/*标记*/
var markEnable = 1;
$("#markStatus .confirm_btn").click(function(){
	//赋值来源于页面，2018-01-09 
	var headSel=$(".headCon .navActive").text().trim();
	var markSource=[{"name":"查询","id":"original"},{"name":"欺诈检测","id":"original"},{"name":"专项模型","id":"special"}];
	for(var i=0;i<markSource.length;i++){
		if(headSel==markSource[i].name){
			graph.para.markWeb=markSource[i].id;
			break;
		}else{
			graph.para.markWeb=null;
		}
	}//以上是判断标注时，数据的来源，2018-01-09

	if(markEnable == 0){
		return;
	}
	markEnable = 0;
	var type = $("#markStatus .markCon").data("choose")+"";
	var content = $("#markReason").val().trim();
	var id = $("#markStatus .filter_titleCon").data("id");
	var cType=$("#markStatus .label2").text();
	var cTSem=$("#markStatus .label1").text();
	var impairmentAmount=$("#markStatus .djMoney input").val();
	var agencySelect=$("#agencySelect2 span input:checked").val();//0是机构，1是个人
	var customName = $("#customName2").val().trim();//机构或个人名称
	var isNew=$("#customName2").data("isnew"); //true为输入的数据，false为下拉框的数据
	//机构名称正则验证
	var reg=/^(.{11,100})(([\d]{4}(((0[13578]|1[02])((0[1-9])|([12][0-9])|(3[01])))|(((0[469])|11)((0[1-9])|([12][0-9])|30))|(02((0[1-9])|(1[0-9])|(2[0-8])))))|((((([02468][048])|([13579][26]))00)|([0-9]{2}(([02468][048])|([13579][26]))))(((0[13578]|1[02])((0[1-9])|([12][0-9])|(3[01])))|(((0[469])|11)((0[1-9])|([12][0-9])|30))|(02((0[1-9])|(1[0-9])|(2[0-9]))))))(.*(案))$/;
	if(agencySelect=="0" && customName!=''){
		if(!reg.test(customName)){
			markEnable = 1;
			alert("系列案名称不符合规范！请按提示输入并且日期前不少于11位字符");
			return false;
		}
	}
	/*if(impairmentAmount!=''){
		var reg2=/^[0-9]+(.[0-9]{2})?$/;//匹配只有两位小数的正式
		if(!reg2.test(impairmentAmount)){
			markEnable = 1;
			alert("输入金额的格式不正确！请重新输入");
			return false;
		}
	}*/
	if(Number(impairmentAmount)<0){
		markEnable = 1;
		alert("打假检出金额不能小于0！");
		return false;
	}else if(isNaN(Number(impairmentAmount))){
		markEnable = 1;
		alert("打假检出金额只能为数字！");
		return false;
	}
	if(type!=11){
		cTSem=null;
		cType=null;
	}

	if(type=="" || type==undefined){
		markEnable = 1;
		alert("请选择状态！");
		return;
	}
	if(type!=10){
		if(content==""){
			markEnable = 1;
			alert("请输入判定理由！");
			return;
		}
	}
	if(content.length>2000){
		markEnable = 1;
		alert("判定理由不能大于2000个字！");
		return;
	}
	$.ajax({
		type:"POST",
		url:urlPath+"/graph/mark.do",
		data:{id:id,markStatus:type,markMess:content,ctype:cType,ctsem:cTSem,markSource:graph.para.markWeb,impairmentAmount:impairmentAmount,flag:agencySelect,flagValue:customName,manual:isNew,entityType:graph.entityType},
		dataType:"json",
		success:function(result){
			if(result.status=="succ"){
				graph.markStatus(id,type,content);
			}
			alert(result.mess);
			$("#markStatus").hide();
		},
		error:function(){
			markEnable = 1;
		},
		complete:function(){
			markEnable = 1;
		}
	})	
});

$("#markStatus .delete_btn").click(function(){
	markEnable = 1;
	$("#markStatus").hide();
});
var istype=false;//判断是否是可疑“11”,2018-04-26
$("#markStatus").delegate(".options span","click",function(){
	var caseType=$("#markStatus .filter_titleCon").data("type");
	var tvalue=$("#markStatus .markCon").data("choose")+"";
	var type = $(this).data("type");
	if(tvalue!=type){
		$("#markReason").val("");
	}
	//可疑时，标注内容提示，2018-04-26
	if(type==11){
		$("#markReason").attr("placeholder","请双击或输入标注的内容,最多不超过2000字");
		istype=true;
	}else{
		$("#markReason").attr("placeholder","请输入需要标注的内容,最多不超过2000字");
		istype=false;
	}
	
	//var type = $(this).data("type");
	$(this).addClass("active1").siblings().removeClass("active1");
	$("#markStatus .markCon").data("choose",type)
	if(type==11 || type==12){
		$("#markStatus .optFor .star").show();
		if(caseType=="C"){
			$("#markStatus .djMoney").show();
		}else{
			$("#markStatus .djMoney").hide();
		}
		$("#markStatus .agencyShow").show();
		$("#markStatus #markReason").css("height","100px");
	}else{
		$("#markStatus .optFor .star").hide();
		$("#markStatus .djMoney").hide();
		$("#markStatus .agencyShow").hide();
		$("#markStatus #markReason").css("height","190px");
	}
});

//个案、串案
//$("#markStatus").delegate(".suspicious","click",function(){
$("#markStatus").delegate(".markRe","dblclick",function(){
	//var type = $(this).data("type");
	//if(type==11){
	if(istype){
		$("#gaTable").css("z-index","20001");
		$("#gaTable").show();
		$("#gaTable").data("id","markStatus");
	}
	var id = $("#markStatus .filter_titleCon").data("id");
	$.ajax({
		type:"POST",
		url:urlPath+"/graph/getType.do",
		data:{id:id},
		success:function(list){
			console.log(list);
			var str='';
			var strr='<td rowspan="'+list.gecase+'"><input data-ctype="个案"  type="checkbox" data-casecon="" class="check_box1 check_box2" name="type" value="个案"/>个案</td>';
			for(var i=0;i<list.list.length;i++){
				if(list.list[i].itemAttribute=="individualCase"){
					str+='<tr>'+strr+'<td><input data-ctype="个案" type="checkbox" data-casecon="'+list.list[i].itemName+','+list.list[i].itemDescribe+'" class="check_box" name="leixing1"/>'+list.list[i].itemName+'</td>'
					+'<td>'+list.list[i].itemDescribe+'</td></tr>'
					strr='';
				}
			}
			strr='<td rowspan="'+list.cuancase+'"><input type="checkbox" data-ctype="串案" data-casecon="" class="check_box1 check_box3" name="type" value="串案"/>串案</td>';
			for(var i=0;i<list.list.length;i++){
				if(list.list[i].itemAttribute=="OnCase"){
					str+='<tr>'+strr+'<td><input data-ctype="串案" type="checkbox" data-casecon="'+list.list[i].itemName+','+list.list[i].itemDescribe+'" class="check_box" name="leixing1"/>'+list.list[i].itemName+'</td>'
					+'<td>'+list.list[i].itemDescribe+'</td></tr>'
					strr='';
				}
			}
			$("#case_type_con").html(str);
			if(list.map==null || list.map.ctsem==null || list.map.ctype==null){
				return;
			}
			var arr=list.map.ctsem.split(",");
			$("#case_type_con .check_box").each(function(){
				var val=$(this).parent().text();
				if(arr.indexOf(val)>=0){
					$(this).prop("checked",true);
				}else{
					$(this).prop("checked",false);
				}
			});
			var arrs=list.map.ctype.split(",");
			$("#case_type_con .check_box1").each(function(){
				var val=$(this).parent().text();
				if(arrs.indexOf(val)>=0){
					$(this).prop("checked",true);
				}else{
					$(this).prop("checked",false);
				}
			});
		}
	})
});
$("#gaTable").click(function(){
	$("#gaTable .check_box").each(function(){
		if(this.checked){
			if($(this).data("ctype")=="个案"){
				$("#gaTable .check_box2").prop("checked",true);
			}
			if($(this).data("ctype")=="串案"){
				$("#gaTable .check_box3").prop("checked",true);
			}
		}
	});
});
//点击案件弹出框确定
$("#gaTable .confirm_btn").click(function(){
	var ht='';
	var cType="";
	var text="";
	$("#case_type_con .check_box").each(function(){
		if(this.checked){
			var self = $(this).data("casecon");
			ht=ht+self+",";
		}
		
	});
	var list=ht.split(",");
	for(var i=0;i<list.length;i++){
		if(i%2==0){
			cType+=list[i]+",";
			
		}else{
			text+=list[i];
			
		}
	}
	var id=$("#gaTable").data("id");
	if(id=="markStatus"){
		$("#markReason").val(text);
		$("#markStatus .label1").text(cType);
		var value="";
		$("#case_type_con .check_box1").each(function(){
			if(this.checked){
				var self = $(this).val();
				value= value+self+",";
			}
			
		})
		$("#markStatus .label2").text(value);
	}else if(id=="selectLabel2"){
		$("#markReason2").val(text);
		$("#selectLabel2 .label1").text(cType);
		var value="";
		$("#case_type_con .check_box1").each(function(){
			if(this.checked){
				var self = $(this).val();
				value= value+self+",";
			}
			
		})
		$("#selectLabel2 .label2").text(value);
	}	
	$("#gaTable").hide();
});

$("#gaTable .delete_btn").click(function(){
	$("#gaTable").hide();
});
_.MessageManager.on("showMarkCon",function($ev,result){
	//清空弹出框
	$("#markStatus .markCon span").removeClass("active1");
	$("#markStatus .markCon").data("choose","");
	$("#markStatus textarea").val("");
	$("#markStatus .filter_people").html("");
	$("#markStatus .filter_titleCon").data("type","");
	$("#markStatus .djMoney input").val("");
	$("#markStatus .mark_custom").val("");
	//判断实体是否已被系统确定标注类型 2017.11.22
	if(result.data.markStatus=="13"){
		alert("该实体已被系统确定标注类型!");
		return false;
	}
	//判断该实体是否已被确认为欺诈 2018.05.22
	if(result.data.markStatus=="12"){
		alert("该实体已被确认为欺诈!");
		return false;
	}
	$("#markStatus .filter_titleCon").html(result.data.name).data("id",result.data.id);
	$("#markStatus .filter_titleCon").data("type",result.data.type);

	/*if(result.data.markUser!=undefined){
		if(result.data.markUser==$("#userName").val()){
			$("#markStatus .filter_people").html('('+result.data.markUser+')');
			$("#markStatus .filter_title").attr("title",result.data.name+'('+result.data.markUser+')');
		}else{
			$("#markStatus .filter_people").html('('+result.data.markDate+')');
			$("#markStatus .filter_title").attr("title",result.data.name+'('+result.data.markDate+')');
		}
		
	}*/
	var status = ["10","11","12"];
	var markStatus = result.data.markStatus;
	if(status.indexOf(markStatus)>=0){
		$("#markStatus .markCon span[data-type='"+markStatus+"']").click();
		$("#gaTable").hide();
		if(result.data.markMess!=""){
			if(result.data.markUser==undefined || result.data.markUser==$("#userName").val()){
				$("#markStatus .filter_people").html('('+$("#userName").val()+')'); //标注人
				$("#markStatus .filter_title").attr("title",result.data.name+'('+result.data.markUser+')');
				$("#markStatus #markReason").val(result.data.markMess).css("color","#333");
			}else{
				$("#markStatus .filter_people").html('('+result.data.markDate+')');
				$("#markStatus .filter_title").attr("title",result.data.name+'('+result.data.markDate+')');
				$("#markStatus #markReason").val("最近一次标注时间为："+result.data.markDate).css("color","#333");
			}
			/*if(result.data.markDate=="1990-01-01 12:00:00"){
				$("#markStatus .filter_people").html('('+$("#userName").val()+')'); //标注人
				$("#markStatus textarea").val(result.data.markMess);
			}else{
				if(result.data.markUser==$("#userName").val()){
					$("#markStatus textarea").val(result.data.markMess);
				}else{
					$("#markStatus textarea").val("最近一次标注时间为："+result.data.markDate);
				}
			}*/
		}
	}else{
		$("#markStatus .optFor .star").hide();
		$("#markStatus .djMoney").hide();
		$("#markStatus .agencyShow").hide();
		$("#markStatus #markReason").css("height","190px").css("color","#333");
	}
	$("#markStatus").show();
});
//个案、串案，点击可疑时
//$("#selectLabel2").delegate(".suspicious","click",function(){
$("#selectLabel2").delegate(".markRe","dblclick",function(){
	//var type = $(this).data("type");
	//if(type==11){
	if(istype){
		$("#gaTable").show();
		$("#gaTable").css("z-index","30000");
		$("#gaTable").data("id","selectLabel2");
	}
	$.ajax({
		type:"POST",
		url:urlPath+"/graph/getType.do",
		success:function(list){
			console.log(list);
			var str='';
			var strr='<td rowspan="'+list.gecase+'"><input data-ctype="个案"  type="checkbox" data-casecon="" class="check_box1 check_box2" name="type" value="个案"/>个案</td>';
			for(var i=0;i<list.list.length;i++){
				if(list.list[i].itemAttribute=="individualCase"){
					str+='<tr>'+strr+'<td><input data-ctype="个案" type="checkbox" data-casecon="'+list.list[i].itemName+','+list.list[i].itemDescribe+'" class="check_box" name="leixing1"/>'+list.list[i].itemName+'</td>'
					+'<td>'+list.list[i].itemDescribe+'</td></tr>'
					strr='';
				}
			}
			strr='<td rowspan="'+list.cuancase+'"><input type="checkbox" data-ctype="串案" data-casecon="" class="check_box1 check_box3" name="type" value="串案"/>串案</td>';
			for(var i=0;i<list.list.length;i++){
				if(list.list[i].itemAttribute=="OnCase"){
					str+='<tr>'+strr+'<td><input data-ctype="串案" type="checkbox" data-casecon="'+list.list[i].itemName+','+list.list[i].itemDescribe+'" class="check_box" name="leixing1"/>'+list.list[i].itemName+'</td>'
					+'<td>'+list.list[i].itemDescribe+'</td></tr>'
					strr='';
				}
			}
			$("#case_type_con").html(str);
			if(list.map==null || list.map.ctsem==null || list.map.ctype==null){
				return;
			}
			var arr=list.map.ctsem.split(",");
			$("#case_type_con .check_box").each(function(){
				var val=$(this).parent().text();
				if(arr.indexOf(val)>=0){
					$(this).prop("checked",true);
				}else{
					$(this).prop("checked",false);
				}
			});
			var arrs=list.map.ctype.split(",");
			$("#case_type_con .check_box1").each(function(){
				var val=$(this).parent().text();
				if(arrs.indexOf(val)>=0){
					$(this).prop("checked",true);
				}else{
					$(this).prop("checked",false);
				}
			});
		}
	})
});

/*过滤两年内的案件和保单*/
var dateFormat = "yy-mm-dd",
	from = $("#minY").datepicker({
		dateFormat:dateFormat,
		changeMonth:true,
		changeYear:true
	}).on("change",function(){
		to.datepicker("option","minDate",getDate(this));
		$("#preSet span").removeClass("active");
	}),
	to = $("#maxY").datepicker({
		dateFormat:dateFormat,
		changeMonth:true,
		changeYear:true
	}).on("change",function(){
		from.datepicker("option","maxDate",getDate(this));
		$("#preSet span").removeClass("active");
	});
function getDate(element){
	var date;
	try{
		date = $.datepicker.parseDate(dateFormat,element.value);
	}catch(error){
		date = null;
	}
	return date;
}

$("#preSet span").click(function(e){
	e.stopPropagation();
	if($(this).hasClass("active")){

	}else{
		var thisTime = new Date();
		var dayNum = $(this).data("day");
		var minTime = thisTime.getTime()-1000*60*60*24*dayNum;
		var minDate = new Date(minTime);
		
		$(this).siblings().removeClass();
		$(this).addClass("active");
		
		from.datepicker("setDate",minDate);
		to.datepicker("setDate",thisTime);
		from.datepicker("option","maxDate",thisTime);
		to.datepicker("option","minDate",minDate);
	}
});
$("#choSet .btn").click(function(e){
	e.stopPropagation();
	if($(this).hasClass("btn-cancel")){
		$("#choSet input").val("");
		$("#preSet span").removeClass("active");
		from.datepicker("option","maxDate",null);
		to.datepicker("option","minDate",null);
		cancelFilter();
	}else{
		var flag = 1;
		var message = "";
		var maxY = $("#choSet #maxY").val();
		var minY = $("#choSet #minY").val();
		if(maxY=="" || minY==""){
			flag =2;
			message = "日期不能为空！";
		}
		var maxTime = new Date(maxY);
		var minTime = new Date(minY);
		if(maxTime<=minTime){
			flag =3;
			message = "终止时间必须大于起始时间！";
		}
		if(flag==1){
			goFilter(maxTime.getTime(),minTime.getTime());
		}else{
			alert(message);
		}
	}
});
$("#timeFilter").click(function(){
	if($("#timeFilter").data("enable")==0){
		$("#timeFilter").css("background-color","rgb(36, 38, 44)");
		$("#timeFilterCon2").css("opacity",0).show().animate({opacity:1},500);
		$("#timeFilter").data("enable",1);
		//$("#timeInput input").val(($("#timeInput input").data("value")||2015));
	}else{
		$("#timeFilter").css("background-color","#4059b4");
		$("#timeFilterCon2").hide();
		$("#timeFilter").data("enable",0);
	}
});
$("#timeFilterCon2").click(function(e){
	e.stopPropagation();
});
function goFilter(maxT,minT){
	graph.para.timeFilter = true;
	graph.clearTime();
	graph.timeFilter(maxT,minT);			
	graph.filterselect();
	if(graph.para.filterType.length>0){
		graph.filterSameType(graph.para.filterType);
	}
	
	_.MessageManager.fire("getStatic");
	graph.refreshInfoDetail(false);
	graph.mouseoutNode();
}
function cancelFilter(){
	clearTime();
	if(graph.para.filterType.length>0){
		graph.filterSameType(graph.para.filterType);
	}
	_.MessageManager.fire("getStatic");
	graph.refreshInfoDetail(false);
	graph.mouseoutNode();
}
function clearTime(){
	graph.para.timeFilter = false;
	graph.para.maxT = 0;
	graph.para.minT = 0;
	graph.recoverTimeFilter();
}
function resetTimeFilter(){
	$("#preSet span").removeClass("active");
	from.datepicker("option","maxDate",null);
	to.datepicker("option","minDate",null);
	
	$("#choSet input").val("");
	clearTime();
	$("#preSet span").removeClass("active");		
}
/*
$("#timeInput span").click(function(e){
	e.stopPropagation();
	if($(this).data("id")=="y"){
		var rule = /^\+?[1-9][0-9]*$/;
		var value = $("#timeInput input").val();
		var y = parseInt(value);
		if(rule.test(y)){
			var nowY = (new Date()).getFullYear();
			if(nowY<=y){
				$("#timeInput em").html("只能输入历史年份！");
			}else{
				graph.para.timeFilter = true;
				graph.timeFilter(nowY-y);
				graph.filterselect();
				
				_.MessageManager.fire("getStatic");
				graph.refreshInfoDetail(false);
				graph.mouseoutNode();
				
				$("#timeInput em").html("");
				$("#timeInput input").data("value",y).val(y);
			}
		}else{
			$("#timeInput em").html("请输入正整数！");
		}
	}else{
		clearTime();
		
		_.MessageManager.fire("getStatic");
		graph.refreshInfoDetail(false);
		graph.mouseoutNode();
	}	
});
*/

/*展开模式*/
$("#extendMode").click(function(){
	if($(this).data("mode")==0){
		$(this).data("mode",1);
		graph.para.extendMode = 1;
		$(this).css("background-color","rgb(36, 38, 44)").attr("title","开启抖动");
	}else{
		$(this).data("mode",0);
		graph.para.extendMode =0;
		$(this).css("background-color","#4059b4").attr("title","开启抖动");
	}
});

//单击点击复制内容
var clipboard = new Clipboard("body .cocyCon");
//复制成功执行的回调，可选
clipboard.on('success', function(e) {
	var left = getLeft(e.trigger)-28;
	var top = getTop(e.trigger)+27;
	$(".tooltips1").remove();
	$("body").append('<div class="tooltips1">复制成功! </div>');
	$(".tooltips1").css({top:top,left:left});
	setTimeout(function(){
		$(".tooltips1").remove();
	},1000);
});

//复制失败执行的回调，可选
clipboard.on('error', function(e) {
	var left = getLeft(e.trigger)-28;
	var top = getTop(e.trigger)+27;
	$(".tooltips1").remove();
	var flag = Clipboard.isSupported();
	var status = flag==false?"浏览器版本不支持！":"复制失败！"
	$("body").append('<div class="tooltips1">'+status+'</div>');
	$(".tooltips1").css({top:top,left:left});
	setTimeout(function(){
		$(".tooltips1").remove();
	},1000);
});
//框选标注
	//选项卡
$("#selectLabel2").delegate(".options span","click",function(){
	var tvalue=$("#selectLabel2 .markCon").data("choose")+"";
	var type = $(this).data("type");
	if(tvalue!=type){
		$("#markReason2").val("");
	}
	//可疑时，标注内容提示，2018-04-26
	if(type==11){
		$("#markReason2").attr("placeholder","请双击或输入标注的内容,最多不超过2000字");
		istype=true;
	}else{
		$("#markReason2").attr("placeholder","请输入需要标注的内容,最多不超过2000字");
		istype=false;
	}

	$(this).addClass("active1").siblings().removeClass("active1");
	$("#selectLabel2 .markCon").data("choose",type);
	if(type==11 || type==12){
		$("#selectLabel2 .optFor .star").css("display","block");
		$("#selectLabel2 .djMoney").show();
		$("#selectLabel2 .agencyShow").show();
		$("#selectLabel2 #markReason2").css("height","120px");
	}else{
		$("#selectLabel2 .optFor .star").css("display","none");
		$("#selectLabel2 .djMoney").hide();
		$("#selectLabel2 .agencyShow").hide();
		$("#selectLabel2 #markReason2").css("height","170px");
	}	
});

//input属性为number时，只能输入数字,屏蔽其他键,有小数点的
$("body").delegate("input[type='number']","keyup",function(){
	var val=Number($(this).val());
	if(val<0){
		alert("不能小于0！");
		$(this).val("");
		return false;
	}else if(isNaN(val)){
		alert("只能为数字！");
		$(this).val("");
		return false;
	}
})

$("body").delegate("input[type='number']","keydown",function(){	
	var k=event.keyCode;
	if((k<=57&&k>=48)||(k<=105&&k>=96)||(k==8)||(k==190)||(k==110)){
		return true;
	}else{
		return false;
	}
})

//框选标注点击确定
$("#selectLabel2 .confirm_btn").click(function(){
	//赋值来源于页面，2018-01-09 
	var headSel=$(".headCon .navActive").text().trim();
	var markSource=[{"name":"查询","id":"original"},{"name":"串案模型","id":"original"},{"name":"专项模型","id":"special"}];
	for(var i=0;i<markSource.length;i++){
		if(headSel==markSource[i].name){
			graph.para.markWeb=markSource[i].id;
			break;
		}else{
			graph.para.markWeb=null;
		}
	}//以上是判断标注时，数据的来源，2018-01-09
	
	var selectedIDs = [],mySelectedIDs=[];
	var markStatus = $("#selectLabel2 .options .active1").data("type")+"";
	var markMess = $("#selectLabel2 #markReason2").val()+"";
	var cType=$("#selectLabel2 .label2").text();
	var cTSem=$("#selectLabel2 .label1").text();
	var agencySelect=$("#agencySelect span input:checked").val();//0是机构，1是个人
	var customName = $("#customName").val().trim();//机构或个人名称
	var isNew=$("#customName").data("isnew"); //true为输入的数据，false为下拉框的数据
	//机构名称正则验证
	var reg=/^(.{11,100})(([\d]{4}(((0[13578]|1[02])((0[1-9])|([12][0-9])|(3[01])))|(((0[469])|11)((0[1-9])|([12][0-9])|30))|(02((0[1-9])|(1[0-9])|(2[0-8])))))|((((([02468][048])|([13579][26]))00)|([0-9]{2}(([02468][048])|([13579][26]))))(((0[13578]|1[02])((0[1-9])|([12][0-9])|(3[01])))|(((0[469])|11)((0[1-9])|([12][0-9])|30))|(02((0[1-9])|(1[0-9])|(2[0-9]))))))(.*(案))$/;
	if(agencySelect=="0" && customName!=''){
		if(!reg.test(customName)){
			alert("系列案名称不符合规范！请按提示输入并且日期前不少于11位字符");
			return false;
		}
	}

	if(markStatus!=11){
		cTSem=null;
		cType=null;
	}
	if(markStatus!="undefined"){
		if(markStatus=="11" || markStatus=="12"){
			if(markMess==""){
				alert("请输入判定该类型的理由！");
				return false;
			}
		}
	}else{
		alert("请选择判定类型！");
		return false;
	}
	
	$("#selectedTabCon2 tr").each(function(){
		if($(this).data("type")=="C"){
			var jsMoney=$(this).find("input").val();
			/*if(jsMoney!=''){
				var reg2=/^[0-9]+(.[0-9]{2})?$/;//匹配只有两位小数的正式
				if(!reg2.test(jsMoney)){
					markEnable = 1;
					alert("输入金额的格式不正确！请重新输入");
					return false;
				}
			}*/			
			if(Number(jsMoney)<0){
				alert("打假检出金额不能小于0！");
				return false;
			}else if(isNaN(Number(jsMoney))){
				alert("打假检出金额只能为数字！");
				return false;
			}
			var str=$(this).data("id")+'&'+jsMoney;
			selectedIDs.push(str);
		}else{
			selectedIDs.push($(this).data("id"));
		}
		mySelectedIDs.push($(this).data("id"));			
	});
	
	$.ajax({
		type:"POST",
		url:urlPath+"/baseInfo/mark2.do",
		data:{
			id:selectedIDs.join(","),
			markStatus:markStatus,
			markMess:markMess,
			ctype:cType,
			ctsem:cTSem,
			markSource:graph.para.markWeb,
			flag:agencySelect,
			flagValue:customName,
			manual:isNew
		},
		success:function(result){
			if(result.status=="succ"){
				for(var i=0;i<mySelectedIDs.length;i++){				
					graph.markStatus(mySelectedIDs[i],markStatus,markMess);
				}
			}else{
				if(typeof(result)=="string"){
					var result=JSON.parse(result); //字符串转json
				}
			}
			alert(result.mess);
			$("#selectLabel2").css("display","none");	
		}
	});
	$("#selectLabel2").css("display","none");	
})
//点击取消是执行
$("#selectLabel2 .delete_btn").click(function(){
	$("#selectLabel2").css("display","none");
});
//点击框选标注出现弹框
_.MessageManager.on("selectLabel",function($ev,data1){
	//判断实体是否已被系统确定标注类型 2017.11.22
	for(var i=0;i<data1.markSelect.length;i++){
		var item=data1.markSelect[i];
		if(item.markStatus=="13"){
			alert("有实体已经被系统确认标注类型！");
			return;			
		}else if(item.markStatus=="12"){//判断实体是否已被确认为欺诈 2018.05.22
			alert("有实体已被确认为欺诈！");
			return;	
		}
	}
	$("#selectLabel2").show();		
	var ht = baidu.template("selectLabel2_template",{data1:data1.markSelect});
	$("#selectedTabCon2").html(ht);
	$("#selectLabel2 .options span").removeClass("active1");
	$("#selectLabel2 #markReason2").val("");
	$("#agencyName").val("");
	$("#customName").val("");
	$('#selectedTabCon2').perfectScrollbar();
	$("#selectLabel2 .optFor .star").css("display","none");
	$("#selectLabel2 .agencyShow").hide();
	$("#selectLabel2 #markReason2").css("height","170px");

});


function getTop(e){
	var offset = e.offsetTop-e.scrollTop;
	if(e.offsetParent!=null){
		offset+=getTop(e.offsetParent);
	}
	return offset;
}
function getLeft(e){
	var offset = e.offsetLeft-e.scrollLeft;
	if(e.offsetParent!=null){
		offset+=getLeft(e.offsetParent);
	}
	return offset;
}

/*判断是否是专项模型页面,2018-01-16*/
if($(".nav .navActive").text().trim()=="专项模型"){
 	graph.para.webPosition="special";
}else{
	graph.para.webPosition=null;
}

/*案件图像*/
_.MessageManager.on("getCaseImg",function($ev,result){
	var branchComCode = "9010100";
	var attrs = result.data.attrs;
	for(attr_index in attrs) {
//			cnname:"标的车车架号"
//			name:"daja#CASE_TARGET_CAR_VIN"
//			type:"string"
//			value:"LFPM4ACP3C1A52583"
		if (attrs[attr_index].name == "daja#CASE_UNDERWIRTING_BRANCH_CODE") {
			if(attrs[attr_index].value!=""){
				branchComCode = attrs[attr_index].value;
				break;
			}			
		}
	}
	
	var userCode = $("#userCode").val();
	var userName = $("#userName").val();
	var userInfo = $("#userInfo").val();
	userInfo = JSON.parse(userInfo);
	userInfo.branchComCode = userInfo.branchComCode=="null"?"9010100":userInfo.branchComCode;
	userInfo.branchComName = userInfo.branchComName=="null"?"太保总公司":userInfo.branchComName;
	var xml = getCaseImgXml(userCode,userName,branchComCode,userInfo.branchComCode,userInfo.branchComName,userInfo.empType,result.data.name);
	console.info(xml);
	$.ajax({
		type:"POST",
		url:urlPath+"/sysTask/getImageUrl.do",
		success:function(result){
			window.open(result+xml);
		},
		error:function(){
			alert("请求接口失败！");
		},	
	})	
	//window.open("http://10.182.243.207:7001/SunECM/servlet/RouterServlet?format=xml&code=ECM0002&xml="+xml);//测试接口
	//window.open("http://10.190.48.90:7001/SunECM/servlet/RouterServlet?format=xml&code=ECM0002&xml="+xml);//生产接口
});
function getCaseImgXml(usercode,username,deptcode,comcode,orgname,rolecode,dataId){
	var xml = '<?xml version="1.0" encoding="UTF-8"?>'
			+'<root>'
			+ '<BASE_DATA>'
			+ '<USER_CODE>'+usercode+'</USER_CODE>'
			+ '<USER_NAME>'+username+'</USER_NAME>'
			+ '<ORG_CODE>'+deptcode+'</ORG_CODE>'
			+ '<COM_CODE>'+deptcode+'</COM_CODE>'
			+ '<ORG_NAME>'+orgname+'</ORG_NAME>'
			+ '<ROLE_CODE>cpic</ROLE_CODE>'
			+ '</BASE_DATA><META_DATA>'
			+ '<BATCH>'
			+ '<APP_CODE>CLC</APP_CODE>'
			+ '<APP_NAME>车险理赔</APP_NAME>'
			+ '<BUSI_NO>'+dataId+'</BUSI_NO>'
			+ '</BATCH>'
			+ '<SYSTEM_ID>1</SYSTEM_ID>'
			+ '</META_DATA>'
		    + '</root>';
	return xml;
}



function arrow_animate() {
	var self = $('#zhankai_arrow');
	if(self.css('left')==='20px') {
		$('.resultContainer').animate({
			width: '254px',
			height: '100%',
			opacity: 1
		})
		self.animate({
			left: '210px'
		})
		self.find('img').css('transform', 'rotate(0deg)');
		$('.result').animate({
			marginLeft: '254px'
		});
		$('#draw').animate({
			width: $(window).width()-254 +'px'
		});
	} else {
		$('.resultContainer').animate({
			width: '0px',
			height: '0px',
			opacity: 0
		})
		self.animate({
			left: '20px'
		})
		self.find('img').css('transform', 'rotate(180deg)');
		$('.result').animate({
			marginLeft: 0
		});
		$('#draw').animate({
			width: $(window).width() +'px'
		});
	}
}
$('#zhankai_arrow').click(function() {
    arrow_animate();
    if ($("#search-Btn").data("search") == 0) {
        return;
    }
    if ($('.fullScreen-btn').data("isfull") == 0) {
        $(".headCon").hide();
        $("#resultHeadPar").hide();
        $(".searchCon").hide();
        $('.fullScreen-btn').data("height", $("#draw").height());
        $("#draw").css("height", $(window).height());
        $("#cateCon").css("z-index", "0");
        $("#resultHeadPar").css("z-index", "0");
        $(".result").css("background-image", "url('" + urlPath + "/images/indexNew/bgImg.jpg')");
        $(".result").css("background-repeat", "no-repeat");
        $(".result").css("background-size", "100% 100%");
        $(".result").css({
            width: "100%"
        });
        $('.fullScreen-btn').data("isfull", 1);
        $('.fullScreen-btn').find("i").removeClass("tool-max").addClass("tool-min");
        graph.resize($(window).width(), $(window).height());
        $("#toggle").css({"background-color": "#2B3751"});
    } else {
        $(".headCon").show();
        $("#resultHeadPar").show();
        $(".searchCon").show();
        $("#draw").css("height", $(".fullScreen-btn").data("height"));
        $("#cateCon").css("z-index", $("#toggle").data("enable") == 1 ? 1 : -1);
        $("resultHeadPar").css("z-index", "1")
        $(".result").css("background-image", "");
        $(".result").css({
            width: ""
        });
        $('.fullScreen-btn').data("isfull", 0);
        $('.fullScreen-btn').find("i").removeClass("tool-min").addClass("tool-max");
        graph.resize($("#draw").width(), $("#draw").height());
        $("#toggle").css({"background-color": "#4059b4"});
    }
})