123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- var locat = (window.location+'').split('/');
- $(function(){if('fhsms'== locat[3]){locat = locat[0]+'//'+locat[2];}else{locat = locat[0]+'//'+locat[2]+'/'+locat[3];};});
- $(getTop(globalThis).hangge());
- var pd_TABLETYPE = $('#pd_TABLETYPE').html();
- var subtable = $('#subtable').html();
- var pd_COMPANY = $("#pd_COMPANY").html();
- var pd_COMPANY_ID = $("#pd_COMPANY_ID").html();
- var pd_YEAR = $("#pd_YEAR").html();
- var pd_mode = $("#pd_mode").html();
- var editflag = 0;
- var validateJsonData = new Object();
- function tableInit(){
- //最后的汇总
- $('#simple-table tbody .edittr').each(function(index,e){
- //行内总计
- setRowSumCell(e);
- //百分比初始化
- setTrPercentCell(e);
- });
-
-
- //各个小计行
- var subtotal = $('.subtotal').find('td[totalType="subtotal"]');
- for(var i=0; i<subtotal.length; i++){
- var companyid = subtotal.eq(i).parent().attr("id");
- var var1=subtotal.eq(i).attr("class");
- var var2=var1.split(' ');
- var classname = var2[1];
- setSubTotalCell(companyid,classname,i);
-
- }
-
- //数字格式化
- $('td.num').each(function(index,e){
- var num = $(e).html();
- num = numFormat(num);
- $(e).html(num);
- });
- //小计行的汇总
- $('#simple-table tbody .subtotal').each(function(index,e){
- setRowSumCell2(e);
- //小计行百分比初始化(实际/审核费用)
- setTrPercentCell(e);
- });
- //最下面的累计值
- var totalcells = $('.totaltr').find('.sumCell');
- for(var i=0; i<totalcells.length; i++){
- setTotalCell(i);
- }
- $('#simple-table tbody .totaltr').each(function(index,e){
- //汇总行百分比初始化(实际/审核费用)
- setTrPercentCell1(e);
- });
-
- }
- //累计 = 所有小计的和 totalType='subtotal'(实际上计算应该是计算的totalType='sum')
- function setTotalCell(index){
- if(index < $('.totaltr').find('.sumCell').length){//28
- var totalvalue = 0;
- for(var i=0; i<$('.edittr').length; i++){
- var editcellval;
- if($('.edittr').eq(i).find('[totalType="sum"]')[index].tagName == "SPAN"){
- editcellval = $('.edittr').eq(i).find('[totalType="sum"]').eq(index).html();
- }else{
- editcellval = $('.edittr').eq(i).find('td[totalType="sum"]').eq(index).html();
- }
- if(typeof(editcellval) != "undefined")
- totalvalue += Number(editcellval);
- }
- if(totalvalue != 0){
- $('.totaltr').find('.sumCell').eq(index).html(numFormat(totalvalue) + '');
- }
- }
- }
- //小计=上面所有totalType='sum' 的td的和
- function setSubTotalCell(companyid,classname,index){
- var totalvalue = 0;
- for(var i=0; i<$('.edittr.'+companyid +' .'+classname).length; i++){
- var subcellval;
-
- if($('.edittr.'+companyid +' .'+classname).eq(i).find("INPUT").length > 0){
- subcellval = $('.edittr.'+companyid +' .'+classname).eq(i).val();
- }else{
- subcellval = $('.edittr.'+companyid +' .'+classname).eq(i).html();
- }
- if(typeof(subcellval) != "undefined")
- totalvalue += Number(subcellval);
- }
- if(totalvalue != 0){
- $('.subtotal').find('td[totalType="subtotal"]').eq(index).html(numFormat(totalvalue) + '');
- }
- }
- //计算整行的总和
- function setRowSumCell(tr){
- $(tr).find(".rowSumCell").each(function(index,e){
- var totalvalue = 0;
- var sumtype = $(e).attr('class').split(' ')[2] + '_';
- for(var i=1; i<13; i++){
- var editcellval = $(tr).find("."+sumtype+i).html();
- if(typeof(editcellval) != "undefined"){
- totalvalue += Number(editcellval);
- }
- }
- $(e).html(numFormat(totalvalue) + '');
- });
- }
- //小计这一行的计算
- function setRowSumCell2(tr){
- $(tr).find(".rowSumCell").each(function(index,e){
- var totalvalue = 0;
- var sumtype = $(e).attr('class').split(' ')[2] + '_';
- for(var i=1; i<13; i++){
- var editcellval = $(tr).find("."+sumtype+i).html();
- if(typeof(editcellval) != "undefined"){
- totalvalue += Number(editcellval);
- }
- }
- $(e).html(numFormat(totalvalue) + '');
- });
- }
- //计算百分比
- function setTrPercentCell(tr){
- $(tr).find("td.percentCell").each(function(index,e){
- var num1 = $(tr).find("td."+$(e).attr("num1")).html();
- var num2 = $(tr).find("td."+$(e).attr("num2")).html();
-
- var result = percentage(num1, num2);
- $(e).html(result);
- });
- }
- //累计计算百分比
- function setTrPercentCell1(tr){
- $(tr).find("td>.percentCell").each(function(index,e){
- var num1,num2;
- if($(tr).find("td>."+$(e).attr("num1"))[0].tagName == "INPUT"){
- num1 = $(tr).find("td>."+$(e).attr("num1")).val();
- }else if($(tr).find("td>."+$(e).attr("num1"))[0].tagName == "SPAN"){
- num1 = $(tr).find("td>."+$(e).attr("num1")).html();
- }
- if($(tr).find("td>."+$(e).attr("num2"))[0].tagName == "INPUT"){
- num2 = $(tr).find("td>."+$(e).attr("num2")).val();
- }else if($(tr).find("td>."+$(e).attr("num2"))[0].tagName == "SPAN"){
- num2 = $(tr).find("td>."+$(e).attr("num2")).html();
- }
- var result = percentage(num1, num2);
- if(e.tagName == "INPUT") $(e).val(result);
- else if(e.tagName == "SPAN") $(e).html(result);
- });
- }
- function percentage(num1, num2){
- var percent = "";
- if(!isNaN(Number(num1)) && !isNaN(Number(num2)) && Number(num2) != "0" )
- // percent = Math.round(Number(num1) / Number(num2) * 10000) / 100.00 + "%";
- percent = Math.round(Number(num1) / Number(num2) * 100);
- return percent;
- }
- //数字格式化
- function numFormat(num){
- if(!isNaN(Number(num)) && Number(num) != "0"){
- if(num<10) num = Number(num).toFixed(1);
- else num = Math.round(Number(num));
- }
- return num;
- }
- $(function(){
- tableInit();
- });
|