
//待结案优化 导出 20161215 wl start 
//设置批量导出按钮，可以使用,点击导出之后，由于效率问题，会把导出按钮设置为不可用
$(function() {
	$("input[type='button'][value='导出']").removeAttr("disabled");	
});
//待结案优化 导出 20161215 wl end
	function queryClaimTrack(claimNo){
		$("#historyTrack").find("p").remove();
		$.ajax({
			type:"POST",
			url:"queryClaimTrack.do",
			data:{"claimNo":claimNo},
			error :function(){
				alert("查询赔案操作轨迹失败，请稍后再试！");
				return ;
			},
			success :function(data){
				$("#historyTrackClaim").text(claimNo+" 历史轨迹");
				if(data ==""){
					alert("没有历史轨迹！");
					return ;
				}
				for ( var i= 0; i < data.length; i++) {
					var t=data[i];
					var p=$("<p class=\"sild_open_his\"><span class=\"sild_open_his_icon\" style=\"width:20%;white-space:nowrap;\">" +t.operateType+"</span><span style=\"width:30%;white-space:nowrap;\">"+t.operateDate+
							"	</span><span style=\"width:30%;white-space:nowrap;\">"+t.operator+"</span></p>");
					$("#historyTrack").append(p);
				}
				showDiv('open1');
			}
		});
	}

	//待结案优化 导出 20161215 wl start 
	function export_find_result_btn(){
		$("input[type='button'][value='导出']").attr("disabled","disabled");
		$("#endCaseList").submit();
	}

	//批量回退结案
	function batchRollBackEndCase_btn() {
		var n=0;
		var objlist= new Array();
		$("#endCaseListTbl tr:gt(0)").each(function (){
			if($(this).find("span").attr("class")=="check_yes"){
				var obj = new Object();
				n++;
				var check=$(this).attr("id");
				var num="claimno_"+check;
				var claimNo=$("#"+num).val();
				obj.claimNo = claimNo;
				//obj.mtype = mtype;
				objlist.push(obj);
			}
		});
		if(n==0){
			jAlert("请先选择赔案！","提示");
			return;
		}

		var baseUrl = $("#BASE_URL").val();
		$.ajax({
			type : "post",
			url : baseUrl + "/auditinfo/batchRollBackAudio.do",
			data : JSON.stringify(objlist),
			contentType:"application/json; charset=UTF-8",
			error:function(){
				jAlert("操作失败！", "提示");
				return;
			},
			success:function(data){
				if(data.message =="success"){
					jAlert("操作成功！", "提示");
					SkipByPost("showendcase.do");
				}
				else{
					jAlert("操作失败！" + data.message , "提示");	
				}
			}
		});
	}

	//待结案优化 导出 20161215 wl end 


	//结案批量发送保存数据
	function batchSend_btn(mtype){
		var n=0;
		var objlist= new Array();
		$("#endCaseListTbl tr:gt(0)").each(function (){
			if($(this).find("span").attr("class")=="check_yes"){
				var obj = new Object();
				n++;
				var check=$(this).attr("id");
				var num="claimno_"+check;
				var claimNo=$("#"+num).val();
				obj.claimNo = claimNo;
				obj.mtype = mtype;
				objlist.push(obj);
			}
		});
		if(n==0){
			alert("请先选择赔案！");
			return;
		}		
		if(mtype=='4'){			
		var str=isSendAnyone_btn();
		if(str==0){
			return;
		}
		}
		$.ajax({
			type : "post",
			url : "savebatchendcase.do",
			data : JSON.stringify(objlist),
			contentType:"application/json; charset=UTF-8",
			error:function(){
				alert("操作失败！");
				return;
			},
			success:function(data){
				if(data.message =="success"){
					if(data.refundedClaimNos) {
						alert("赔案号"+data.refundedClaimNos+"不支持批量结案");
					} else {						
						alert("操作成功！");
					}
				}
				else{
					alert("操作失败！");	
				}
			}
		});		
	}
	
	//补充结案批量发送保存数据
	function rebatchSend_btn(mtype){
		var n=0;
		var objlist= new Array();
		$("#endCaseListTbl tr:gt(0)").each(function (){
			if($(this).find("span").attr("class")=="check_yes"){
				var obj = new Object();
				n++;
				var check=$(this).attr("id");
				var num="claimno_"+check;
				var claimNo=$("#"+num).val();
				obj.claimNo = claimNo;
				obj.mtype = mtype;
				objlist.push(obj);
			}
		});
		if(n==0){
			alert("请先选择赔案！");
			return;
		}		
		$.ajax({
			type : "post",
			url : "batchbeforecase.do",
			data : JSON.stringify(objlist),
			contentType:"application/json; charset=UTF-8",
			error:function(){
				alert("操作失败！");
				return;
			},
			success:function(data){
				if(data.message =="success"){
					alert("操作成功！");
				}
				else{
					alert("操作失败！");	
				}
			}
		});		
	}
	
	//判断是否需要打印、发短信或发邮件
	function isSendAnyone_btn(){
		var objlist= new Array();
		var isconfirm=1;
		$("#endCaseListTbl tr:gt(0)").each(function (){
			if($(this).find("span").attr("class")=="check_yes"){
				var obj = new Object();
				var check=$(this).attr("id");
				var num="claimno_"+check;
				var claimNo=$("#"+num).val();
				obj.claimNo = claimNo;
				objlist.push(obj);
			}
		});
		$.ajax({
			type : "post",
			url : "issenddate.do",
			data : JSON.stringify(objlist),
			contentType:"application/json; charset=UTF-8",
			async:false,
			error:function(){
				
			},
			success:function(data){
				if(data == "0"){
				if (confirm("是否需要打印、发短信或发邮件？") == true) {
					//alert("前："+isconfirm);
					isconfirm=0;
					//alert("后："+isconfirm);
						}
					}
			}
		});	
		return isconfirm;		
	}
	
	//时间显示工具
	function jsonDateFormat(date,length){
	    var datetime = new Date();
	    datetime.setTime(date);
	    var year = datetime.getFullYear();
	    var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
	    var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
	    var hour = datetime.getHours()< 10 ? "0" + datetime.getHours() : datetime.getHours();
	    var minute = datetime.getMinutes()< 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
	    var second = datetime.getSeconds()< 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
	    if(length==10){
	    	return year + "-" + month + "-" + date;
	    }else{
	    	return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second;
	    }
	}
	
	//判断是否全选
	function checkAll(flag1,flag2){
		if(flag2=="1"){//总开关
			if($(flag1).attr("class")=="check_no"){
				$("#endCaseListTbl tr:gt(0)").each(function (){
					$(this).find("span").attr("class","check_yes");
				});
			}else{
				$("#endCaseListTbl tr:gt(0)").each(function (){
					$(this).find("span").attr("class","check_no");
				});
			}
		}else{//子开关
			if($(flag1).attr("class")=="check_yes"){
				var bool=false;
				$("#endCaseListTbl tr:gt(0)").each(function (){
					if($(this).find("span").attr("class")=="check_no"){
						bool=true;
						return;
					}
				});
				if(!bool){
					$("#titSpan").attr("class","check_yes");
				}
			}else{
				$("#titSpan").attr("class","check_no");
			}
		}
	}
	//清空所有全选按钮选框
	function clearChecked(){
		$("#endCaseListTbl tr").each(function (){
			$(this).find("span").attr("class","check_no");
		});
	}	
	
	//选择险种后续处理时触发
	function selectProcess(name, val) {
		if(name=="iscase"){
		$("#caseprotice").val(val);	
		}
		if(name=="isresult"){
		$("#payresult").val(val);		
		}

		 // 待结案优化 导出 2016年12月19日 Add wl start 
		 // 结案状态 0:全部 1:待结案 2:结案失败
		if(name=="endcaseStatus"){
			$("#endcaseStatus").val(val);		
		}
		 // 待结案优化 导出 2016年12月19日 Add wl end 
	}
	
	//翻页
	function cur_skip(s,e){
		/*var nextcheck=[];
		nextcheck=allselect();
		var refindchek;
		var strlist=[];
		refindchek=$("#findcheckArry").val();
		if(refindchek!=null && refindchek.length>0){		
		strlist=refindchek.split(",");		
		nextcheck.push(strlist);
		}
		*/
		var pn = $(e).find("span").html();
		var json = {pageNo:pn,claimNoQuery:$("#claimNoQuery").val(),policyNo:$("#policyNo").val(),enterDateFrom:$("#enterDateFrom").val(),enterDateTo:$("#enterDateTo").val(),pid:$("#pid").val(),pname:$("#pname").val(),batchNo:$("#batchNo").val(),caseprotice:$("#caseprotice").val(),payresult:$("#payresult").val()};
		//SkipByPost("showendcase.do",{pageNo:pn,nextcheck:nextcheck});
		if(s=="1"){
		SkipByPost("showendcase.do",{pageNo:pn});
		}
		else if(s=="2"){
		SkipByPost("showbeforeendcase.do",json);
		}
		$(".turn_cur").removeAttr("class");
		$(e).find("span").attr("class","turn_cur");
	}

	//前一页
	function pre(s,e){
		//var nextcheck=[];
		var cur = $("#nav").find(".turn_cur").html();
		if(cur==1){
			return;
		}
		/*nextcheck=allselect();		
		var refindchek;
		var strlist=[];
		refindchek=$("#findcheckArry").val();
		if(refindchek!=null && refindchek.length>0){		
		strlist=refindchek.split(",");		
		nextcheck.push(strlist);
		}*/		
		if(cur>1){
		var pre = Number(cur)-Number(1);	
		var json = {pageNo:pre,claimNoQuery:$("#claimNoQuery").val(),policyNo:$("#policyNo").val(),enterDateFrom:$("#enterDateFrom").val(),enterDateTo:$("#enterDateTo").val(),pid:$("#pid").val(),pname:$("#pname").val(),batchNo:$("#batchNo").val(),caseprotice:$("#caseprotice").val(),payresult:$("#payresult").val()};
		
		//SkipByPost("showendcase.do",{pageNo:pre,nextcheck:nextcheck});
		if(s=="1"){
			SkipByPost("showendcase.do",{pageNo:pre});
			}
			else if(s=="2"){
			SkipByPost("showbeforeendcase.do",json);
			}
		}
		/*else{
			SkipByPost("showendcase.do",{pageNo:maxPage});
		}*/
	}
	//下一页
	
	function next(s,e){
		//var nextcheck=[];
		//var refindchek;
		//var strlist=[];
		var cur = $("#nav").find(".turn_cur").html();
		var next = Number(cur)+Number(1);
		var maxPage = $("#max").val();
		
		if(parseInt(cur)==parseInt(maxPage)){			
			return;
		}
		
		/*nextcheck=allselect();
		
		refindchek=$("#findcheckArry").val();		
		if(refindchek!=null && refindchek.length>0){		
			strlist=refindchek.split(",");		
			strlist.push(nextcheck);
			}
		else{		
			strlist=nextcheck;		
		}
		*/
		var json = {pageNo:next,claimNoQuery:$("#claimNoQuery").val(),policyNo:$("#policyNo").val(),enterDateFrom:$("#enterDateFrom").val(),enterDateTo:$("#enterDateTo").val(),pid:$("#pid").val(),pname:$("#pname").val(),batchNo:$("#batchNo").val(),caseprotice:$("#caseprotice").val(),payresult:$("#payresult").val()};
		if(parseInt(cur)<parseInt(maxPage)){
			//SkipByPost("showendcase.do",{pageNo:next,nextcheck:strlist});
			if(s=="1"){
				SkipByPost("showendcase.do",{pageNo:next});
				}
				else if(s=="2"){
				SkipByPost("showbeforeendcase.do",json);
				}
		}
		/*else{
			SkipByPost("showendcase.do",{pageNo:1});
		}*/
	}
	//跳转至
	function custom(s){		
		
		//var nextcheck=[];
		var maxPage = $("#max").val();
		var pn = $.trim($("#turn_inp").val());
		
		if(pn == "") {
			return;
			}
		if(pn>maxPage){
			return;
		}
		
		/*nextcheck=allselect();			
		
		var refindchek;
		var strlist=[];
		refindchek=$("#findcheckArry").val();
		if(refindchek!=null && refindchek.length>0){		
		strlist=refindchek.split(",");		
		nextcheck.push(strlist);
		}*/
		var json = {pageNo:Number(pn),claimNoQuery:$("#claimNoQuery").val(),policyNo:$("#policyNo").val(),enterDateFrom:$("#enterDateFrom").val(),enterDateTo:$("#enterDateTo").val(),pid:$("#pid").val(),pname:$("#pname").val(),batchNo:$("#batchNo").val(),caseprotice:$("#caseprotice").val(),payresult:$("#payresult").val()};
		
		if(s=="1"){
			SkipByPost("showendcase.do",{pageNo:Number(pn)});
			}
			else if(s=="2"){
			SkipByPost("showbeforeendcase.do",json);
			}
		//SkipByPost("showendcase.do",{pageNo:Number(pn),nextcheck:nextcheck});
	}
	//记录选中项
	function  allselect(){
		var check = [];
		var s=0;
		$("#endCaseListTbl tr:gt(0)").each(function (){
			if($(this).find("span").attr("class")=="check_yes"){				
				check[s]=$(this).attr("id");	
				s++;
			}
		});	
	return check;
	}

	
	//本地打印通知书
	function localPrint(){
		var n=0;
		var objlist= new Array();
		$("#endCaseListTbl tr:gt(0)").each(function (){
			if($(this).find("span").attr("class")=="check_yes"){
				var obj = new Object();
				n++;
				var check=$(this).attr("id");
				var num="claimno_"+check;
				var claimNo=$("#"+num).val();
				obj.claimNo = claimNo;
				objlist.push(obj);
			}
		});
		if(n==0){
			alert("请先选择赔案！");
			return;
		}
		$("#localprint").attr('disabled',true);
		$.ajax({
			type : "post",
			url : "localPrint.do",
			data : JSON.stringify(objlist),
			contentType:"application/json; charset=UTF-8",
			error:function(){
				alert("操作失败！");
				$("#localprint").attr('disabled',false);
				return;
			},
			success:function(data){
				if(data.message =="success"){
					alert("操作成功！");
					$("#localprint").attr('disabled',false);
				}
				else{
					alert("操作失败！");
					$("#localprint").attr('disabled',false);
				}
			}
		});		
	}
	
	//下载通知书
	function downNotice_btn(){
		var ipAddress=$("#ipAddress").val();
		var n=0;
		var objlist= new Array();
		$("#endCaseListTbl tr:gt(0)").each(function (){
			if($(this).find("span").attr("class")=="check_yes"){
				var obj = new Object();
				n++;
				var check=$(this).attr("id");
				var num="claimno_"+check;
				var claimNo=$("#"+num).val();
				obj.claimNo = claimNo;
				objlist.push(obj);
			}
		});
		if(n==0){
			alert("请先选择赔案！");
			return;
		}		
		
		$("#downloadNotice").attr('disabled',true);
		$.ajax({
			type : "post",
			url : "hasNoticeOfClaimNo.do",
			data : JSON.stringify(objlist),
			contentType:"application/json; charset=UTF-8",
			error:function(){
				alert("操作失败！");
				$("#downloadNotice").attr('disabled',false);
				return;
			},
			success:function(data){
				if(data=="1"){
				
					SkipByPost(ipAddress+"/claimserver/claim/noticeMoreDownload.do",{jsonStr:JSON.stringify(objlist)});
					$("#downloadNotice").attr('disabled',false);
				}else if(data =='2'){
					alert("数据有误，请联系管理员！");
					$("#downloadNotice").attr('disabled',false);
				}else if(data =='3'){
					$("#downloadNotice").attr('disabled',false);
				}else{
					alert("通知书获取中，请等待！");
					$("#downloadNotice").attr('disabled',false);
				}
			}
		});	
	}
	
	
	function listPageFn(pageNo,pageType){
		if(pageType==1){//首页
			if($("#page").val()=="0"){
				return;
			}else{
				$("#page").val("0");
			}
		}else if(pageType==2){//上一页
			if($("#page").val()=="0"){
				return;
			}else{
				$("#page").val(($("#page").val()*1)-1);
			}
		}else if(pageType==3){//下一页
			if(($("#page").val()*1+1)==$("#totalPages").val()){
				return;
			}else{
				$("#page").val(($("#page").val()*1)+1);
			}
		}else if(pageType==4){//尾页
			if(($("#page").val()*1+1)==$("#totalPages").val()){
				return ;
			}else{
				$("#page").val($("#totalPages").val()*1-1);
			}
		}else if(pageType==5){//跳转至
			var patrn=/^\d+$/; 
			if(pageNo==null || pageNo==""){
				return ;
			}
		    if (!patrn.exec(pageNo)) {
		    	alert("输入非法!");
		    	return ;
		    }else{
		    	if(pageNo!="0"&&(pageNo*1)<=$("#totalPages").val()*1){
		    		$("#page").val((pageNo*1-1));
		    	}else{
		    		alert("输入非法!");
			    	return ;
		    	}
		    }
		}else {
			alert("无效操作!");
			return;
		}

		//待结案优化 导出 20161215 wl start 
		var tmp = $("#formId").attr("action");
		if(null != tmp && "" != tmp) {
			if(tmp.lastIndexOf("showendcase.do") > 0) {				
				editNextPageCondition();

			    $("#formId").attr("action",'/claimserver/claim/queryEndcondation.do');
				$("#formId").attr("method","POST");
				$("#formId").submit();
			} else {
				queryByCondsFn();
			}
		}
		//待结案优化 导出 20161215 wl end 

		//待结案优化 导出 edit 20161215 wl start
		//queryByCondsFn();
		//待结案优化 导出 edit 20161215 wl end
	}
	
	function queryByCondsFn(){
		$("#formId").submit();
		$("#page").val('');
	}

	//待结案优化 导出 20161215 wl start
	function editNextPageCondition() {
		var claimNoad = $("#claimNoad").val(); 
		var policyNo = $("#policyNo").val(); 
		var enterDateFrom = $("#enterDateFrom").val(); 
		var enterDateTo = $("#enterDateTo").val(); 
		var reportDateFrom = $("#reportDateFrom").val(); 
		var reportDateTo = $("#reportDateTo").val(); 
		var filedcaseDateFrom = $("#filedcaseDateFrom").val(); 
		var filedcaseDateTo = $("#filedcaseDateTo").val(); 
		var unitName = $("#unitName").val(); 
		var batchNo = $("#batchNo").val(); 
		var caseprotice = $("#caseprotice").val(); 
		var payresult = $("#payresult").val(); 
		var endcaseStatus = $("#endcaseStatus").val(); 
		var page = $("#page").val(); 
		var totalPages = $("#totalPages").val(); 

		var claimNo2 = $("#claimNo2").val(); 
		var policyNo2 = $("#policyNo2").val(); 
		var enterDateFrom2 = $("#enterDateFrom2").val(); 
		var enterDateTo2 = $("#enterDateTo2").val(); 
		var reportDateFrom2 = $("#reportDateFrom2").val(); 
		var reportDateTo2 = $("#reportDateTo2").val(); 
		var filedcaseDateFrom2 = $("#filedcaseDateFrom2").val(); 
		var filedcaseDateTo2 = $("#filedcaseDateTo2").val(); 
		var unitName2 = $("#unitName2").val(); 
		var batchNo2 = $("#batchNo2").val(); 
		var caseprotice2 = $("#caseprotice2").val(); 
		var payresult2 = $("#payresult2").val(); 
		var endcaseStatus2 = $("#endcaseStatus2").val(); 
		var pageNo2 = $("#pageNo2").val(); 
		var totalPages2 = $("#totalPages2").val(); 

		if((null == claimNoad || "" == claimNoad) && (null != claimNo2 && "" != claimNo2)) { $("#claimNoad").val(claimNo2);} 
		if((null == policyNo || "" == policyNo) && (null != policyNo2 && "" != policyNo2)) { $("#policyNo").val(policyNo2);} 
		if((null == enterDateFrom || "" == enterDateFrom) && (null != enterDateFrom2 && "" != enterDateFrom2)) { $("#enterDateFrom").val(enterDateFrom2);} 
		if((null == enterDateTo || "" == enterDateTo) && (null != enterDateTo2 && "" != enterDateTo2)) { $("#enterDateTo").val(enterDateTo2);} 
		if((null == reportDateFrom || "" == reportDateFrom) && (null != reportDateFrom2 && "" != reportDateFrom2)) { $("#reportDateFrom").val(reportDateFrom2);} 
		if((null == reportDateTo || "" == reportDateTo) && (null != reportDateTo2 && "" != reportDateTo2)) { $("#reportDateTo").val(reportDateTo2);} 
		if((null == filedcaseDateFrom || "" == filedcaseDateFrom) && (null != filedcaseDateFrom2 && "" != filedcaseDateFrom2)) { $("#filedcaseDateFrom").val(filedcaseDateFrom2);} 
		if((null == filedcaseDateTo || "" == filedcaseDateTo) && (null != filedcaseDateTo2 && "" != filedcaseDateTo2)) { $("#filedcaseDateTo").val(filedcaseDateTo2);} 
		if((null == unitName || "" == unitName) && (null != unitName2 && "" != unitName2)) { $("#unitName").val(unitName2);} 
		if((null == batchNo || "" == batchNo) && (null != batchNo2 && "" != batchNo2)) { $("#batchNo").val(batchNo2);} 
		if((null == caseprotice || "" == caseprotice) && (null != caseprotice2 && "" != caseprotice2)) { $("#caseprotice").val(caseprotice2);} 
		if((null == payresult || "" == payresult) && (null != payresult2 && "" != payresult2)) { $("#payresult").val(payresult2);} 
		if((null == endcaseStatus || "" == endcaseStatus) && (null != endcaseStatus2 && "" != endcaseStatus2)) { $("#endcaseStatus").val(endcaseStatus2);} 
		if((null == page || "" == page) && (null != pageNo2 && "" != pageNo2)) { $("#page").val(pageNo2);} 
		if((null == totalPages || "" == totalPages) && (null != totalPages2 && "" != totalPages2)) { $("#totalPages").val(totalPages2);} 


	}
	//待结案优化 导出 20161215 wl end 