/** * 报表生成 * @param id * @param layerType */ function onlineExcel4minio(id, layerType) { var sheetName = ''; //获取该excel的所有sheet 默认加载第一个sheet $.post(ext.contextPath + '/report/rptCreate/getSheet.do', {id: id}, function (data) { var datastr = eval('(' + data + ')'); if (datastr.code == 1) { var msg = datastr.msg; var arr = msg.split(","); var sheetstr = '
'; var btnClass = ""; var sheetName = ""; //循环sheet for (var i = 0; i < arr.length - 1; i++) { if (i == 0) { btnClass = "btn-primary"; } else { btnClass = "btn-default"; } if (arr[i] != null && arr[i] != '') { sheetName = arr[i]; } else { sheetName = "sheet" + i; } sheetstr += '
' + sheetName + '
'; } sheetstr += '
'; $('#viewFile_top').html(sheetstr); // console.log(arr); //获取excel数据,前端渲染 sheetName = arr[0]; viewFile_open(id, sheetName, layerType); } }); } //赋值并打开页面 function viewFile_open(id, sheetName, layerType) { //先清空excel div $('#viewFile_bottom').html(''); //等待 top.layer.load(1); //sheet赋值 $('#sheet').val(sheetName); //creatId赋值 $('#creatId').val(id); $.post(ext.contextPath + '/report/rptCreate/viewFile.do', { id: id, sheetName: sheetName, layerType: layerType }, function (data) { var end = data; $('#viewFile_bottom').html(end); $('#viewFile_bottom td').addClass("viewFile-td"); //获取并加载日志 getLog('cal'); //关闭等待 top.layer.closeAll('loading'); //前端后端 XY转化 setCellsInfo(); }); layer.open({ type: 1, title: '报表预览', area: '95%', skin: 'bgfff', //没有背景色 maxmin: true, shadeClose: true, closeBtn: '1', content: $('#viewFile'), success: function (layero, index) { //弹出层加载成功后执行 } }); } //仅赋值---切换sheet function viewFile(id, sheetName, layerType, ele) { if (ele != null && ele != undefined) { $(ele).siblings().removeClass("btn-primary"); $(ele).siblings().removeClass("btn-default"); $(ele).siblings().addClass("btn-default"); $(ele).removeClass("btn-default"); $(ele).addClass("btn-primary"); } //先清空excel div $('#viewFile_bottom').html(''); //等待 top.layer.load(1); //给sheet赋值 $('#sheet').val(sheetName); $.post(ext.contextPath + '/report/rptCreate/viewFile.do', { id: id, sheetName: sheetName, layerType: layerType }, function (data) { var end = data; $('#viewFile_bottom').html(end); $('#viewFile_bottom td').addClass("viewFile-td"); //获取并加载日志 getLog('cal'); //关闭等待 top.layer.closeAll('loading'); //前端后端 XY转化 setCellsInfo(); }); } //渲染后的table 右键事件 function tabClickRight() { var td = event.srcElement; // 通过event.srcElement 获取激活事件的对象 td if (td.parentElement.rowIndex != 'undefined' && td.parentElement.rowIndex != undefined && td.cellIndex != 'undefined' && td.cellIndex != undefined) { // var posx = td.cellIndex; // var posy = td.parentElement.rowIndex; var posx = td.cellIndex; var posy = td.parentElement.rowIndex; // alert(posx + '------' + posy); $('#tableLog').bootstrapTable('destroy'); $("#tableLog").bootstrapTable({ // 对应table标签的id url: ext.contextPath + '/report/rptLog/getList.do', // 获取表格数据的url cache: false, // 设置为 false 禁用 AJAX 数据缓存, 默认为true striped: true, //表格显示条纹,默认为false pagination: true, // 在表格底部显示分页组件,默认false pageList: [200], // 设置页面可以显示的数据条数 pageSize: 200, // 页面数据条数 pageNumber: 1, // 首页页码 paginationDetailHAlign: ' hidden',//去除分页的显示 sidePagination: 'server', // 设置为服务器端分页 queryParams: function (params) { // 请求服务器数据时发送的参数,可以在这里添加额外的查询参数,返回false则终止请求 return { rows: params.limit, // 每页要显示的数据条数 page: params.offset / params.limit + 1, // 每页显示数据的开始页码 sort: params.sort, // 要排序的字段 order: params.order, createId: $('#creatId').val(), posx: posx, posy: posy } }, sortName: 'insdt', // 要排序的字段 sortOrder: 'desc', // 排序规则 columns: [ { field: '', // 返回json数据中的name title: '修订前值', // 表格表头显示文字 align: 'center', // 左右居中 valign: 'middle', // 上下居中 width: '25%', formatter: function (value, row, index) { return row.beforeValue; } }, { field: '', // 返回json数据中的name title: '修订值', // 表格表头显示文字 align: 'center', // 左右居中 valign: 'middle', // 上下居中 width: '25%', formatter: function (value, row, index) { return row.afterValue; } }, { field: '', // 返回json数据中的name title: '修订人', // 表格表头显示文字 align: 'center', // 左右居中 valign: 'middle', // 上下居中 width: '25%', formatter: function (value, row, index) { if (row.user != null && row.user != '') { return row.user.caption; } } }, { field: '', // 返回json数据中的name title: '修订时间', // 表格表头显示文字 align: 'center', // 左右居中 valign: 'middle', // 上下居中 width: '25%', formatter: function (value, row, index) { return row.insdt.substring(0, 19); } } ], onLoadSuccess: function (data) { //加载成功时执行 adjustBootstrapTableView("tableLog"); if (data.total > 0) { layer.open({ type: 1, title: false, area: '50%', skin: 'bgfff', //没有背景色 maxmin: false, content: $('#viewHis'), cancel: function () {//获取右上角关闭事件 //无 } }); } }, onLoadError: function () { //加载失败时执行 console.info("加载数据失败"); } }); } } /** * 转换前端和excel XY公式 */ function setCellsInfo() { var rowSpanAll = []; var objTab = document.getElementById('t1') // 遍历表格 for (var i = 0; i < objTab.rows.length; i++) { var posTempX = 1 // var rowSpanAll_row =[] for (var j = 0; j < objTab.rows[i].cells.length; j++) { var cellItem = objTab.rows[i].cells[j] cellItem.id = 'cell-' + Math.floor(Math.random() * 1000000) if (j > 0) { posTempX += objTab.rows[i].cells[j - 1].colSpan } var realRow = i + 1 // 行 var realCol = posTempX // console.log("默认第"+realRow+"行初始列", realCol) if (rowSpanAll.length > 0) { rowSpanAll.forEach(function (rowSpanObj) { if (rowSpanObj.row < realRow && rowSpanObj.rowSpanNum > 0 && realCol >= rowSpanObj.col) { // console.log("默认第"+realRow+"行加", rowSpanObj) realCol += rowSpanObj.colSpanNum } // else{ // console.log("默认第"+realRow+"行未加", rowSpanObj) // } }) } cellItem.setAttribute('posx', realCol) cellItem.setAttribute('posy', realRow) if (cellItem.rowSpan > 1) { var obj = {} obj['rowSpanNum'] = cellItem.rowSpan obj['colSpanNum'] = cellItem.colSpan obj['row'] = realRow obj['col'] = realCol rowSpanAll.push(obj) rowSpanAll.sort(function (a, b) { return a.col - b.col }) } } // rowSpanAll= rowSpanAll_row.concat(rowSpanAll) if (rowSpanAll.length > 0) { rowSpanAll.forEach(function (rowSpanObj) { rowSpanObj.rowSpanNum-- }) } } } //渲染后的table 左键事件 function tabClickLeft(type, cellId) { var box = document.getElementById(cellId); //excel中的X var posx_e = box.getAttribute("posx"); //excel中的Y var posy_e = box.getAttribute("posy"); var td = event.srcElement; // 通过event.srcElement 获取激活事件的对象 td if (td.parentElement.rowIndex != 'undefined' && td.parentElement.rowIndex != undefined && td.cellIndex != 'undefined' && td.cellIndex != undefined) { var str = td.innerHTML; var reg = RegExp(/button/); //如果包含button则为有事件的单元格 不参与修改值 if (str.match(reg)) { //if (str.match('确认区域')) { layer.confirm("是否确认该时间段内数据?", {icon: 3, title: '提示'}, function (index) {//确认 var sheet = $('#sheet').val(); var creatId = $('#creatId').val(); // var type = type; var posx = td.cellIndex; var posy = td.parentElement.rowIndex; var userId = '${userId}'; $.post(ext.contextPath + '/report/rptLog/doupdate.do', { sheet: sheet, creatId: creatId, type: type, posx: posx, posy: posy, userId: userId, val: 0 }, function (data) { // }); td.innerHTML = '${userName}'; layer.close(index); }, function (index) {//取消 layer.close(index); }); } else { layer.prompt({value: str}, function (val, index) { td.innerHTML = val;//设置单击单元格的值 var sheet = $('#sheet').val(); var creatId = $('#creatId').val(); // var type = type; var posx = td.cellIndex; var posy = td.parentElement.rowIndex; if (str == null || str == '' || str == ' ') { str = 0; } //去除输入过程中的空格 不然无法识别 val = val.replace(/\s*/g, ""); if (val != null && val != '') { //正常的 $.post(ext.contextPath + '/report/rptLog/dosave.do', { sheet: sheet, creatId: creatId, type: type, posx: posx,//table中的x posy: posy,//table中的y posx_e: posx_e,//excel中的x posy_e: posy_e,//excel中的y beforeValue: str,//修改前的值 afterValue: val //修改后的值 }, function (data) { }); } else { //空格 $.post(ext.contextPath + '/report/rptLog/dosave4Space.do', { sheet: sheet, creatId: creatId, type: type, posx: posx,//table中的x posy: posy,//table中的y posx_e: posx_e,//excel中的x posy_e: posy_e,//excel中的y beforeValue: str,//修改前的值 afterValue: '' //修改后的值 }, function (data) { }); } layer.close(index); }); } } } //获取数据修改日志 function getLog(type) { var sheet = $('#sheet').val(); var creatId = $('#creatId').val(); $.post(ext.contextPath + '/report/rptCreate/getCreateById.do', { id: creatId }, function (data) { var create_json = $.parseJSON(data); $.post(ext.contextPath + '/report/rptLog/getJson.do', { sheet: sheet, creatId: creatId, type: type }, function (data) { var json = $.parseJSON(data); if (json != null && json.length > 0) { for (let i = 0; i < json.length; i++) { if (json[i].type == 'cal') { var y = parseInt(json[i].posy); var x = $("tr:eq(" + y + ")"); if (json[i].afterValue != null && json[i].afterValue != '') { x.find("td").eq(json[i].posx).text(json[i].afterValue);//afterValue if (create_json.status != 'finish') { x.find("td").eq(json[i].posx).css('background-color', '#33CCCC'); } } else { // x.find("td").eq(json[i].posx).text('');//afterValue } } } } }); }); } //确认数据方法 function confirmData() { var td = event.srcElement; // 通过event.srcElement 获取激活事件的对象 td layer.confirm("是否确认该时间段内数据?", {icon: 3, title: '提示'}, function (index) {//确认 var sheet = $('#sheet').val(); var creatId = $('#creatId').val(); var type = '${RptSpSet_Type_Confirm}'; var posx = td.cellIndex; var posy = td.parentElement.rowIndex; var userId = '${userId}'; $.post(ext.contextPath + '/report/rptLog/doupdate.do', { sheet: sheet, creatId: creatId, type: type, posx: posx, posy: posy, beforeValue: '',//修改前的值 afterValue: '' //修改后的值 }, function (data) { // }); td.innerHTML = '${userName}'; layer.close(index); }, function (index) {//取消 layer.close(index); }); }