annualDailyComp.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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 pd_TABLETYPE = $('#pd_TABLETYPE').html();
  5. var pd_COMPANY = $('#pd_COMPANY').html();
  6. var pd_COMPANY_ID = $('#pd_COMPANY_ID').html();
  7. var pd_YEAR = $('#pd_YEAR').html();
  8. var editflag = 0;
  9. var recordData = new Object();
  10. var recordBeforeValue = new Object();
  11. var status = $('.edittr:eq(0) >td >input[name="STATUS"]').val();
  12. var currStatus = status;
  13. var rocordInfoList = new Object();
  14. function tableInit(){
  15. //行内小计列
  16. //setRowSumCell(e);
  17. //小计行的总计列
  18. var totalcells = $('.totaltr').find('.sumCell');
  19. for(var i=0; i<totalcells.length; i++){
  20. setTotalCell(i);
  21. }
  22. //百分比初始化
  23. $('#Form table tbody tr').each(function(index,e){
  24. setTrPercentCell(e);
  25. });
  26. //小计序号
  27. $('.totaltr').find('.indexCell').html($('.edittr').length+1);
  28. //留痕标红
  29. setRecordInfo();
  30. //数字格式化
  31. $("input.editInput").each(function(index,e){
  32. var num = $(e).val();
  33. num = numFormat(num);
  34. $(e).val(num);
  35. });
  36. }
  37. function setTotalCell(index){
  38. if(index < $('.totaltr').find('.sumCell').length){
  39. var totalvalue = 0;
  40. for(var i=0; i<$('.edittr').length; i++){
  41. var editcellval = $('.edittr').eq(i).find('input[totalType="sum"]').eq(index).val();
  42. if(typeof(editcellval) != "undefined")
  43. totalvalue += Number(editcellval);
  44. }
  45. $('.totaltr').find('.sumCell').eq(index).html(numFormat(totalvalue) + '');
  46. }
  47. }
  48. function setRowSumCell(e){
  49. if(index < $('.totaltr').find('.sumCell').length){
  50. var totalvalue = 0;
  51. for(var i=0; i<$('.edittr').length; i++){
  52. var editcellval = $('.edittr').eq(i).find('input[totalType="sum"]').eq(index).val();
  53. if(typeof(editcellval) != "undefined")
  54. totalvalue += Number(editcellval);
  55. }
  56. $('.totaltr').find('.sumCell').eq(index).html(numFormat(totalvalue) + '');
  57. }
  58. }
  59. function editTable(){
  60. if(editflag == 0){
  61. $('#editbutton').html('编辑中');
  62. $(".editInput").removeAttr("readonly");
  63. editflag = 1;
  64. }else if(editflag == 1){
  65. $('#editbutton').html('编辑');
  66. $(".editInput").attr("readonly","readonly" );
  67. editflag = 0;
  68. }
  69. }
  70. function saveTable(type){
  71. changeStatus(type);
  72. if(editflag == 1){
  73. $('#editbutton').html('编辑');
  74. $(".editInput").attr("readonly","readonly");
  75. editflag = 0;
  76. }
  77. var tabledata = dataResult();
  78. $.ajax({
  79. type : "get",
  80. url : locat+'/annualDailyComp/saveData.do?data='+JSON.stringify(tabledata)+'&TABLETYPE='+pd_TABLETYPE+'&COMPANY_ID='+pd_COMPANY_ID+'&YEAR='+pd_YEAR,
  81. dataType : 'json',
  82. success : function(data){
  83. if(JSON.stringify(recordData) != "{}") saveRecordInfo();
  84. //保存后更新input原始值
  85. for(var i=0;i<$('.editInput').length;i++){
  86. var e = $('.editInput')[i];
  87. $(e).attr('value',$(e).val());
  88. }
  89. }
  90. });
  91. updateStatus(type);
  92. }
  93. function changeStatus(type){
  94. for(var i=0;i<$("input[name='STATUS']").length;i++){
  95. var e = $("input[name='STATUS']")[i];
  96. $(e).attr('value',type);
  97. $(e).val(type);
  98. currStatus = type;
  99. }
  100. }
  101. function updateAllStatus(status, companyid, year){
  102. debugger;
  103. $.ajax({
  104. type : "get",
  105. url : locat+'/annualDailyComp/updateAllStatus.do?STATUS='+status+'&COMPANY_ID='+companyid+'&YEAR='+year,
  106. dataType : 'json',
  107. success : function(data){
  108. if(status == 2){
  109. status = '提交审核';
  110. }else if(status == 9){
  111. status = '审批';
  112. }else{
  113. status = '提交';
  114. }
  115. alert(status+"完成");
  116. }
  117. });
  118. }
  119. function updateStatus(type){
  120. $.ajax({
  121. type : "get",
  122. url : locat+'/annualDailyComp/updateStatus.do?STATUS='+type+'&TABLETYPE='+pd_TABLETYPE+'&COMPANY_ID='+pd_COMPANY_ID+'&YEAR='+pd_YEAR,
  123. dataType : 'json',
  124. success : function(data){
  125. //alert("change success!");
  126. }
  127. });
  128. }
  129. function updatePlanStatus(type,companyid,year){
  130. $.ajax({
  131. type : "get",
  132. url : locat+'/annualDailyComp/updateAllStatus.do?STATUS='+type+'&COMPANY_ID='+companyid+'&YEAR='+year,
  133. dataType : 'json',
  134. success : function(data){
  135. alert("change success!");
  136. }
  137. });
  138. }
  139. function saveRecordInfo(){
  140. $.ajax({
  141. type : "get",
  142. url : locat+'/annualDailyComp/saveRecordInfo.do?recordData='+JSON.stringify(recordData)
  143. +'&recordBeforeValue='+JSON.stringify(recordBeforeValue)+'&TABLE_NAME='+pd_TABLETYPE
  144. +'&COMPANY_ID='+pd_COMPANY_ID+'&YEAR='+pd_YEAR+'&BEFORE_STATUS='+status+'&AFTER_STATUS='+currStatus+'&type=ROAD_ID',
  145. dataType : 'json',
  146. success : function(data){
  147. recordData = new Object();
  148. recordBeforeValue = new Object();
  149. //留痕标红
  150. setRecordInfo();
  151. }
  152. });
  153. }
  154. function dataResult(){
  155. var mapArry = $("#Form").serializeArray();
  156. var dataArry = [];
  157. var cellcount = $('.edittr:eq(0) >td').length;
  158. var recordcount = $('.edittr').length;
  159. for(var i=0; i<recordcount; i++){
  160. var recordmap = new Object();
  161. for(var j=0; j<cellcount; j++){
  162. recordmap[mapArry[i*cellcount+j].name] = mapArry[i*cellcount+j].value.replace("%","");
  163. }
  164. dataArry.push(recordmap);
  165. }
  166. return dataArry;
  167. }
  168. function editValue(e){
  169. if(!$(e).attr('readonly')){
  170. //数字格式化
  171. var num = "";
  172. if(e.tagName == "INPUT"){
  173. num = $(e).val();
  174. num = numFormat(num);
  175. $(e).val(num);
  176. }
  177. if($(e).attr("totalType") == "sum") setTotalCell($(e).parent().parent().find('input[totalType="sum"]').index(e));
  178. setTrPercentCell($(e).parent().parent()[0]);
  179. setTrPercentCell($(".totaltr")[0]);
  180. if($('#pd_mode').html() == 'edit') setRecordData(e);
  181. }
  182. }
  183. function setRecordData(e){
  184. var key = $(e).attr('name');
  185. var roadid = $(e).parent().parent().attr('class').substring(7);
  186. var value = $(e).val();
  187. var beforeValue = $(e).attr('value');
  188. if($(e).val() != $(e).attr('value') && $(e).attr('value') != ''){
  189. if(!recordData[roadid]){
  190. recordData[roadid] = new Object();
  191. recordBeforeValue[roadid] = new Object();
  192. }
  193. recordData[roadid][key] = value;
  194. recordBeforeValue[roadid][key] = beforeValue;
  195. }else if($(e).val() == $(e).attr('value') && $(e).attr('value') != ''){
  196. if(key in recordData[roadid] && roadid in recordData){
  197. delete recordData[roadid][key];
  198. delete recordBeforeValue[roadid][key];
  199. if(JSON.stringify(recordData[roadid]) == "{}"){
  200. delete recordData[roadid];
  201. delete recordBeforeValue[roadid];
  202. }
  203. }
  204. }
  205. }
  206. function setRecordInfo(){
  207. $.ajax({
  208. type : "get",
  209. url : locat+'/annualDailyComp/showRecodInfo.do?TABLE_NAME='+pd_TABLETYPE+'&COMPANY_ID='+pd_COMPANY_ID+'&YEAR='+pd_YEAR,
  210. dataType : 'json',
  211. success : function(data){
  212. for(var e in rocordInfoList){
  213. $('.highlight').removeClass(e);
  214. }
  215. $('.highlight').removeClass('highlight');
  216. rocordInfoList = data.rocordInfoList;
  217. for(var e in data.rocordInfoList){
  218. $('.'+data.rocordInfoList[e].ROAD_ID+' >td >.'+data.rocordInfoList[e].TABLE_FIELDS).addClass("highlight " + e);
  219. }
  220. }
  221. });
  222. }
  223. function highlightInit(){
  224. $('.editInput').off("mouseover mouseout").on("mouseover mouseout",function(event){
  225. if($(this).attr('class').split(' ').length > 2){
  226. if(event.type == "mouseover"){
  227. var indexClass = $(this).attr('class').split(' ')[3];
  228. var before = rocordInfoList[indexClass].BEFORE_VAL;
  229. var after = rocordInfoList[indexClass].AFTER;
  230. $(this).parent().append('<div id="recordInfoDiv">'+before+'--'+after+'</div>');
  231. }else if(event.type == "mouseout"){
  232. $("#recordInfoDiv").remove();
  233. }
  234. }
  235. });
  236. }
  237. //function excelExport(){
  238. // window.location.href=locat+'/annualDailyComp/exportDoc.do?modelName=311_highway_scientific_project_dettable.ftl&COMPANY_ID=001&YEAR=2018&ROAD_ID=111&TABLETYPE=highway_scientific_project_dettable';
  239. //}
  240. function excelExport(){
  241. var arry = [];
  242. $('.edittr:eq(0)>td>input').each(function(index,e){
  243. var n = $(e).attr('name');
  244. if(n!='SERIAL_NUM'&&n!='STATUS'&&n!='COMPANY'&&n!='YEAR'&&n!='COMPANY_ID'&&n!='ROAD_ID'){
  245. var key = $(e).attr('name');
  246. arry.push(key);
  247. }
  248. });
  249. var keyStr = arry.join(',');
  250. window.location.href=locat+'/annualDailyComp/export.do?TABLETYPE='+pd_TABLETYPE+'&COMPANY_ID='+pd_COMPANY_ID+'&YEAR='+pd_YEAR+'&keyStr='+keyStr;
  251. }
  252. $(function(){
  253. // importInit();
  254. tableInit();
  255. highlightInit();
  256. });
  257. function setTrPercentCell(tr){
  258. $(tr).find("td>.percentCell").each(function(index,e){
  259. if(e.tagName == "INPUT"){
  260. var num1 = $(tr).find("td>."+$(e).attr("num1")).val();
  261. var num2 = $(tr).find("td>."+$(e).attr("num2")).val();
  262. var result = percentage(num1, num2);
  263. $(e).val(result);
  264. }else if(e.tagName == "SPAN"){
  265. var num1 = $(tr).find("td>."+$(e).attr("num1")).html();
  266. var num2 = $(tr).find("td>."+$(e).attr("num2")).html();
  267. var result = percentage(num1, num2);
  268. $(e).html(result);
  269. }
  270. });
  271. }
  272. function percentage(num1, num2){
  273. var percent = "";
  274. if(!isNaN(Number(num1)) && !isNaN(Number(num2)) && Number(num2) != "0" )
  275. // percent = Math.round(Number(num1) / Number(num2) * 10000) / 100.00 + "%";
  276. percent = Math.round(Number(num1) / Number(num2) * 100);
  277. return percent;
  278. }
  279. //function fileType(obj){
  280. // var fileType=obj.value.substr(obj.value.lastIndexOf(".")).toLowerCase();//获得文件后缀名
  281. // if(fileType != '.xls'){
  282. // $("#excel").tips({
  283. // side:3,
  284. // msg:'请上传xls格式的文件',
  285. // bg:'#AE81FF',
  286. // time:3
  287. // });
  288. // $("#excel").val('');
  289. // document.getElementById("excel").files[0] = '请选择xls格式的文件';
  290. // }
  291. //}
  292. //function importExcle(){
  293. // if($("#excel").val()=="" || document.getElementById("excel").files[0] =='请选择xls格式的文件'){
  294. // $("#excel").tips({
  295. // side:3,
  296. // msg:'请选择文件',
  297. // bg:'#AE81FF',
  298. // time:3
  299. // });
  300. // return false;
  301. // }
  302. // $.ajax({
  303. // type : "get",
  304. // url : locat+'/annualDailyComp/readExcel.do?TABLE_NAME='+pd_TABLETYPE+'&COMPANY_ID='+pd_COMPANY_ID+'&YEAR='+pd_YEAR+'&COMPANY='+pd_COMPANY+'&excel='+$("#excel").val(),
  305. // dataType : 'json',
  306. // success : function(data){
  307. //
  308. // }
  309. // });
  310. //}
  311. //
  312. //function importInit(){
  313. // //上传
  314. // $('#excel').ace_file_input({
  315. //// style:'well',
  316. // no_file:'请选择EXCEL ...',
  317. // btn_choose:'选择',
  318. // btn_change:'更改',
  319. // droppable:false,
  320. // onchange:null,
  321. // thumbnail:false, //| true | large
  322. // whitelist:'xls|xlsx',
  323. // blacklist:'gif|png|jpg|jpeg',
  324. // allowExt: ['xls','xlsx']
  325. // //onchange:''
  326. // });
  327. //}
  328. function numFormat(num){
  329. if(!isNaN(Number(num)) && Number(num) != "0"){
  330. if(num<10) num = Number(num).toFixed(1);
  331. else num = Math.round(Number(num));
  332. }
  333. return num;
  334. }
  335. //获取本网站的顶级节点,解决被其他网站iframe引入时发生的跨域问题
  336. function getTop(obj){
  337. var tp = obj;
  338. //alert(obj.name);
  339. if (tp.mainFrame == undefined) {
  340. tp = tp.parent;
  341. return getTop(tp);
  342. } else {
  343. return tp;
  344. }
  345. }