//打开影像
function openImage(flag){
	var caseSource = $("#caseSource").val();
	var claimNo = $("#claim-no").val();
	var iscommon= $("#isBpo").val();
	if(flag=="1"){//赔案影像
		if("1"==caseSource  && iscommon=="Y"){
			callEcm(claimNo,"");
		}else{
			window.open('../../inspection/clmtask/imageInfo.do?claimNo='+claimNo,"影像");
		}
	}
	if(flag=="2"){
		if("1"==$("#caseSource").val()){
			callEcm(claimNo,"2");
		}else{
			window.open('../../inspection/clmtask/imageInfo.do?claimNo='+claimNo+'&flag=2',"保单影像");
		}

	}
}


//	任务池查询
	function submitPageForm(){
		$("#formId").attr("action","requestPools.do");
		$("#formId").attr("method","POST");
		$("#formId").submit();
	}
//	进入立案页面
	function submitFiledCaseForm(claimNo){
		$("#claimNo").val(claimNo);
		$("#formId").attr("action","requestFiledCase.do");
		$("#formId").attr("method","POST");
		$("#formId").submit();
	}
//	模糊查询
	function queryCondTask(){
		var cond=$("#searchCond").val();
		if(cond=="" || cond==null ||(cond.trim().length!=15&&cond.trim().length!=10&&cond.trim().length!=8)){
			 alert("录入格式错误，请输入15位赔案号或者8位和10位日期(20140101/2014-01-01)");
			 return ;
		}else{
			$("#formId").attr("action","searchCond.do");
			$("#formId").attr("method","POST");
			$("#formId").submit();
		}
	}
//	排序 
	function setSortValue(sortValue){
		$("#sortValue").val(sortValue);
		$("#formId").attr("action","showTaskSort.do");
		$("#formId").submit();
	}
//	查询赔案操作轨迹
	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');
			}
		});
	}
//	时间显示工具
	function jsonDateFormat(date,length){
		if(date==null || date==""){
			return "";
		}
		if(isNaN(date)){
			return date;
		}
	    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 skip2OtherPage(url,claimNo,pid,pageFrom){
		var params = new Array();
		params["claimNo"] = claimNo;
		params["pid"] = pid;
		params["pageFrom"] = pageFrom;
		SkipByPost(url, params);
	}
	
//	选择需要移入的行
	var index;
	function selectDeceitReason(flag){
		var tblId=$(flag).parent().parent().attr("id");
		$("#la_cc_con_tblList2").attr("onclick","changeRight()");
		$("#la_cc_con_tblList1").attr("onclick","changeLeft()");
		$("#la_cc_con_tblList2").find("a").css("color","#007aff");
		$("#la_cc_con_tblList1").find("a").css("color","#007aff");
		$("#la_cc_con_"+tblId).removeAttr("onclick");
		$("#la_cc_con_"+tblId).find("a").css("color","#ccc");
		
		$(flag).css("background-color", "#e5e5e5").siblings().css("background-color", "#FFFFFF");
		index=$(flag).index();
	}
//	移入
	function changeRight(){
		if(index==null){
			alert("请选择需要移入的欺诈嫌疑信息！");
			return;
		}
		var tr=$("<tr onclick=\"selectDeceitReason(this)\"></tr>");
		var td=$("#tblList1 tr").eq(index).html();
		var text=$("#tblList1 tr").eq(index).find("td:eq(0)").find("input:eq(0)").val();
		$("#deceitMemo").removeAttr("readonly");
		if("99"==text){
			$("#deceitOthDesc").removeAttr("readonly");
		}
		$("#tblList1 tr").eq(index).remove();
		$(tr).append(td);
		$("#tblList2").append(tr);
		index=null;
	}
//	移出
	function changeLeft(){
		if(index==null){
			alert("请选择需要移出的欺诈嫌疑信息！");
			return;
		}
		var tr=$("<tr onclick=\"selectDeceitReason(this)\"></tr>");
		var td=$("#tblList2 tr").eq(index).html();
		var text=$("#tblList2 tr").eq(index).find("td:eq(0)").find("input:eq(0)").val();
		if("99"==text){
			$("#deceitOthDesc").val("");
			$("#deceitOthDesc").attr("readonly","readonly");
		}
		if($("#tblList2 tr").index()<=0){
			$("#deceitMemo").val("");
			$("#deceitMemo").attr("readonly","readonly");
		}
		$("#tblList2 tr").eq(index).remove();
		$(tr).append(td);
		$("#tblList1").append(tr);
		index=null;
	}
// 预估金额校验数字类型
	function validateClmEstimate(flag){
		var value=$(flag).val();
		if(value==""){
			return ;
		}else{
			if(isNaN(value)){
				alert("请输入一个正确的金额！");
				$(flag).val("");
			}else{
				if((!isNaN(value)&&value<0)|| value.indexOf("-")!=-1){
					alert("请输入一个非负数的金额！");
					$(flag).val("");
				}else{
					value=parseFloat(value).toFixed(2);
					if(value.length>15){
						alert("请输入一个有效的金额！");
						$(flag).val("");
					}else{
						$(flag).val(value);
					}
				}
			}
		}
	}
// 获取保存与立案的数据
	var jsonStr="";
	var estAmtSum;
	function getData(){
		var bool=true;
		estAmtSum=0;
//		赔案号
		var claimNo=$("#tblClmTaskInfo tr:eq(0)").find("td:eq(0)").text();
//		var dpa=$("#dpa").val()==""?"0":$("#dpa").val();
//		var tpa=$("#tpa").val()==""?"0":$("#tpa").val();
		var dpa="0";
		var tpa="0";
//		险种列表
		var estAmtList="";
		var plcpolicyList="";
		$("#tblPlcPolicyInfo tr:gt(0)").each(function(i){
			if(!$(this).find("td:eq(4)").find("input").attr("readonly")){
				var policyNo=$(this).find("td:eq(0)").find("input:eq(1)").val();
				var sysattr=$(this).find("td:eq(0)").find("input:eq(0)").val();
				var classcode= $(this).find("td:eq(1)").find("input:eq(0)").val();
				var estAmt=$(this).find("td:eq(4)").find("input").val();
				estAmt=estAmt==null?"0":estAmt==""?"0":estAmt;
				estAmtSum+=parseFloat(estAmt);
				estAmtList+=	'{"classCode":"' + classcode + '","estamt":"' + estAmt+ '","policyNo":"' + policyNo+'"},';
				plcpolicyList+='{"classcode":"' + classcode + '","policyno":"' + policyNo+ '","sysattr":"'+sysattr+'"},';
			}
		 });
		estAmtList="["+estAmtList.substring(0, estAmtList.length-1)+"]";
		plcpolicyList="["+plcpolicyList.substring(0, plcpolicyList.length-1)+"]";
//	 	欺诈嫌疑描述
		var deceitReason="";
		var deceitOthDesc="";
		var deceitMemo="";
		$("#tblList2 tr").each(function(i){
			var deceitType=$(this).find("td:eq(0)").find("input:eq(0)").val();
			var deceitReasonCode=$(this).find("td:eq(1)").find("input:eq(0)").val();
			deceitReason+=	'{"deceitType":"' + deceitType + '","deceitReasonCode":"' + deceitReasonCode+ '"},';
			deceitMemo=$("#deceitMemo").val();
			if(deceitMemo.length>200){
				alert("备注不能大于200个字符！");
				bool=false;
				return ;
			}
			if("99"==deceitType){
				deceitOthDesc=$("#deceitOthDesc").val();
				if(deceitOthDesc==""){
					alert("其他欺诈嫌疑描述不能为空！");
					bool=false;
					return ;
				}
				if(deceitOthDesc.length>200){
					alert("其他欺诈嫌疑描述不能大于200个字符！");
					bool=false;
					return ;
				}
			}
		});
		deceitReason="["+deceitReason.substring(0,deceitReason.length-1)+"]";
		jsonStr= '{"claimNo":"' + claimNo + '","estAmtList":' + estAmtList
			+ ',"deceitReason":' + deceitReason  +  ',"deceitOthDesc":"' 
			+ deceitOthDesc+ '","deceitMemo":"' + deceitMemo+'","plcPolicyInfoList":'+plcpolicyList+',"dpa":"'+dpa+'","tpa":"'+tpa+'"}';
		return bool;
	}
	
	
//	//	保存
//	function saveFiledCaseForm(){
//		$("#saveFiledCase").removeAttr("onclick");
//		getData();
//		if(bool){
//			$.ajax({
//				type:"POST",
//				contentType:"application/json; charset=UTF-8",
//				url:"requestSaveFiledCase.do",
//				data:jsonStr,
//				error :function(){
//					$("#saveFiledCase").attr("onclick","saveFiledCaseForm()");
//					alert("保存立案信息失败！");
//				},
//				success :function(data){
//					if(data){
//					alert("保存立案信息成功！");
//					}else{
//						alert("保存立案信息失败！");
//					}
//					$("#saveFiledCase").attr("onclick","saveFiledCaseForm()");
//				}
//			});
//		}
//	}
//	立案
	function submitFiledCase(){ 
		$("#submitFiledCase").attr("onclick","");
		//得到被保险人信息查询是否存在未结案的赔案
		var claimNo=$("#tblClmTaskInfo tr:eq(0)").find("td:eq(0)").text();
		var isQuest=$("#quest").attr("value");
		$.ajax({
			type:"POST",
//			contentType:"application/json; charset=UTF-8",
			url:"requestIsHaveFiledCase.do",
			data:{"claimNo":claimNo,"isQuest":isQuest},
			error :function(){
				alert("查询被保人是否已存在立案未结案的赔案失败！");
			},
			success :function(data){
				if(data.isHave == 'Y'){
					alert("该被保人 "+data.fClaimNo+" 赔案 "+data.cName+" 操作员正在 "+data.cState+" 中!需结案后,该赔案才能立案!");
				}else{
					if(getData()){
						if($("#tblPlcPolicyInfo tr").index()>0){
//							var lenInput=$("#tblPlcPolicyInfo tr:gt(0)").find("td:eq(4)").find("input").length;
							var readonlyBool=false;
							$("#tblPlcPolicyInfo tr:gt(0)").find("td:eq(4)").find("input").each(
									function (i){
										if($(this).attr("readonly")){
											readonlyBool=true;
										}else{
											readonlyBool=false;
											return ;
										}
									}
							);
							
							if(!readonlyBool &&  parseFloat(estAmtSum)<=0){
								alert("输入预估金额总和需大于0!");
								return ;
							}
//							if(confirm("预估金额为0，是否确认立案？")){
//							}else{
//								return ;
//							}
						}else{
							if($("#tblPlcPolicyInfo tr").index()<=0){
								alert("没有可用的保单信息，无法完成立案操作！");
								return ;
							}
							
						}
					}else{
						return ;
					}
					$("#submitFiledCase").removeAttr("onclick");
					$.ajax({
						type:"POST",
						contentType:"application/json; charset=UTF-8",
						url:"requestSubmitFiledCase.do",
						data:jsonStr,
						error :function(){
							$("#submitFiledCase").attr("onclick","submitFiledCase()");
							alert("立案失败！");
						},
						success :function(data){
							$("#submitFiledCase").attr("onclick","submitFiledCase()");
							if(eval(data.isBool)){
								alert("立案完成，待审核！");
								//alert(data.smsTemplate);
								if(!(($("#caseSource").val()=="2"||$("#caseSource").val()=="1")&&($("#isBpo").val()=="Y"))){
								//if($("#caseSource").val()!="2" && $("#caseSource").val()!="1"){
									$("#end1").html(data.smsTemplate[0]);
						        	$("#end2").html(data.smsTemplate[1]);
						        	$("#phoneno").html(data.smsTemplate[2]);
						        	var end1_html = $("#end1").html();
						        	if (end1_html != '') {
						        		end1_html = end1_html.replace("12312312312","<input type=\"text\" id=\"phone1\" name=\"phone1\" class=\"input input_bot_line i_s_100\" />");

						        	}
						        	$("#end1").html(end1_html);
						        	
						        	var end2_html = $("#end2").html();
						        	if (end2_html != '') {
						        		end2_html = end2_html.replace("尊敬的","尊敬的<input type=\"text\" id=\"yname\" name=\"yname\" class=\"input input_bot_line i_s_100\" />");
						        		end2_html = end2_html.replace("12312312312","<input type=\"text\" id=\"phone\" name=\"phone\" class=\"input input_bot_line i_s_100\" />");

						        	}
						        	$("#end2").html(end2_html);
						        	
						        	showSmsDivfn();
								}else{
									submitPageForm();
								}
							}else{
								//alert("立案失败！");
								alert(data.errMsg);
							}
						}
					});
				}
			}
		});
	}

	function showSmsDivfn(){
		showDiv('openMse');
	}
	
	function closeSmsDivfn(flag,claimNo){
		
		if('1'==flag){
			closeDiv('openMse');
			submitPageForm();
		}
		if('2'==flag){
		   var sms_clmPerson;
		   var sms_salesman;
		   if($('#clmPerson').attr('class')=="check_yes"){
			   sms_clmPerson = 1;

		   }else{
				sms_clmPerson = 0;
		   }
		   
		   if($('#salesman').attr('class')=="check_yes"){
			   sms_salesman = 1;
			  
		   }else{
				sms_salesman = 0;
		   }
		   var operator = $("#operator").val();
		   var yname = $("#yname").val();
		   var phone = $("#phone").val();
		   var phone1 = $("#phone1").val();
      		 if(sms_salesman=='1'){
      			 if(operator!=null && operator.length!=11){
	        			   alert("请输入11位手机号码");
	        			   return ;
	        		   }
      		 }
      		 
		   
		   $.ajax({
				type:"POST",
				url:"requestsendSms.do",
				data:{"claimNo":claimNo,"sms_clmPerson":sms_clmPerson,"sms_salesman":sms_salesman,"operator":operator,"yname":yname,"phone":phone,"phone1":phone1},
				error :function(){
					 alert("发送短信失败！");
					
				},
				success :function(data){
					if((sms_clmPerson=='1' && data[3]!=null) || (sms_clmPerson=='0'&&sms_salesman=='1' && data[3]!=null)||sms_clmPerson=='0'&&sms_salesman=='1' && data[4]!=null){
						
							 closeDiv('openMse');
			        		 alert("短信发送成功！");
			        		 $('#clmPerson').attr('class',"check_no");
			        		 $('#salesman').attr('class',"check_no");
			        		 $("#operator").val('');
						
			        				 
			        		 submitPageForm();
						
					}
					
				}
			
		});
		}
		if('3'==flag){
//			<!-- 内容start -->
//			<div class="open_mas_t txt_blue">
//		       <span id="checkedSms" class="check_no"></span>不予受理短信
//	        </div>
//			<div style="padding:10px;">
//				尊敬的<span id="pName">申请人</span>，您递交的被保险人<span id="bbrName">被保人</span>赔案（赔案号为<span id="noGrantClaimNo">赔案号</span>）的保险理赔已不予受理，
//				不予受理原因为<span id="reason">不予受理通知书上录入的不予受理原因</span>，您可登陆 
//				<a href="http://www.ecpic.com.cn/mall/policy/claims/view">http://www.ecpic.com.cn/mall/policy/claims/view</a>查询，或致电95500咨询。
//			<br/>
//			<br/>
//			<br/>
//				申请人手机号:<span id="pPhoneNo"></span>
			 if($('#checkedSms').attr('class')=="check_no"){
				 alert('请选择不予受理短信模板！');
				 return;
			 }
			 var pName=$("#pName").val();
			 var bbrName=$("#bbrName").val();
			 var claimNo=$("#noGrantClaimNo").val();
			 var reason=$("#reason").val();
			 var pPhoneNo=$("#pPhoneNo").val();
			 $.ajax({
					type:"POST",
					url:"requestsendSms.do",
					data:{"pName":pName,"bbrName":bbrName,"claimNo":claimNo,"reason":reason,"pPhoneNo":pPhoneNo},
					error :function(){
						 alert("发送短信失败！");
						
					},
					success :function(data){
						if((sms_clmPerson=='1' && data[3]!=null) || (sms_clmPerson=='0'&&sms_salesman=='1' && data[3]!=null)||sms_clmPerson=='0'&&sms_salesman=='1' && data[4]!=null){
							
								 closeDiv('openMse');
				        		 alert("短信发送成功！");
				        		 $('#clmPerson').attr('class',"check_no");
				        		 $('#salesman').attr('class',"check_no");
				        		 $("#operator").val('');
							
				        				 
				        		 submitPageForm();
							
						}
						
					}
				
			});
		}
	}
	
	function selectLiAnType(flag){
		
		$(flag).attr("value")=='1'?$(flag).val("0"):$(flag).val("1");
		
	}
	
	function skipTo(str){
		var params={};
		params['preno'] = str;
		SkipByPost("../../dataenter/checkgrant.do",params);
	}
	/**
	 * 跳转保单详情页面
	 * @param policyNo
	 * @param claimNo
	 * @param pid
	 * @param classcode
	 */
	function policyInfoquery(policyNo,claimNo,pid,classcode,policyInterSource,sGrpattr,familyFlag){
		policyInterSource=policyInterSource=="01"?"1":"2";
		SkipByPost("../../adjustmentGengduo/policyInfo.do",{sGrpattr:sGrpattr,policyNo:policyNo,claimNo:claimNo,pid:pid,classcode:classcode,policyInterSource:policyInterSource,familyFlag:familyFlag,pageFrom:"../claim/filedCase/requestFiledCase.do"});
	}
	
	
	/**
	 * 撤案//不予受理
	 */
	function revokedFiledCase(){
		var claimNo=$("#claim-no").val();
		
		
		if(confirm("是否确认不予受理？")){
			var isQuest=$("#quest").attr("value");
			$("#revokedFiledCase").removeAttr("onclick");
			$.ajax({
				type:"POST",
//				contentType:"application/json; charset=UTF-8",
				url:"requestRevokedFiledCase.do",
				data:{"claimNo":claimNo,"isQuest":isQuest},
				error :function(){
					$("#revokedFiledCase").attr("onclick","revokedFiledCase()");
					alert("不予受理失败！");
				},
				success :function(data){
					$("#revokedFiledCase").attr("onclick","revokedFiledCase()");
					if(eval(data.isBool)){
						alert("不予受理完成！");
						setDataRevokedFn(data.reMap);
						showDiv('notGrantOp');
					}else{
						alert(data.errMsg);
					}
				}
			});
			
		}
	}
	
	
	function queryCheckReason(claimNo){
		$.ajax({
			type:"POST",
			url:"queryCheckReason.do",
			data:{"claimNo":claimNo},
			error:function(){
				alert("查询转立案池原因失败！");
				return;
			},
			success:function(data){
				$("#checkReason").html('');
				
				if(data==null || data==""){				
					$("#checkReason").append("<tr><td colspan=\"7\">没有转立案池原因！</td></tr>");
				}else{
					for(var i= 0; i < data.length; i++){
						var h = data[i];
						$("#checkReason").append("<tr>" +
						"<td>"+h.qctreason+"</td></tr>");
					}
				}
			}
		});
	}
	function setDataRevokedFn(data){
		var insureName = data.insureName;
		var xzName = data.xzName;
		var policyno = data.policyno;
		var reportName = data.reportName;
		var idcard = data.idcard;
		var currentDate = data.currentDate;
		var branchName = data.branchName;
		var clmAccAndReportType = data.clmAccAndReportType;
		$("#notGrantOp").find("#claimNo").html(data.claimNo);
		$("#notGrantOp").find("#policyno").html(policyno);
		$("#notGrantOp").find("#insureName").html(insureName);
		$("#notGrantOp").find("#reportName").html(reportName);
		$("#notGrantOp").find("#idcard").html(idcard);
		$("#notGrantOp").find("#currentDate").val(currentDate);
		//$("#notGrantOp").find("#clmAccAndReportType").html(clmAccAndReportType);
		$("#notGrantOp").find("#clmAccAndReportType").html(xzName);
		$("#notGrantOp").find("#branchName").html(branchName);
		//REQHOP1-161014-1427 理赔通知书优化 lujibin 20161226 
		$("#notGrantOp").find("#name1").val(data.appName);
		$("#notGrantOp").find("#cNo1").val(data.claimNo);
		$("#notGrantOp").find("#cDate1").val(data.applyDate);
		$("#notGrantOp").find("#iName1").val(insureName);
		$("#notGrantOp").find("#pid1").val(idcard);
		$("#notGrantOp").find("#iName2").val(insureName);
		$("#notGrantOp").find("#pid2").val(idcard);
		$("#notGrantOp").find("#p0000001InfoTel").val(data.p0000001InfoTel);
		//REQHOP1-161014-1427 理赔通知书优化 lujibin 20161226 
	}
	/**不予受理通知书打印*/
	function printBYCL(){
		var param={};
		var appName=$("#notGrantOp").find("#name1").val();
		var claimNo = $("#notGrantOp").find("#cNo1").val();
		var policyno = $("#notGrantOp").find("#policyno").html();
		var insureName = $("#notGrantOp").find("#insureName").html();
		var reportName = $("#notGrantOp").find("#reportName").html();
		var idcard = $("#notGrantOp").find("#idcard").html();
		var reason =$("#notGrantOp").find("#reason").val();
		var currentDate = $("#notGrantOp").find("#currentDate").val();
		var clmAccAndReportType = $("#notGrantOp").find("#clmAccAndReportType").html();
		var branchName = $("#notGrantOp").find("#branchName").html();
		

		param['appName']=appName;
		param['claimNo']=claimNo;
		param['idcard']=idcard;
		param['insureName']=insureName;
		param['currentDate']=currentDate;
		param['policyno']=policyno;
		param['reason'] = reason;
		param['reportName'] = reportName;
		param['clmAccAndReportType'] = clmAccAndReportType;
		param['branchName'] = branchName;
		param['infoTel']=$("#p0000001InfoTel").val();
		$.ajax({
			 type: "POST", 
		     url: "../../claim/notification/printBYSL.do",
		     data:param,
		     async : false,
		     success:function(data){
		    	 if(data =='0000000'){
		    		 alert("操作成功");
		    		 closeDiv('notGrantOp');
//		    		 showDiv('noGrantDiv');
		    		 submitPageForm();
		    	 }else{
		    		 alert("操作失败");
		    	 }
		     },
		     error:function(data){
		    	alert("操作失败") ;
		     }
		});
	}