var ExcelJsonStr = '';

$(function(){
	//复选框
	$(".check_yes1,.check_no1").click(function(){
		  if($(this).is(".check_yes1")){
		    
			$(this).removeClass("check_yes1");
			$(this).addClass("check_no1"); 
		  
		  }else{
				$(this).removeClass("check_no1");
		        $(this).addClass("check_yes1");
		}
	      
		  
	 });
	selected();
});

function amount(){
	var isbpo=getIsBpo();
	//来源
	var caseSource = getCaseSuorceNo($("#caseSource").html());
	
	//年度
	var year = $(".table_con span:eq(3)").html();
	
	//维度
	var dimension=$("#dimension").attr("value");
	//精度
	var longitude="";
	
	if(dimension=="month"){
		longitude = $("#monthV").attr("value");
	}else if(dimension=="season"){
		longitude = $("#seasonV").attr("value");
	}else if(dimension=="year"){
		longitude = $("#yearV").attr("value");
	}
	//时效
	var limitTimeRange=$("#limitTime").attr("value");
	
	if(year==''||year=='请选择统计年度'){
		alert('请选择统计年度');
		return;
	}
	
	if(longitude==''||longitude=='请选择类型'){
		alert('请选择统计维度');
		return;
	}
	ExcelJsonStr ='';
	showLoading();
	$.ajax({
		type : "POST",
		url : "/claimserver/bpoInterface/bpoTimeAmountSerach.do",
		data : {
			"isBpo" : isbpo,
			"caseSource" : caseSource,
			"year" : year,
			"dimension": dimension,
			"longitude": longitude,
			"timeRange": limitTimeRange
		},
		success : function(data) {
			if(data!=null&&data.length>0){
				$("#SHcon2 table tr").each(function(i){
					if(i>1){
						$(this).remove();
					}
				});	
				$("#SHcon2 table tr:eq(0) + tr").remove();
				for(var i=0;i<data.length;i++){
					var trHtml = '<tr><td>'+data[i].limitTimeRange+'</td><td>'+data[i].claimNum+'</td><td>'+data[i].averageTime+'</td></tr>';
					$("#SHcon2 table").append(trHtml);
					
					ExcelJsonStr+='{"limitTimeRange":"'+data[i].limitTimeRange+'",'
							    +'"claimNum":"'+data[i].claimNum+'",'
							    +'"averageTime":"'+data[i].averageTime+'"},';
				}
				if(ExcelJsonStr!=''){
					ExcelJsonStr ="["+ExcelJsonStr.substring(0,ExcelJsonStr.length-1)+"]";
				}
				$("#SHcon2").show(); 
				closeLoading();
			}else{
				$("#SHcon2 table tr").each(function(i){
					if(i>=1){
						$(this).remove();
					}
				});
				closeLoading();
				alert("未查询到符合条件的数据");
			}
		},
		error : function() {
			alert("查询数据失败");
		}
	});	
}


function excelExport(){
	if(ExcelJsonStr==''){
		alert("没有需要导出的数据");
	}else{
		$("#ExcelJsonStr").val(ExcelJsonStr);
		$("form").attr('action','/claimserver/bpoInterface/excleExportBpoTimeAmount.do');
		$("form").submit();
	}
}







function selected(){
	$(".select").hover( function () {
		$(this).addClass("sel_over");
	},function () {
		$(this).removeClass("sel_over");
	}).on('click',function(){
		var _this = $(this),
			_bthis = $(this).find(".sel_list");
		if ( _this.attr('isopen') ) {
			_bthis.slideUp(0 , function(){
				_this.removeAttr('isopen');
			});			
		} else {
			_bthis.slideDown(0,function(){
				_this.attr('isopen',"1");
			});	
		}
	}).on('mouseleave',function(){
		var _thisa = $(this).find(".sel_list"),
			_this = $(this);
		_thisa.hide();
		_this.removeAttr('isopen');
	}),$(".select").find(".sel_list li").hover( function (){
		$(this).addClass("sel_hov");		
	},function (){
		$(this).removeClass("sel_hov");	
	}).on('click',function(){
		var _this = $(this).html();
		var _value=$(this).attr("code");
		var _thisText = $(this).closest(".select").find(".sel_text");
		_thisText.attr("value",_value);
		_thisText.html(_this);
		
		//维度联动
		getSecondSpan(_value);
	});
}

function getSecondSpan(value){
	
	if(value=="month"){
		$("#season").hide();
		$("#year").hide();
		$("#"+value).show();
	}else if(value=="season"){
		$("#month").hide();
		$("#year").hide();
		$("#"+value).show();
	}else if(value=="year"){
		$("#month").hide();
		$("#season").hide();
		$("#"+value).show();
	}
}


//扫描机构勾选情况   1.BPO   2.非BPO  3.全部     
function getIsBpo(){
	var type="";
	var bpo_y=$(".table_con span:eq(0)").attr("class")=='check_yes1'?'Y':'N';
	var bpo_n=$(".table_con span:eq(1)").attr("class")=='check_yes1'?'Y':'N';
	if(bpo_y=='Y'&&bpo_n=='Y'){
		type='';
	}
	if(bpo_y=='Y'&&bpo_n=='N'){
		type='01';
	}
	if(bpo_y=='N'&&bpo_n=='Y'){
		type='02';
	}
	return type;
}


function showLoading(){
	$("body").append("<div id='loading_cen' class='loading_cen'></div>");
	createSelectBg();
	var select_content = $("#loading_cen");
	var top = ($(window).height()- select_content.height())/2;
	var left = ($(window).width()-select_content.width())/2;
	select_content.css("top",top);
	select_content.css("left",left);
	select_content.css("z-index",10001);
	select_content.show();
}

function closeLoading(){
	if($("#loading_cen").is(".loading_cen")){
		$("#loading_cen").remove();
		$("#lock_select_bg").remove();
	}
}
function createSelectBg() {
	if ($("#lock_select_bg").is(".lock_select_bg")) {
		$("#lock_select_bg").show();
	} else {
		$("body")
				.append(
						"<div id='lock_select_bg' class='lock_select_bg' style='position:absolute;left: 0px; top: 0px;display:none'></div>");
		$("#lock_select_bg").show();
		var lock = $("#lock_select_bg");
		var height = $(document).height();
		var width = $(document).width();
		lock.css("height", height);
		lock.css("width", width);
		lock.css("opacity", 0.5);
		lock.css("z-index", 10000);
		lock.css("background", "#000");
	}
}

//箭头朝上显示隐藏
function showTopOpen(id,obj){
		createBg();
		var left = $(obj).offset().left-$("#"+id).width()/2+15;
		var top = $(obj).offset().top+$(obj).height()+5;
		$("#"+id).css({"display":"block","left":left,"top":top});
		
		$("#lock_click_bg").unbind();
		$("#lock_click_bg").bind("click",function(){$("#lock_click_bg").hide();$("#"+id).hide()});
} 


//鼠标经过显示隐藏弹出小层
function createBg(){
	if($("#lock_click_bg").is(".lock_click_bg")){
		$("#lock_click_bg").show();
	}else{
		$("body").append("<div id='lock_click_bg' class='lock_click_bg' style='position:absolute;left: 0px; top: 0px;display:none'></div>");
		$("#lock_click_bg").show();
		var lock = $("#lock_click_bg");
		var height = $(document).height();
		var width = $(document).width();
		lock.css("height", height);
		lock.css("width", width);
		lock.css("background","#000");
		lock.css("opacity", 0);
		lock.css("z-index",100);
	}
}

//获取赔案来源编号
function getCaseSuorceNo(text){
	var SuorceNo = '';
	if(text!=''&&text!=undefined){
		$(".table_con li").each(function(){
			if($(this).html()==text){
				SuorceNo = $(this).attr("id");
			}
		});
	}
	return SuorceNo;
}


