annualPlan.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. var locat = (window.location+'').split('/');
  2. $(function(){if('fhsms'== locat[3]){locat = locat[0]+'//'+locat[2];}else{locat = locat[0]+'//'+locat[2]+'/'+locat[3];};});
  3. $(getTop(globalThis).hangge());
  4. var editflag = 0;
  5. var recordData = new Object();
  6. var recordBeforeValue = new Object();
  7. $(function(){
  8. tableInit();
  9. //highlightInit();
  10. });
  11. function tableInit(){
  12. //行内小计列
  13. //setRowSumCell(e);
  14. //预防、修复小中大修分别计算总和
  15. $('.threeNum').each(function(index,e){
  16. setPreTotalCell(e);
  17. });
  18. //每行的合计
  19. $('.rowSum').each(function(index,e){
  20. var temp = $(e).attr("class").split(' ');
  21. var classname = temp[2];
  22. //console.log("index:"+index + ",e:"+e + ",classname:"+classname);
  23. setRowTotalCell(e, classname);
  24. });
  25. //计划费用万元格式化
  26. $('td.wnum').each(function(index,e){
  27. var num = $(e).html();
  28. //单位 元=>万元
  29. num = num/10000;
  30. num = numFormat(num);
  31. $(e).html(num);
  32. });
  33. //公司小计
  34. var subtotal = $('.subtotal').find('td[totalType="subtotal"]');
  35. for(var i=0; i<subtotal.length; i++){
  36. var companyid = subtotal.eq(i).parent().attr("id");
  37. var var1=subtotal.eq(i).attr("class");
  38. var var2=var1.split(' ');
  39. var classname = var2[1];
  40. setSubTotalCell(companyid,classname,i);
  41. }
  42. //小计序号
  43. $('.totaltr').find('.indexCell').html($('.edittr').length+1);
  44. //留痕标红
  45. //setRecordInfo();
  46. //数字格式化
  47. $('td.num').each(function(index,e){
  48. var num = $(e).html();
  49. num = numFormat(num);
  50. $(e).html(num);
  51. });
  52. $("input.editInput").each(function(index,e){
  53. var num = $(e).val();
  54. num = numFormat(num);
  55. $(e).val(num);
  56. });
  57. //小修、中修、大修 小计
  58. $('.fourNum').each(function(index,e){
  59. setXiuTotalCell(e);
  60. });
  61. // 修复养护小修、中修、大修 小计
  62. $('.eightNum').each(function(index,e){
  63. setXFYHTotalCell(e);
  64. });
  65. //小计行的总计列
  66. var totalcells = $('.totaltr').find('.sumCell');
  67. for(var i=0; i<totalcells.length; i++){
  68. setTotalCell(i);
  69. }
  70. //除
  71. $('#Form table tbody tr').each(function(index,e){
  72. //setTrPercentCell(e);
  73. setTrPercentCell(e);
  74. });
  75. }
  76. function setRowTotalCell(e, classname){
  77. var totalvalue = 0;
  78. for(var i=0; i<$(e).parent().find("td[class*="+classname+"]").length; i++){
  79. /* if(i=="14"){
  80. debugger;
  81. }*/
  82. var subcellval;
  83. if($(e).parent().find("td[class*="+classname+"]").eq(i).find("INPUT").length > 0){
  84. subcellval = $(e).parent().find("td[class*="+classname+"]").eq(i).val();
  85. //console.log("INPUT:" + "i:"+i+",subcellval:"+ subcellval);
  86. }else{
  87. subcellval = $(e).parent().find("td[class*="+classname+"]").eq(i).html();
  88. }
  89. if(typeof(subcellval) != "undefined" && subcellval != "")
  90. //console.log("i:"+i+",subcellval:"+ subcellval);
  91. totalvalue += Number(subcellval);
  92. }
  93. if(totalvalue != 0 && totalvalue != 'NaN'){
  94. $(e).html(numFormat(totalvalue) + '');
  95. //console.log("totalvalue:"+ numFormat(totalvalue));
  96. }
  97. }
  98. function setPreTotalCell(e){
  99. var totalvalue = 0;
  100. var num1 = $(e).parent().find("."+$(e).attr("num3")).html();
  101. var num2 = $(e).parent().find("."+$(e).attr("num4")).html();
  102. var num3 = $(e).parent().find("."+$(e).attr("num5")).html();
  103. if(typeof(num1) != "undefined" && typeof(num2) != "undefined" && typeof(num3) != "undefined"){
  104. totalvalue = Number(num1) + Number(num2) + Number(num3);
  105. }
  106. if(totalvalue != 0){
  107. $(e).html(numFormat(totalvalue) + '');
  108. }
  109. }
  110. function setSubTotalCell(companyid,classname,index){
  111. var totalvalue = 0;
  112. for(var i=0; i<$('.edittr.'+companyid +' .'+classname).length; i++){
  113. var subcellval;
  114. if($('.edittr.'+companyid +' .'+classname).eq(i).find("INPUT").length > 0){
  115. subcellval = $('.edittr.'+companyid +' .'+classname).eq(i).val();
  116. }else{
  117. subcellval = $('.edittr.'+companyid +' .'+classname).eq(i).html();
  118. }
  119. if(typeof(subcellval) != "undefined")
  120. totalvalue += Number(subcellval);
  121. }
  122. if(totalvalue != 0){
  123. $('.subtotal').find('td[totalType="subtotal"]').eq(index).html(numFormat(totalvalue) + '');
  124. }
  125. }
  126. function setTotalCell(index){
  127. if(index < $('.totaltr').find('.sumCell').length){
  128. var totalvalue = 0;
  129. for(var i=0; i<$('.edittr').length; i++){
  130. var editcellval;
  131. if($('.edittr').eq(i).find('td[totalType="sum"]').eq(index).find("INPUT").length > 0){
  132. editcellval = $('.edittr').eq(i).find('td[totalType="sum"]').eq(index).val();
  133. }else{
  134. editcellval = $('.edittr').eq(i).find('td[totalType="sum"]').eq(index).html();
  135. //console.log("i:"+i+",index:"+index+",subcellval:"+ editcellval);
  136. }
  137. if(typeof(editcellval) != "undefined")
  138. totalvalue += Number(editcellval);
  139. }
  140. if(totalvalue != 0){
  141. $('.totaltr').find('.sumCell').eq(index).html(numFormat(totalvalue) + '');
  142. }
  143. }
  144. }
  145. function setSubtotal(tr){
  146. // $(tr).find("td>.subtotal").each(function(index,e){
  147. // var name = $(e).attr("name");
  148. var totalNum;
  149. $(tr).find("td[name='PREVENTION_DESIGN']").each(function(index,e){
  150. var num = $(e).text();
  151. totalNum = totalNum + num;
  152. });
  153. //$(e).val(totalNum);
  154. // });
  155. }
  156. function setTrPercentCell(tr){
  157. $(tr).find("td.percentCell").each(function(index,e){
  158. var num1 = $(tr).find("td."+$(e).attr("num1")).html();
  159. var num2 = $(tr).find("td."+$(e).attr("num2")).html();
  160. var result = percentage(num1, num2);
  161. $(e).html(result);
  162. });
  163. }
  164. function percentage(num1, num2){
  165. var percent = "";
  166. if(!isNaN(Number(num1)) && !isNaN(Number(num2)) && Number(num2) != "0" )
  167. // percent = Math.round(Number(num1) / Number(num2) * 10000) / 100.00 + "%";
  168. percent = Math.round(Number(num1) / Number(num2));
  169. return percent;
  170. }
  171. function numFormat(num){
  172. if(!isNaN(Number(num)) && Number(num) != "0"){
  173. if(num<10) num = Number(num).toFixed(1);
  174. else num = Math.round(Number(num));
  175. }
  176. return num;
  177. }
  178. function setXiuTotalCell(e){
  179. var totalvalue = 0;
  180. var num1 = $(e).parent().find("."+$(e).attr("num6")).html();
  181. var num2 = $(e).parent().find("."+$(e).attr("num7")).html();
  182. var num3 = $(e).parent().find("."+$(e).attr("num8")).html();
  183. var num4 = $(e).parent().find("."+$(e).attr("num9")).html();
  184. if(typeof(num1) != "undefined" && typeof(num2) != "undefined"
  185. && typeof(num3) != "undefined"&& typeof(num4) != "undefined"){
  186. totalvalue = Number(num1) + Number(num2) + Number(num3) + Number(num4);
  187. }
  188. if(totalvalue != 0){
  189. $(e).html(numFormat(totalvalue) + '');
  190. }
  191. }
  192. //修复养护小修、中修、大修小计
  193. function setXFYHTotalCell(e){
  194. var totalvalue = 0;
  195. var num1 = $(e).parent().find("."+$(e).attr("num10")).html();
  196. var num2 = $(e).parent().find("."+$(e).attr("num11")).html();
  197. var num3 = $(e).parent().find("."+$(e).attr("num12")).html();
  198. var num4 = $(e).parent().find("."+$(e).attr("num13")).html();
  199. var num5 = $(e).parent().find("."+$(e).attr("num14")).html();
  200. var num6 = $(e).parent().find("."+$(e).attr("num15")).html();
  201. var num7 = $(e).parent().find("."+$(e).attr("num16")).html();
  202. var num8 = $(e).parent().find("."+$(e).attr("num17")).html();
  203. if(typeof(num1) != "undefined" && typeof(num2) != "undefined"
  204. && typeof(num3) != "undefined"&& typeof(num4) != "undefined"
  205. && typeof(num5) != "undefined"&& typeof(num6) != "undefined"
  206. && typeof(num7) != "undefined"&& typeof(num8) != "undefined"){
  207. totalvalue = Number(num1) + Number(num2) + Number(num3) + Number(num4)
  208. +Number(num5) + Number(num6) + Number(num7) + Number(num8);
  209. }
  210. if(totalvalue != 0){
  211. $(e).html(numFormat(totalvalue) + '');
  212. }
  213. }
  214. //获取本网站的顶级节点,解决被其他网站iframe引入时发生的跨域问题
  215. function getTop(obj){
  216. var tp = obj;
  217. //alert(obj.name);
  218. if (tp.mainFrame == undefined) {
  219. tp = tp.parent;
  220. return getTop(tp);
  221. } else {
  222. return tp;
  223. }
  224. }