123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606 |
- 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 editflag = 0;
- var recordData = new Object();
- var recordBeforeValue = new Object();
- $(function(){
- tableInit();
- //highlightInit();
- });
- function tableInit(){
- //行内小计列
- //setRowSumCell(e);
- //预防、修复小中大修分别计算总和
- $('.threeNum').each(function(index,e){
- setPreTotalCell(e);
- });
- //数字格式化
- $('td.num').each(function(index,e){
- var num = $(e).html();
- num = numFormat(num);
- $(e).html(num);
- });
-
- //每行的合计
- $('.rowSum').each(function(index,e){
- var temp = $(e).attr("class").split(' ');
- var classname = temp[2];
- //console.log("index:"+index + ",e:"+e + ",classname:"+classname);
- setRowTotalCell(e, classname);
- });
- //计划费用万元格式化
- $('td.wnum').each(function(index,e){
- var num = $(e).html();
- //单位 元=>万元
- num = num/10000;
- num = numFormat(num);
- $(e).html(num);
- });
- //公司小计
- 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);
- }
- //公司里程小计
- var subtotal = $('.subtotal').find('td[totalType="km_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];
- setKmSubTotalCell(companyid,classname,i);
-
- }
-
- //小计序号
- $('.totaltr').find('.indexCell').html($('.edittr').length+1);
- //留痕标红
- //setRecordInfo();
-
- //数字格式化-里程格式化
- $('td.kmnum').each(function(index,e){
- var num = $(e).html();
- if(""!= num){
- num = Number(num).toFixed(3) ;
- }
- $(e).html(num);
- });
-
- $("input.editInput").each(function(index,e){
- var num = $(e).val();
- if(num.indexOf("input") != -1){
- num = numFormat(num);
- $(e).val(num);
- }
- });
-
- //预防小修、中修、大修 小计
- $('.fourNum').each(function(index,e){
- setYFTotalCell(e);
- });
-
-
- $('.sevenNum').each(function(index,e){
- setYHJHTotalCell(e);
- });
-
-
- $('.3Num').each(function(index,e){
- setXJCell(e);
- });
-
- // 修复养护小修、中修、大修 小计
- $('.eightNum').each(function(index,e){
- setXFYHTotalCell(e);
- });
-
- // 计划养护汇总-合计
- $('.eightNumJHHZ').each(function(index,e){
- eightNumJHHZ(e);
- });
- //小计行的总计列
- var totalcells = $('.totaltr').find('.sumCell');
- for(var i=0; i<totalcells.length; i++){
- /*if(i==14){
- setTotalCell(i);
- }*/
- setTotalCell(i);
- }
- //里程的总计列
- var totalkmcells = $('.totaltr').find('.sumkmCell');
- for(var i=0; i<totalkmcells.length; i++){
- setKMTotalCell(i);
- }
- //百分比初始化
- $('#Form table tbody tr').each(function(index,e){
- //setTrPercentCell(e);
- setTrPercentCell2(e);
- setTrKmPercentCell2(e);
- });
-
- //除法
- $('#Form table tbody tr').each(function(index,e){
- //setTrPercentCell(e);
- setTrDivisionCell(e);
- });
-
-
- }
- //明细表input失焦后操作(计算公司审批费用小计)
- function editValue(e){
- if(!$(e).attr('readonly')){
- //公司小计
- var subtotal = $('.edittr').find('td[tType="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[2];
- setSTotalCell(companyid,classname,i);
-
- }
- //小计行的总计列
- var totalcells = $('.totaltr').find('.sumCell');
- for(var i=0; i<totalcells.length; i++){
- setTotalCell(i);
- }
- }
- }
- function setSTotalCell(companyid,classname,index){
- var totalvalue = 0;
- for(var i=0; i<$('.edittr.date.'+companyid).length; i++){
- var subcellval = $('.edittr.date.'+companyid).eq(i).find('.AUDIT_FEE').find("INPUT").val();
- if(typeof(subcellval) != "undefined")
- totalvalue += Number(subcellval);
- }
- if(totalvalue != 0){
- $('.edittr').find('td[tType="subtotal"]').eq(index).html(numFormat(totalvalue) + '');
- }
- }
- function editTable(){
- if(editflag == 0){
- $('#editbutton').html('编辑中');
- $(".editInput").removeAttr("readonly");
- $("#savebutton").removeAttr("disabled");
- editflag = 1;
- }else if(editflag == 1){
- $('#editbutton').html('编辑');
- $(".editInput").attr("readonly","readonly" );
- $("#savebutton").attr("disabled","disabled");
- editflag = 0;
- }
- }
- function saveTable(type,year){
- $("#savebutton").attr("disabled","disabled");
- if(editflag == 1){
- $('#editbutton').html('编辑');
- $(".editInput").attr("readonly","readonly");
- editflag = 0;
- }
- var tabledata = dataResult();
- $.ajax({
- type : "get",
- url : locat+'/annualPlanKG/saveData.do?data='+JSON.stringify(tabledata)+'&TABLETYPE='+type+'&YEAR='+year,
- dataType : 'json',
- success : function(data){
- if(JSON.stringify(recordData) != "{}") saveRecordInfo();
- //保存后更新input原始值
- for(var i=0;i<$('.editInput').length;i++){
- var e = $('.editInput')[i];
- $(e).attr('value',$(e).val());
- }
- if(data.msg == 'success'){
- getTop(globalThis).hangge();
- bootbox.dialog({
- message: "<span class='bigger-110'>保存成功!</span>",
- buttons:
- {
- "button" :
- {
- "label" : "确定",
- "className" : "btn-sm btn-success",
- "callback" : function(){
- var selfhref = self.location.href;
- self.location.href = selfhref;
- }
- }
- }
- });
- }else{
- getTop(globalThis).hangge();
- bootbox.dialog({
- message: "<span class='bigger-110'>"+data.msg+"</span>",
- buttons:
- {
- "button" :
- {
- "label" : "确定",
- "className" : "btn-sm btn-success"
- }
- }
- });
- }
- }
- });
- }
- function dataResult(){
- var mapArry = $("#Form").serializeArray();
- var dataArry = [];
- var cellcount = $('.edittr:eq(0) >td').length;
- var recordcount = $('.edittr.date').length;
- for(var i=0; i<recordcount; i++){
- var recordmap = new Object();
- for(var j=0; j<5; j++){
- recordmap[mapArry[i*5+j].name] = mapArry[i*5+j].value;
- }
- dataArry.push(recordmap);
- }
- return dataArry;
- }
- function setRowTotalCell(e, classname){
- var totalvalue = 0;
- for(var i=0; i<$(e).parent().find("td[class*="+classname+"]").length; i++){
- /* if(i=="14"){
- debugger;
- }*/
- if($(e).parent().find("td[class*="+classname+"]").eq(i)[0].className.indexOf("kmnum") == -1){
- console.log("******className****"+$(e).parent().find("td[class*="+classname+"]").eq(i)[0].className);
- var subcellval;
- if($(e).parent().find("td[class*="+classname+"]").eq(i).find("INPUT").length > 0){
- subcellval = $(e).parent().find("td[class*="+classname+"]").eq(i).val();
- //console.log("INPUT:" + "i:"+i+",subcellval:"+ subcellval);
- }else{
- subcellval = $(e).parent().find("td[class*="+classname+"]").eq(i).html();
- }
- if(typeof(subcellval) != "undefined" && subcellval != "")
- //console.log("i:"+i+",subcellval:"+ subcellval);
- totalvalue += Number(subcellval);
- }
- }
- if(totalvalue != 0 && totalvalue != 'NaN'){
- $(e).html(numFormat(totalvalue) + '');
- //console.log("totalvalue:"+ numFormat(totalvalue));
- }
- }
- function setPreTotalCell(e){
- var totalvalue = 0;
- var num1 = $(e).parent().find("."+$(e).attr("num3")).html();
- var num2 = $(e).parent().find("."+$(e).attr("num4")).html();
- var num3 = $(e).parent().find("."+$(e).attr("num5")).html();
- if(typeof(num1) != "undefined" && typeof(num2) != "undefined" && typeof(num3) != "undefined"){
- totalvalue = Number(num1) + Number(num2) + Number(num3);
- }
- if(totalvalue != 0){
- $(e).html(numFormat(totalvalue) + '');
- }
- }
- function setSubTotalCell(companyid,classname,index){
- var totalvalue = 0;
- for(var i=0; i<$('.edittr.'+companyid +' .'+classname).length; i++){
- var subcellval;
- //
- if(classname!="AUDIT_FEE"){
- 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();
- }
- }
- else{
- subcellval = $('.edittr.'+companyid +' .'+classname).eq(i).html().split("<input")[1].split(" ")[1].replace("value=","").replace("\"","").replace("\"","");
- }
- if(typeof(subcellval) != "undefined")
- totalvalue += Number(subcellval);
- }
- if(totalvalue != 0){
- $('.subtotal').find('td[totalType="subtotal"]').eq(index).html(numFormat(totalvalue) + '');
- }
- }
- function setKmSubTotalCell(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="km_subtotal"]').eq(index).html(Number(totalvalue).toFixed(3) + '');
- }
- }
- function setTotalCell(index){
- if(index < $('.totaltr').find('.sumCell').length){
- var totalvalue = 0;
- for(var i=0; i<$('.subtotal').length; i++){
- var editcellval;
- if($('.subtotal').eq(i).find('td[totalType="subtotal"]').eq(index).find("INPUT").length > 0){
- editcellval = $('.edittr').eq(i).find('td[totalType="subtotal"]').eq(index).val();
- }else{
- editcellval = $('.subtotal').eq(i).find('td[totalType="subtotal"]').eq(index).html();
- }
- if(typeof(editcellval) != "undefined")
- totalvalue += Number(editcellval);
- }
- for(var i=0; i<$('.edittr').length; i++){
- var rycellval=0;
- var myArray=new Array();
- myArray = $('.edittr').eq(i).attr("class").split(" ");
- //加上无小计
- if(myArray != null && myArray.length > 0){
- if(myArray[1] == "006" || myArray[1] == "013" ){
- console.log($('.edittr').eq(i).find('td[totalType="sum"]').eq(index)[0].className.split(" ")[2]);
- if($('.edittr').eq(i).find('td[totalType="sum"]').eq(index)[0].className.split(" ")[2]==("AUDIT_FEE")){
- rycellval = $('.edittr').eq(i).find('td[totalType="sum"]').eq(index).html().split("<input")[1].split(" ")[1].replace("value=","").replace("\"","").replace("\"","");
-
- }
- else{
- if($('.edittr').eq(i).find('td[totalType="sum"]').eq(index).find("INPUT").length > 0){
- rycellval = $('.edittr').eq(i).find('td[totalType="sum"]').eq(index).val();
- }else{
- rycellval = $('.edittr').eq(i).find('td[totalType="sum"]').eq(index).html();
- }
- }
- break;
- }
- }
- }
- totalvalue += Number(rycellval);
- if(totalvalue != 0){
- $('.totaltr').find('.sumCell').eq(index).html(numFormat(totalvalue) + '');
- }
- }
- }
- function setKMTotalCell(index){
- if(index < $('.totaltr').find('.sumkmCell').length){
- var totalvalue = 0;
- for(var i=0; i<$('.edittr').length; i++){
- var editcellval;
- if($('.edittr').eq(i).find('td[totalType="kmsum"]').eq(index).find("INPUT").length > 0){
- editcellval = $('.edittr').eq(i).find('td[totalType="kmsum"]').eq(index).val();
- }else{
- editcellval = $('.edittr').eq(i).find('td[totalType="kmsum"]').eq(index).html();
- }
- if(typeof(editcellval) != "undefined")
- totalvalue += Number(editcellval);
- }
- if(totalvalue != 0){
- $('.totaltr').find('.sumkmCell').eq(index).html(Number(totalvalue).toFixed(3) + '');
- }
- }
- }
- function setSubtotal(tr){
- // $(tr).find("td>.subtotal").each(function(index,e){
- // var name = $(e).attr("name");
- var totalNum;
- $(tr).find("td[name='PREVENTION_DESIGN']").each(function(index,e){
- var num = $(e).text();
- totalNum = totalNum + num;
- });
- //$(e).val(totalNum);
- // });
- }
- function setTrPercentCell(tr){
- $(tr).find("td>.percentCell").each(function(index,e){
- if(e.tagName == "INPUT"){
- var num1 = $(tr).find("td>."+$(e).attr("num1")).val();
- var num2 = $(tr).find("td>."+$(e).attr("num2")).val();
- var result = percentage(num1, num2);
- $(e).val(result);
- }else if(e.tagName == "SPAN"){
- 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 setTrPercentCell2(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 setTrKmPercentCell2(tr){
- $(tr).find("td.percentKmCell").each(function(index,e){
- var num1 = $(tr).find("td."+$(e).attr("num1")).html();
- var num2 = $(tr).find("td."+$(e).attr("num2")).html();
- var result = percentagekm(num1, num2);
- $(e).html(result);
- });
- }
- function setTrDivisionCell(tr){
- $(tr).find("td.divisionCell").each(function(index,e){
- var num1 = $(tr).find("td."+$(e).attr("num1")).html();
- var num2 = $(tr).find("td."+$(e).attr("num2")).html();
- var result = division(num1, num2);
- $(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) + "%";
- percent = Math.round(Number(num1) / Number(num2) * 100);
- return percent;
- }
- function percentagekm(num1, num2){
- var percent = "";
- if(!isNaN(Number(num1)) && !isNaN(Number(num2)) && Number(num2) != "0" )
- percent = (Number(num1) / Number(num2)).toFixed(1);
- return percent;
- }
- function division(num1, num2){
- var percent = "";
- if(!isNaN(Number(num1)) && !isNaN(Number(num2)) && Number(num2) != "0" )
- percent = (Number(num1) / Number(num2)).toFixed(1);
- 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 setYFTotalCell(e){
- var totalvalue = 0;
- var num1 = $(e).parent().find("."+$(e).attr("num6")).html();
- var num2 = $(e).parent().find("."+$(e).attr("num7")).html();
- var num3 = $(e).parent().find("."+$(e).attr("num8")).html();
- var num4 = $(e).parent().find("."+$(e).attr("num9")).html();
- if(typeof(num1) != "undefined" && typeof(num2) != "undefined"
- && typeof(num3) != "undefined"&& typeof(num4) != "undefined"){
- totalvalue = Number(num1) + Number(num2) + Number(num3) + Number(num4);
- }
- if(totalvalue != 0){
- $(e).html(numFormat(totalvalue) + '');
- }
- }
- //修复养护小修、中修、大修小计
- function setXFYHTotalCell(e){
- var totalvalue = 0;
- var num1 = $(e).parent().find("."+$(e).attr("num10")).html();
- var num2 = $(e).parent().find("."+$(e).attr("num11")).html();
- var num3 = $(e).parent().find("."+$(e).attr("num12")).html();
- var num4 = $(e).parent().find("."+$(e).attr("num13")).html();
- var num5 = $(e).parent().find("."+$(e).attr("num14")).html();
- var num6 = $(e).parent().find("."+$(e).attr("num15")).html();
- var num7 = $(e).parent().find("."+$(e).attr("num16")).html();
- var num8 = $(e).parent().find("."+$(e).attr("num17")).html();
-
- //num17下有文本框时取name为$(e).attr("num24")的input值
- var tdInput = $(e).parent().find("."+$(e).attr("num17"));
- if($(tdInput).find('input').length > 0){
- num8 = $(tdInput).find('input[name="'+$(e).attr("num17")+'"]').val();
- }
-
- if(typeof(num1) != "undefined" && typeof(num2) != "undefined"
- && typeof(num3) != "undefined"&& typeof(num4) != "undefined"
- && typeof(num5) != "undefined"&& typeof(num6) != "undefined"
- && typeof(num7) != "undefined"&& typeof(num8) != "undefined"){
- totalvalue = Number(num1) + Number(num2) + Number(num3) + Number(num4)
- +Number(num5) + Number(num6) + Number(num7) + Number(num8);
- }
- if(totalvalue != 0){
- $(e).html(numFormat(totalvalue) + '');
- }
- }
- function eightNumJHHZ(e){
- var totalvalue = 0;
- var num1 = $(e).parent().find("."+$(e).attr("num10")).html();
- var num2 = $(e).parent().find("."+$(e).attr("num11")).html();
- var num3 = $(e).parent().find("."+$(e).attr("num12")).html();
- var num4 = $(e).parent().find("."+$(e).attr("num13")).html();
- var num5 = $(e).parent().find("."+$(e).attr("num14")).html();
- var num6 = $(e).parent().find("."+$(e).attr("num15")).html();
- var num7 = $(e).parent().find("."+$(e).attr("num16")).html();
- var num8 = $(e).parent().find("."+$(e).attr("num17")).html();
- //num17下有文本框时取name为$(e).attr("num24")的input值
- var tdInput = $(e).parent().find("."+$(e).attr("num17"));
- if($(tdInput).find('input').length > 0){
- num8 = $(tdInput).find('input[name="'+$(e).attr("num17")+'"]').val();
- }
-
- if(num8 == ""){
- num8 = $(e).parent().find("."+$(e).attr("num18")).html();
- }
- if(typeof(num1) != "undefined" && typeof(num2) != "undefined"
- && typeof(num3) != "undefined"&& typeof(num4) != "undefined"
- && typeof(num5) != "undefined"&& typeof(num6) != "undefined"
- && typeof(num7) != "undefined"&& typeof(num8) != "undefined"){
- totalvalue = Number(num1) + Number(num2) + Number(num3) + Number(num4)
- +Number(num5) + Number(num6) + Number(num7) + Number(num8);
- }
- if(totalvalue != 0){
- $(e).html(numFormat(totalvalue) + '');
- }
- }
- function setYHJHTotalCell(e){
- var totalvalue = 0;
- var num1 = $(e).parent().find("."+$(e).attr("num18")).html();
- var num2 = $(e).parent().find("."+$(e).attr("num19")).html();
- var num3 = $(e).parent().find("."+$(e).attr("num20")).html();
- var num4 = $(e).parent().find("."+$(e).attr("num21")).html();
- var num5 = $(e).parent().find("."+$(e).attr("num22")).html();
- var num6 = $(e).parent().find("."+$(e).attr("num23")).html();
- var num7 = $(e).parent().find("."+$(e).attr("num24")).html();
- if(typeof(num1) != "undefined" && typeof(num2) != "undefined"
- && typeof(num3) != "undefined"&& typeof(num4) != "undefined"
- && typeof(num5) != "undefined"&& typeof(num6) != "undefined"&& typeof(num7) != "undefined"){
- totalvalue = Number(num1) + Number(num2) + Number(num3) + Number(num4)
- +Number(num5) + Number(num6) + Number(num7) ;
- }
- if(totalvalue != 0){
- $(e).html(numFormat(totalvalue) + '');
- }
- }
- function setXJCell(e){
- var totalvalue = 0;
- var num1 = $(e).parent().find("."+$(e).attr("num3")).html();
- var num2 = $(e).parent().find("."+$(e).attr("num4")).html();
- var num3 = $(e).parent().find("."+$(e).attr("num5")).html();
- if(typeof(num1) != "undefined" && typeof(num2) != "undefined"
- && typeof(num3) != "undefined"){
- totalvalue = Number(num1) + Number(num2) + Number(num3) ;
- }
- if(totalvalue != 0){
- $(e).html(numFormat(totalvalue) + '');
- }
- }
- //获取本网站的顶级节点,解决被其他网站iframe引入时发生的跨域问题
- function getTop(obj){
- var tp = obj;
- //alert(obj.name);
- if (tp.mainFrame == undefined) {
- tp = tp.parent;
- return getTop(tp);
- } else {
- return tp;
- }
- }
|