var hospitalName = null;
function query() {
	$("#contexts").html("");
	hospitalName = $("#hospitalName").val();
	if (hospitalName == "") {
		alert("医院名不能为空");
		return;
	}
	$.ajax({
		type : "POST",
		url : "/claimserver/batchOperation/queryHospital.do",
		data : {
			"hospitalName" : hospitalName,
			"hospitalType" : hospitalType
		},
		error : function() {
			alert("查询数据失败，请稍后重试！");
		},
		success : function(data) {
			if (data == "") {
				alert("无返回数据");
			}
			for ( var i = 0; i < data.length; i++) {
				$("#contexts").append(
						"<tr nid=\"" + data[i].objid
								+ "\"  onclick=\"choosEd(this)\" id="

								+ "><td>" + data[i].partnerName + "</td><td>"
								+ data[i].partnerAddr + "</td><td>"
								+ data[i].partnerType + "</td><td>"
								+ data[i].contactPerson + "</td><td>"
								+ data[i].contactPhone + "</td><td>"
								+ data[i].bankAccountName + "</td><td>"
								+ data[i].bankName + "</td><td>"
								+ data[i].bankAccountNo + "</td></tr>");
			}

		}

	});
}

var TPAName = null;
function queryTPA() {
	$("#contextInfo").html("");
	TPAName = $("#TPAName").val();
	if (TPAName == "") {
		alert("TPA名不能空");
		return;
	}
	$.ajax({
		type : "POST",
		url : "/claimserver/batchOperation/queryHospital.do",
		data : {
			"TPAName" : TPAName,
			"hospitalType" : hospitalType

		},
		error : function() {
			alert("查询数据失败，请稍后重试！");
		},

		success : function(data) {
			if (data == "") {
				alert("无返回数据");
			}
			for ( var i = 0; i < data.length; i++) {
				$("#contextInfo").append(
						"<tr nid=\"" + data[i].objid
								+ "\"  onclick=\"choosEd(this)\"><td>"
								+ data[i].partnerName + "</td><td>"
								+ data[i].partnerAddr + "</td><td>"
								+ data[i].contactPerson + "</td><td>"
								+ data[i].contactPhone + "</td><td>"
								+ data[i].bankAccountName + "</td><td>"
								+ data[i].bankName + "</td><td>"+data[i].bankAccountNo+"</td></tr>");
			}
		}
	});
}
var id = null;
var hospitalType = null;
function select(object) {
	$("#contexts").html("");
	$("#contextInfo").html("");
	$("#hospitalName").val("");
	 $("#TPAName").val("");
	hospitalType = object;
	if (hospitalType == "01" ) {
		oid = "";
		$("#sh5").html("医院名称:");
		$("#sh6")
				.html(
						"<input type='text' id=\"hsName\" class='input i_s_240' onclick=\"showDiv('open0')\"/>");
	}
	if (hospitalType == "02") {
		oid = "";
		$("#sh5").html("TPA名称  : ");
		$("#sh6")
				.html(
						"<input type='text' id=\"hsName\" class='input i_s_240'onclick=\"showDiv('open1')\"/>");
	}
}
var oid = "";
var hsName = "";
function choosEd(obj) {
	$("#obj").html();
	var tds = obj.childNodes;
	oid = $(obj).attr("nid");
	hsName = tds[0].innerHTML;
	$(obj).css("background-color", "#e5e5e5").siblings().css(
			"background-color", "#FFFFFF");
	index = $(obj).index();
}

function querys() {
	$("#cts").html("");
	$("#cts1").html("");
	$("#contexts").html("");
	$("#contextInfo").html("");
	$("#hospitalName").val("");
	 $("#TPAName").val("");
	$("#hospitalName").html("");
	$("#TPAName").html("");
	var firstDate = $("#firstDate").val();
	var lastDate = $("#lastDate").val();
	var fd=firstDate.split("-");
	var ld=lastDate.split("-");
	$("#endDateCondation").val(fd[0]+"/"+fd[1]+"/"+fd[2] + "-" +ld[0]+"/"+ld[1]+"/"+ld[2]);
	var name = hospitalName;
	var num = oid;
	var TPAame = TPAName;
	if (firstDate == null||firstDate == ""  ||lastDate == null||lastDate == "") {
		alert("开始日期和结束日期没有填写完整！");
		return;
	}
	if(firstDate>lastDate){
		alert("请勿开始日期大于结束日期");
		return;
	}
	var fds1=firstDate.split("-");
	var fds2=lastDate.split("-");
	var year = fds2[0]-fds1[0];
	var month = fds2[1]-fds1[1];
	var day = fds2[2]-fds1[2];
	if(year>1){
		alert("时间必须在一年之内");
		return;
	}else if (year==1) {
		if(month>0){
			alert("时间必须在一年之内");
			return;
		}else if (month==0) {
			if(day>0){
				alert("时间必须在一年之内");
				return;
			}
		}
		
	}

	$
			.ajax({
				type : "POST",
				url : "/claimserver/batchOperation/queryClaimData.do",
				data : {
					"hospitalName" : name,
					"hospitalType" : hospitalType,
					"TPAName" : TPAame,
					"firstDate" : firstDate,
					"lastDate" : lastDate,
					"oid" : num

				},
				error : function() {
					alert("查询数据失败！");
				},
				success : function(data) {
					if (data == "") {
						alert("没有数据返回");
					}
					for ( var i = 0; i < data.length; i++) {
						$("#cts").html();
						$("#cts")
								.append(
										" <tr>" + "<td>"
												+ data[i].gathering
												+ "<input type='hidden' name='claimNo' value='"
												+ data[i].claimNo
												+ "'></td>"
												+ "<td>"
												+ data[i].hospital
												+ "<input type='hidden' name='parterId' value='"
												+ data[i].parterId
												+ "'></td>"
												+ "<td>"
												+ data[i].claimNo
												+ "</td>"
												+ "<td>"
												+ data[i].accept
												+ "</td>"
												+ "<td>"
												+ data[i].name
												+ "</td>"
												+ "<td>"
												+ data[i].bills	+ "<input type='hidden' name='bills' value='"+data[i].bills+"'/>"
												+ "</td>"
												+ "<td>"
												+ data[i].claims+ "<input type='hidden' name='claims' value='"+data[i].claims+"'/>"
												+ "</td>"
												+ "<td><a href='#' class='icon_del' id='del_"+i+"' onclick=\"deleteData(this);\"></a></td></tr>");
					}
			
					var most=0;
					var most1=0;
					for( var i = 0; i < data.length; i++){
						most=most+data[i].bills;
						most1=most1+data[i].claims;
					}
					if(most!=0||most!=0){
						$("#cts1").html("");
						$("#cts1").val("");
						$("#cts1").html(
							"<tr><td>累计</td><td></td><td></td><td></td><td></td><td id='most'>"+most+"</td><td id='most1'>"+most1+"</td></tr>"	
						
						);	
					}
						
				}

			});

}
function deleteData(obj) {
	var ok=confirm("是否确定删除？");
	if(ok){
		obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
	}
	var doc=document.getElementsByName("bills");
	var doc1=document.getElementsByName("claims");
	var bmostsss=new Number(0);
	var bmostsss1=new Number(0);
	for( var i = 0; i < doc.length; i++){
		mostsss=new Number(doc[i].value);
		mostsss1=new Number(doc1[i].value);
		bmostsss=mostsss+bmostsss;
		bmostsss1=mostsss1+bmostsss1;
	}
	$("#most").html("");
	$("#most").html(bmostsss);
	$("#most1").html("");
	$("#most1").html(bmostsss1);
}

function change(sel) {
	$("#cts1").html("");
	$("#cts").html("");
	$("#createMethod").val();
	if (sel == "01") {
		$("#sh1").show();
		$("#sh2").show();
		$("#sh3").html("&nbsp;");
		$("#sh4").html("&nbsp;");
		$("#createMethod").val(sel);
		
	}
	if (sel == "02") {
		
		$("#sh3").html("<span class='txt_red'>*</span>赔案号：");
		$("#sh4")
				.html(
						"<input id=\"claimNoInput\" type='text' class='input i_s_240'/><a href='#' class='icon_add' onclick=\"queryByClaimNo();\"></a>");
		$("#sh1").hide();
		$("#sh2").hide();
		$("#createMethod").val(sel);
	
	}
	
}
function confirms() {
	$("#hsName").html();
	$("#hsName").val(hsName);
	closeDiv('open0');
	closeDiv('open1');

}

