//删除行
function del(e){
	$(e).parent().parent("tr").remove();
	
}
//生成对账单
function genBills(){
	var nos="";
	$("#context").find("tr").each(function(){
		var claimNo = $(this).find("td:eq(1)").html();
		if(claimNo !='' && claimNo !=null && claimNo !=undefined){
			nos+=claimNo+",";
		}
	});
	if(nos ==''){
		alert("没有对账单数据");
		return;
	}
	nos = nos.substring(0,nos.length-1);
	
	$.ajax({
		type:"POST",
		url:"genBillNo.do",
		data:{"claimNos":nos},
		error:function(){
			alert("生成对账单号失败");
		},
		success:function(data){
			if(data.m=="success"){
				$("#bill-no").html(data.billNo);
				alert("生成对账单号成功"+data.billNo);
				$("#export-button").attr("style","");
				$("#export-button").attr("onclick","exportExcel()");
				$("#send-email").attr("style","");
				$("#send-email").attr("onclick","alert('发送邮件功能暂不可用')");
				$("#gen-button").attr("onclick","");
				$("#gen-button").attr("style","color: rgb(204, 204, 204)");
			}
		}
	});
	
}

function exportExcel(){
	
	var orgName = $("#orgName").html();
	var partnerType = $("#partnerType").attr("code");
	var accountName = $("#accountName").html();
	var bankNumber = $("#bankNumber").html();
	var paymentNo = $("#paymentNo").html();
	
	var str = "";
	$("#context").find("tr").each(function(){
		var batchNo = $(this).find("td:eq(0)").html();
		var claimNo = $(this).find("td:eq(1)").html();
		var claimStatus = $(this).find("td:eq(2)").html();
		var paymentStatus = $(this).find("td:eq(3)").html();
		var caseSource = $(this).find("td:eq(4)").html();
		var visitDate = $(this).find("td:eq(5)").html();
		var name = $(this).find("td:eq(6)").html();
		var billAmt = $(this).find("td:eq(7)").html();
		var deductionsAmt = $(this).find("td:eq(8)").html();
		var payAmt = $(this).find("td:eq(9)").html();
		var denyingAmt = $(this).find("td:eq(10)").html();
		var denyingReason = $(this).find("td:eq(11)").html();
		var seqNo = $(this).find("td:eq(12)").html();
		
		str+='{"batchNo":"'+batchNo+'","claimNo":"'+claimNo+'","claimStatus":"'+claimStatus+'","paymentStatus":"'+paymentStatus+'",'
		     +'"caseSource":"'+caseSource+'","visitDate":"'+visitDate+'","name":"'+name+'",'
		     +'"billAmt":"'+billAmt+'","deductionsAmt":"'+deductionsAmt+'","payAmt":"'+payAmt+'",'
		     +'"denyingAmt":"'+denyingAmt+'","denyingReason":"'+denyingReason+'","seqNo":"'+seqNo+'"},';
	});
	
	if(str==""){
		alert("没有对账单");
		return;
	}
	str="["+str.substring(0,str.length-1)+"]";
	SkipByPost("exportExcel.do",{str:str,orgName:orgName,partnerType:partnerType,
		accountName:accountName,bankNumber:bankNumber,paymentNo:paymentNo});
}