$(function() {
	$("#content").hide();//隐藏上面的输入框
});
var stch=false;//防止重点
function initInsure(){
	$("#stype").val("1");//默认为被保险人身份证号查询
}
function insureSelectChange(val){
	$("#paper").val("");
	$("#content").val("");
	var estimate= true;
	if(val=="2"){
		divCustomInfo.style.display="block";//选怪姓+名+性别+出生日期
		divCusInfo.style.display="none";
		estimate = false;
		$("#content").hide();//隐藏上面的输入框
	}else{
		$("#content").val("");
		$("#content").show();
		divCustomInfo.style.display="none";
		divCusInfo.style.display="none";
	}
	if(val=="1"&&estimate){
		divCustomInfo.style.display="none";
		divCusInfo.style.display="block";//选怪姓+名+性别+出生日期
		$("#content").hide();//隐藏上面的输入框
	}
	$("#stype").val(val);//默认为被保险人身份证号查询
}
function sexSelectChange(val){
	$("#sex").val(val);//性别
}

function checkInsure(){
	//姓名+性别+出生日期查询类型为2，如果不为2时需要校验查询内容content
	if($("#stype").val()=="3"){ 
		if($("#content").val()==null || $("#content").val()==""){
			alert("查询内容不能为空！");
			return false;
		}
	}
	getCityBypro();
	
	
}

function getCityBypro(){ 
	
	if ($("#stype").val() == '1') {
		if ($("#certificates").val() == "") {
			alert("请选择证件类型");
			return false;
		}
	}
	var channelType = $("#channelType").val();
	if ($("#stype").val() == '1') {
		if($("#certificates").val()=='a'){
			if($("#paper").val().length!=15 && $("#paper").val().length!=18){
				alert("身份证长度必须为15位或18位");
				return false;
			}
		}else {
			if($("#paper").val()==""){
				alert("被保人证件号不能为空");
				return false;
			}
		}
			}
	if(channelType!='2'&&$("#stype").val()=='3'){
		if($("#content").val().length!=15){
			alert("保单号长度必须为15位");
			return false;
		}
	}
	if($("#stype").val()=='2'){
		if($("#sername").val()==null || $("#sername").val()==""){
			alert("姓不能为空");
			return false;
		}
		if($("#name").val()==null || $("#name").val()==""){
			alert("名不能为空");
			return false;
		}
		if($("#sex").val()==null || $("#sex").val()==""){
			alert("性别不能为空");
			return false;
		}
		if($("#birthday").val()==null || $("#birthday").val()==""){
			alert("生日不能为空");
			return false;
		}
	}
	
	
	showDiv('open1');
	$("#insureData").html("");
    $.ajax({  
        type: "POST",  
        async: false, 
        url: "queryInsurce.do",  
        data: {stype:$("#stype").val(),content:$("#content").val(),sername:$("#sername").val(),name:$("#name").val(),sex:$("#sex").val(),birthday:$("#birthday").val(),channelType:channelType,paper:$("#paper").val(),certificates:$("#certificates").val()},  
        success: function(data){  
        	if(data.errorMsg!=null && data.errorMsg!=""){
        		$("#insureData").append("<tr><td>查询不到相关内容，请检查查询条件</td></tr>");
        	}else if(data.insureList==null || data.insureList==null){
        		$("#insureData").append("<tr><td>查询不到相关内容，请检查查询条件</td></tr>");
        	}else{
        		var items = data.insureList;  
                
                $.each(items, function(i, n){
                 	$("#insureData").append("<tr  style=\"cursor: pointer;\" onclick=\"dbclickForword('"+items[i].pid+"','"+items[i].idtype+"',this)\"><input type='hidden' id='cxPid' value='"+items[i].pid+"' /><td width=\"23%\">"+items[i].name+"</td><td  width=\"45%\">"+items[i].pid+"</td><td width=\"21%\">"+items[i].sexName+"</td></tr>");
                });  
        	}
            
        }  
    });   
} 

//查询保单列表和历史赔付
function dbclickForword(pid,idtype,value){
	closeDiv('open1');
	$("#spid").val(pid);
	$("#sIdtype").val(idtype);
	$("#hiddenPid").val(pid);
	$("#policyList").html("");
	$("#historylist").html("");
	var channelType = $("#channelType").val();
    $.ajax({  
        type: "POST",  
        async: false, 
        url: "querypolicylist.do", 
        data: {pid:pid,idtype:idtype,channelType:channelType},  
        success: function(data){
        	
        	if(data.insurePolicylist==null || data.insurePolicylist==""){
        		$("#policyList").append("<tr><td colspan=\"7\">查询不到相关内容，请检查查询条件</td></tr>");
        	}
        	
        	for(var i = 0;i<data.insurePolicylist.length;i++){
        		var n = data.insurePolicylist[i];
        		if(n.familyFlag=='1'){
        			$("#policyList").append("<tr><input type='hidden' id='tbrName' value='"+n.tbrName+"' /><td  onclick=\"payinfo('"+n.policyNo+"','"+n.classcode+"','"+n.sPid+"','"+n.policyInterSource+"','"+n.policySource+"','"+n.branchid+"','"+n.sGrpattr+"','1')\" style=\"cursor: pointer;\"  >"+n.policyNo+"<b class=\"sild_icon_sz\">家</b></td><td>"+n.xzmc+"</td><td>"+n.bdqj+"</td><td>"+isNull(n.policyState)+"</td><td>"+isNull(n.policySource)+"</td><td>"+n.tbrName+"</td><td>"+isNull(n.insureRelation)+"</td></tr>");          	
        		}else{
        			$("#policyList").append("<tr><input type='hidden' id='tbrName' value='"+n.tbrName+"' /><td  onclick=\"payinfo('"+n.policyNo+"','"+n.classcode+"','"+n.sPid+"','"+n.policyInterSource+"','"+n.policySource+"','"+n.branchid+"','"+n.sGrpattr+"','0')\" style=\"cursor: pointer;\"  >"+n.policyNo+"</td><td>"+n.xzmc+"</td><td>"+n.bdqj+"</td><td>"+isNull(n.policyState)+"</td><td>"+isNull(n.policySource)+"</td><td>"+n.tbrName+"</td><td>"+isNull(n.insureRelation)+"</td></tr>");
        		}
        	}
        	
        	
        	if(data.historylist==null || data.historylist==""){
        		$("#historylist").append("<tr><td colspan=\"10\">查询不到相关内容，请检查查询条件</td></tr>");
        	}
        	for(var i = 0;i<data.historylist.length;i++){
        		var n = data.historylist[i];
        		$("#historylist").append("<tr><td  onclick=\"claimdetail('"+n.claimNo+"')\" style=\"cursor: pointer;\"  >"+n.claimNo+"</td><td>"+isNull(n.accidentDate)+"</td><td>"+isNull(n.auditor)+"</td><td>"+isNull(n.claimAmt)+"</td><td>"+isNull(n.claimPayAmtTotal)+"</td><td>"+isNull(n.regDate)+"</td><td>"+isNull(n.endDate)+"</td><td>"+isNull(n.claimState)+"</td><td>"+isNull(n.claimSource)+"</td><td>"+isNull(n.dpa)+"</td></tr>");
        	}
        	
        }  
    });   
}

//勾选健康险寿险
function querylist(channelType){
	//var channelType = $("#channelType").val();

	var pid = $("#spid").val();
	var idtype = $("#sIdtype").val();
	if($("#stype").val()=='1'){
		$("#content").val(pid);
	}
	
	$("#policyList").html("");
	$("#historylist").html("");
	if(pid==""||pid==null){
		$("#policyList").html("");
		$("#historylist").html("");
		$("#channelType").val(channelType);
	}else{
		$.ajax({  
	        type: "POST",  
	        async: false, 
	        url: "querypolicylist.do", 
	        data: {pid:pid,idtype:idtype,channelType:channelType},  
	        success: function(data){
	        	//var itemsEval=eval(data);
	        	
	        	if(data.insurePolicylist==null || data.insurePolicylist==""){
	        		$("#policyList").append("<tr><td colspan=\"7\">查询不到相关内容，请检查查询条件</td></tr>");
	        	}
	        	
	        	for(var i = 0;i<data.insurePolicylist.length;i++){
	        		var n = data.insurePolicylist[i];
	        		$("#policyList").append("<tr><input type=\"hidden\" id=\"tbrName\" value=\"n.tbrName\" /><td  onclick=\"payinfo('"+n.policyNo+"','"+n.classcode+"','"+n.sPid+"','"+n.policyInterSource+"','"+n.branchid+"',,'"+n.sGrpattr+"')\" style=\"cursor: pointer;\"  >"+n.policyNo+"</td><td>"+n.xzmc+"</td><td>"+n.bdqj+"</td><td>"+isNull(n.policyState)+"</td><td>"+isNull(n.policySource)+"</td><td>"+n.tbrName+"</td><td>"+isNull(n.insureRelation)+"</td></tr>");
	        		
	        	}
	        	
	        	if(data.historylist==null || data.historylist==""){
	        		$("#historylist").append("<tr><td colspan=\"10\">查询不到相关内容，请检查查询条件</td></tr>");
	        	}
	        	for(var i = 0;i<data.historylist.length;i++){
	        		var n = data.historylist[i];
	        		$("#historylist").append("<tr><td  onclick=\"claimdetail('"+n.claimNo+"')\" style=\"cursor: pointer;\"  >"+n.claimNo+"</td><td>"+isNull(n.accidentDate)+"</td><td>"+isNull(n.auditor)+"</td><td>"+isNull(n.claimAmt)+"</td><td>"+isNull(n.claimPayAmtTotal)+"</td><td>"+isNull(n.regDate)+"</td><td>"+isNull(n.endDate)+"</td><td>"+isNull(n.claimState)+"</td><td>"+isNull(n.claimSource)+"</td><td>"+isNull(n.dpa)+"</td></tr>");
	        	}
	        	
	        }  
	    });
	}
    
}



//单选

$(".radio_yes,.radio_no").click(function(){ 
	  
	  if($(this).is(".radio_yes")){
		$(this).removeClass("radio_yes");
		$(this).addClass("radio_no"); 
	  } else{
			var obj=  $(".radio_yes");
			obj.removeClass("radio_yes");          
			obj.addClass("radio_no"); 
			$(this).removeClass("radio_no");
	        $(this).addClass("radio_yes");
	        //$("#channelType").val($(this).attr("channelValue"));
	}
});

//保单详情
function payinfo(policyNo,classcode,sPid,policyInterSource,policySource,branchid,sGrpattr,familyFlag){
	var sIdtype = $("#sIdtype").val();
	var searchType = $("#stype").val();
	var searchContent = $("#searchContent").val();
	var searchSername = $("#sername").val();
	var searchName = $("#name").val();
	var searchSex = $("#sex").val();
	var searchBirthday = $("#birthday").val();
    var channelType = $("#channelType").val();
    var pid;
    if(channelType=='2'){
    	 if($("#cxPid").val()!=null||$("#cxPid").val()!=undefined){
    		 pid = $("#cxPid").val();
    	  }else{
    		 pid = $("#cxpid").val();	
    	  }
    }else{
    	pid = sPid;
    }
    
	
	SkipByPost("querypolicyinfo.do",{policyNo:policyNo,classcode:classcode,sPid:pid,policyInterSource:policyInterSource,searchType:searchType,searchContent:searchContent,searchSername:searchSername,searchName:searchName,searchSex:searchSex,searchBirthday:searchBirthday,channelType:channelType,policySource:policySource,branchid:branchid,sGrpattr:sGrpattr,sIdtype:sIdtype,familyFlag:familyFlag});
}

//回车查询
function enterQuery(){
	 var event = window.event||arguments.callee.caller.arguments[0];
	 if(event.keyCode==13){
		 checkInsure();
	 }
}

function isNull(a){
	
	if(a==null){
		return "";
	}else{
		return a;
	}
	
	
}
function gohistory(){
	var params={};
	params['channelType']=$("#channelType").val();
	params['pid']=$("#pid").val();
	params['sIdtype']=$("#sIdtype").val();
	SkipByPost("policyreturn.do",params);
}



function claimdetail(no){
	var channelType = $("#channelType").val();
	var searchPid = $("#spid").val();	
	
	SkipByPost("clmtaskdetailQuery.do",{claimNo:no,searchPid:searchPid,channelType:channelType});
}

function goback(){
	var params={};
	params['channelType']=$("#channelType").val();
	params['pid']=$("#searchPid").val();
	SkipByPost("policyreturn.do",params);
}



function returnTaskPool(){
	SkipByPost("taskpoolQuery.do");
}
//进入录入页面
function goRecord(){
	var certificates = $("#sIdtype").val();//证件类型
	var pid = $("#spid").val();
	var channelType = $("#channelType").val();
	var tbrname = $("#tbrName").val();
	SkipByPost("infoEntryInit.do",{pid:pid,certificates:certificates,channelType:channelType,tbrname:tbrname});
}

function openImage(sModino,cxBranchid){//sModino批单号
	var branchid = $("#branchid").val();
	   //获取当前网址
    var curWwwPath = window.document.location.href;
    //获取主机地址之后的目录
    var pathName = window.document.location.pathname;
    var pos = curWwwPath.indexOf(pathName);
    //获取主机地址
    var localhostPath = curWwwPath.substring(0, pos);
    
    var channelType = $("#channelType").val(); 
    
    if(channelType=='2'){
    	//产险
    	callpdEcm(sModino,cxBranchid,"3");
	}else{
	//健康险寿险保全影像
		window.open(localhostPath+'/claimserver/inspection/clmtask/imageInfo.do?claimNo='+sModino+'&flag=3&branchid='+branchid+'',"保全影像");
	}
	
}



function callpdEcm(pdh,unitcode,queryType){
	$.ajax({
		type:"POST",
		url:getRootPath()+"/ecm/ecmquery.do",
		data:{"claimNo":pdh,"unitcode":unitcode,"queryType":queryType},
		error :function(){
			alert("调用产险新影像服务失败！");
			return ;
		},
		success :function(data){
			url=data.url;
			var params={};
			params["format"]=data.format;
			params["code"]=data.code;
//			  params["xml"]="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><root><BASE_DATA><USER_CODE>999</USER_CODE><USER_NAME>super</USER_NAME><USER_ORG_CODE>3010100</USER_ORG_CODE><USER_SUBORG_CODE>3010100</USER_SUBORG_CODE><ORG_CODE>3010100</ORG_CODE><COM_CODE>3010100</COM_CODE><ORG_NAME>上海分公司</ORG_NAME><ROLE_CODE>RYX_JYCL</ROLE_CODE><SECURITY_INFO><SYSTEM_ID>27</SYSTEM_ID><STR_TXT>kg63kau7gm</STR_TXT><STR_MTXT>b3f5b8410ac9c37efe59eefb671e1471</STR_MTXT></SECURITY_INFO></BASE_DATA><META_DATA><BATCH><APP_CODE>CL_RYX</APP_CODE><APP_NAME>人意险理赔</APP_NAME><ORG_CODE>3010100</ORG_CODE><BUSI_NO>ESHH0102014000159</BUSI_NO><INS_TYPE></INS_TYPE><SYSTEM_ID>27</SYSTEM_ID><CLASSIFY_LIMIT></CLASSIFY_LIMIT><OPERAT_TYPE></OPERAT_TYPE></BATCH></META_DATA></root>";
			params["xml"]=data.xml;
			//alert(data.xml);
			openNewByPost(url,params);
		}
	});
}

function certificate(val){
	$("#paper").val("");
	$("#certificates").val(val);
}