123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- 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 pd_COMPANY = $('#pd_COMPANY').html();
- var pd_COMPANY_ID = $('#pd_COMPANY_ID').html();
- var pd_YEAR = $('#pd_YEAR').html();
- var editflag = 0;
- var recordData = new Object();
- var recordBeforeValue = new Object();
- var status = $('.edittr:eq(0) >td >input[name="STATUS"]').val();
- var currStatus = status;
- var rocordInfoList = new Object();
- function tableInit(){
- //行内小计列
-
- //setRowSumCell(e);
- //小计行的总计列
- var totalcells = $('.totaltr').find('.sumCell');
- for(var i=0; i<totalcells.length; i++){
- setTotalCell(i);
- }
- //百分比初始化
- $('#Form table tbody tr').each(function(index,e){
- setTrPercentCell(e);
- });
- //小计序号
- $('.totaltr').find('.indexCell').html($('.edittr').length+1);
- //留痕标红
- setRecordInfo();
- //数字格式化
- $("input.editInput").each(function(index,e){
- var num = $(e).val();
- num = numFormat(num);
- $(e).val(num);
- });
- }
- function setTotalCell(index){
- if(index < $('.totaltr').find('.sumCell').length){
- var totalvalue = 0;
- for(var i=0; i<$('.edittr').length; i++){
- var editcellval = $('.edittr').eq(i).find('input[totalType="sum"]').eq(index).val();
- if(typeof(editcellval) != "undefined")
- totalvalue += Number(editcellval);
- }
- $('.totaltr').find('.sumCell').eq(index).html(numFormat(totalvalue) + '');
- }
- }
- function setRowSumCell(e){
- if(index < $('.totaltr').find('.sumCell').length){
- var totalvalue = 0;
- for(var i=0; i<$('.edittr').length; i++){
- var editcellval = $('.edittr').eq(i).find('input[totalType="sum"]').eq(index).val();
- if(typeof(editcellval) != "undefined")
- totalvalue += Number(editcellval);
- }
- $('.totaltr').find('.sumCell').eq(index).html(numFormat(totalvalue) + '');
- }
- }
- function editTable(){
- if(editflag == 0){
- $('#editbutton').html('编辑中');
- $(".editInput").removeAttr("readonly");
- editflag = 1;
- }else if(editflag == 1){
- $('#editbutton').html('编辑');
- $(".editInput").attr("readonly","readonly" );
- editflag = 0;
- }
- }
- function saveTable(type){
- changeStatus(type);
- if(editflag == 1){
- $('#editbutton').html('编辑');
- $(".editInput").attr("readonly","readonly");
- editflag = 0;
- }
- var tabledata = dataResult();
- $.ajax({
- type : "get",
- url : locat+'/annualDailyComp/saveData.do?data='+JSON.stringify(tabledata)+'&TABLETYPE='+pd_TABLETYPE+'&COMPANY_ID='+pd_COMPANY_ID+'&YEAR='+pd_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());
- }
- }
- });
- updateStatus(type);
- }
- function changeStatus(type){
- for(var i=0;i<$("input[name='STATUS']").length;i++){
- var e = $("input[name='STATUS']")[i];
- $(e).attr('value',type);
- $(e).val(type);
- currStatus = type;
- }
- }
- function updateAllStatus(status, companyid, year){
- debugger;
- $.ajax({
- type : "get",
- url : locat+'/annualDailyComp/updateAllStatus.do?STATUS='+status+'&COMPANY_ID='+companyid+'&YEAR='+year,
- dataType : 'json',
- success : function(data){
- if(status == 2){
- status = '提交审核';
- }else if(status == 9){
- status = '审批';
- }else{
- status = '提交';
- }
- alert(status+"完成");
- }
- });
- }
- function updateStatus(type){
- $.ajax({
- type : "get",
- url : locat+'/annualDailyComp/updateStatus.do?STATUS='+type+'&TABLETYPE='+pd_TABLETYPE+'&COMPANY_ID='+pd_COMPANY_ID+'&YEAR='+pd_YEAR,
- dataType : 'json',
- success : function(data){
- //alert("change success!");
- }
- });
- }
- function updatePlanStatus(type,companyid,year){
- $.ajax({
- type : "get",
- url : locat+'/annualDailyComp/updateAllStatus.do?STATUS='+type+'&COMPANY_ID='+companyid+'&YEAR='+year,
- dataType : 'json',
- success : function(data){
- alert("change success!");
- }
- });
- }
- function saveRecordInfo(){
- $.ajax({
- type : "get",
- url : locat+'/annualDailyComp/saveRecordInfo.do?recordData='+JSON.stringify(recordData)
- +'&recordBeforeValue='+JSON.stringify(recordBeforeValue)+'&TABLE_NAME='+pd_TABLETYPE
- +'&COMPANY_ID='+pd_COMPANY_ID+'&YEAR='+pd_YEAR+'&BEFORE_STATUS='+status+'&AFTER_STATUS='+currStatus+'&type=ROAD_ID',
- dataType : 'json',
- success : function(data){
- recordData = new Object();
- recordBeforeValue = new Object();
- //留痕标红
- setRecordInfo();
- }
- });
- }
- function dataResult(){
- var mapArry = $("#Form").serializeArray();
- var dataArry = [];
- var cellcount = $('.edittr:eq(0) >td').length;
- var recordcount = $('.edittr').length;
- for(var i=0; i<recordcount; i++){
- var recordmap = new Object();
- for(var j=0; j<cellcount; j++){
- recordmap[mapArry[i*cellcount+j].name] = mapArry[i*cellcount+j].value.replace("%","");
- }
- dataArry.push(recordmap);
- }
- return dataArry;
- }
- function editValue(e){
- if(!$(e).attr('readonly')){
- //数字格式化
- var num = "";
- if(e.tagName == "INPUT"){
- num = $(e).val();
- num = numFormat(num);
- $(e).val(num);
- }
- if($(e).attr("totalType") == "sum") setTotalCell($(e).parent().parent().find('input[totalType="sum"]').index(e));
- setTrPercentCell($(e).parent().parent()[0]);
- setTrPercentCell($(".totaltr")[0]);
- if($('#pd_mode').html() == 'edit') setRecordData(e);
- }
- }
- function setRecordData(e){
- var key = $(e).attr('name');
- var roadid = $(e).parent().parent().attr('class').substring(7);
- var value = $(e).val();
- var beforeValue = $(e).attr('value');
- if($(e).val() != $(e).attr('value') && $(e).attr('value') != ''){
- if(!recordData[roadid]){
- recordData[roadid] = new Object();
- recordBeforeValue[roadid] = new Object();
- }
- recordData[roadid][key] = value;
- recordBeforeValue[roadid][key] = beforeValue;
- }else if($(e).val() == $(e).attr('value') && $(e).attr('value') != ''){
- if(key in recordData[roadid] && roadid in recordData){
- delete recordData[roadid][key];
- delete recordBeforeValue[roadid][key];
- if(JSON.stringify(recordData[roadid]) == "{}"){
- delete recordData[roadid];
- delete recordBeforeValue[roadid];
- }
- }
- }
- }
- function setRecordInfo(){
- $.ajax({
- type : "get",
- url : locat+'/annualDailyComp/showRecodInfo.do?TABLE_NAME='+pd_TABLETYPE+'&COMPANY_ID='+pd_COMPANY_ID+'&YEAR='+pd_YEAR,
- dataType : 'json',
- success : function(data){
- for(var e in rocordInfoList){
- $('.highlight').removeClass(e);
- }
- $('.highlight').removeClass('highlight');
- rocordInfoList = data.rocordInfoList;
- for(var e in data.rocordInfoList){
- $('.'+data.rocordInfoList[e].ROAD_ID+' >td >.'+data.rocordInfoList[e].TABLE_FIELDS).addClass("highlight " + e);
- }
- }
- });
- }
- function highlightInit(){
- $('.editInput').off("mouseover mouseout").on("mouseover mouseout",function(event){
- if($(this).attr('class').split(' ').length > 2){
- if(event.type == "mouseover"){
- var indexClass = $(this).attr('class').split(' ')[3];
- var before = rocordInfoList[indexClass].BEFORE_VAL;
- var after = rocordInfoList[indexClass].AFTER;
- $(this).parent().append('<div id="recordInfoDiv">'+before+'--'+after+'</div>');
- }else if(event.type == "mouseout"){
- $("#recordInfoDiv").remove();
- }
- }
- });
- }
- //function excelExport(){
- // 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';
- //}
- function excelExport(){
- var arry = [];
- $('.edittr:eq(0)>td>input').each(function(index,e){
- var n = $(e).attr('name');
- if(n!='SERIAL_NUM'&&n!='STATUS'&&n!='COMPANY'&&n!='YEAR'&&n!='COMPANY_ID'&&n!='ROAD_ID'){
- var key = $(e).attr('name');
- arry.push(key);
- }
- });
- var keyStr = arry.join(',');
- window.location.href=locat+'/annualDailyComp/export.do?TABLETYPE='+pd_TABLETYPE+'&COMPANY_ID='+pd_COMPANY_ID+'&YEAR='+pd_YEAR+'&keyStr='+keyStr;
- }
- $(function(){
- // importInit();
- tableInit();
- highlightInit();
- });
- 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 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 fileType(obj){
- // var fileType=obj.value.substr(obj.value.lastIndexOf(".")).toLowerCase();//获得文件后缀名
- // if(fileType != '.xls'){
- // $("#excel").tips({
- // side:3,
- // msg:'请上传xls格式的文件',
- // bg:'#AE81FF',
- // time:3
- // });
- // $("#excel").val('');
- // document.getElementById("excel").files[0] = '请选择xls格式的文件';
- // }
- //}
- //function importExcle(){
- // if($("#excel").val()=="" || document.getElementById("excel").files[0] =='请选择xls格式的文件'){
- // $("#excel").tips({
- // side:3,
- // msg:'请选择文件',
- // bg:'#AE81FF',
- // time:3
- // });
- // return false;
- // }
- // $.ajax({
- // type : "get",
- // url : locat+'/annualDailyComp/readExcel.do?TABLE_NAME='+pd_TABLETYPE+'&COMPANY_ID='+pd_COMPANY_ID+'&YEAR='+pd_YEAR+'&COMPANY='+pd_COMPANY+'&excel='+$("#excel").val(),
- // dataType : 'json',
- // success : function(data){
- //
- // }
- // });
- //}
- //
- //function importInit(){
- // //上传
- // $('#excel').ace_file_input({
- //// style:'well',
- // no_file:'请选择EXCEL ...',
- // btn_choose:'选择',
- // btn_change:'更改',
- // droppable:false,
- // onchange:null,
- // thumbnail:false, //| true | large
- // whitelist:'xls|xlsx',
- // blacklist:'gif|png|jpg|jpeg',
- // allowExt: ['xls','xlsx']
- // //onchange:''
- // });
- //}
- 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;
- }
- //获取本网站的顶级节点,解决被其他网站iframe引入时发生的跨域问题
- function getTop(obj){
- var tp = obj;
- //alert(obj.name);
- if (tp.mainFrame == undefined) {
- tp = tp.parent;
- return getTop(tp);
- } else {
- return tp;
- }
- }
|