/** * 报表展示界面,获取报表相关数据并展示在界面上 * 2016-12-20 添加图表展示功能,在弹出窗口中展示. */ define(function(require, exports, module) { var GridAdapter = require('../../adapter/datagridAdapter'); var QueryPanelAdapter = require('../../adapter/querypanelAdapter'); var ToolbarAdapter = require('../../adapter/toolbarAdapter'); var PaginationAdapter = require('../../adapter/paginationAdapter'); var EchartsAdapter = require('../../adapter/echartsAdapter'); var Printwindow = require('./printwindow/printwindow'); var ChartWindow = require('./chartwindow/chartwindow'); var GridStyleWindow = require('./gridstylewindow/gridstylewindow'); var FullScreenGrid = require('./fullscreenwindow/fullscreengrid'); var FullScreenChart = require('./fullscreenwindow/fullscreenchart'); require('./basicReport.css'); var echarts = require('vendor/echarts/echarts.min'); require('vendor/canvas/html2canvas.js'); require('vendor/canvas/canvas2image.js'); var rptFormatDomStr = '
报表样式:
'; var remarkWindowStr = '
确定
'; var backShowTandQStr = '
筛选条件
展开
'; var areaHideButton = '
收起
'; var refreshallButton = '
刷新
'; function PageReport(args) { this.id = createGuid(); this.paginited = false; } PageReport.prototype.init = function() { this.fillPageBody(); this.initPrintOption(); this.initToolbar(); this.initFullScreenToolbar(); // this.initRptFormats(); this.initQueryPanel(); this.initQpHideButton(); this.initGrid(); this.listenResize(); // this.initPagination(); this.parseVK(); addHideButton(); this.initButtonEvent(); this.initChartFold(); this.chartResize(); }; PageReport.prototype.initChartFold = function() { var self = this; $('.chart-fold').on('click', function() { $('.chart-fold').css('display', 'none'); $('.chart-unfold').css('display', 'inline-block'); $('.chart-toolbar').addClass('chart-toolbar-fold'); $('.chart-name').text('图形展示'); $('.chart-content').css('display', 'none'); var buttonsList = [{ fieldname: 'chartfullscreen', dispname: '全屏', class: '', hint: '全屏', opcode: 'chartfullscreen' }]; changeChartToolbar(self, buttonsList); }); $('.chart-unfold').on('click', function() { $('.chart-fold').css('display', 'inline-block'); $('.chart-unfold').css('display', 'none'); $('.chart-toolbar').removeClass('chart-toolbar-fold'); self.initChartsContent(); // $('.chart-content').css('display', 'block'); var buttonsList = [{ fieldname: 'download', dispname: '下载', class: '', hint: '下载', opcode: 'download' }, { fieldname: 'chartfullscreen', dispname: '全屏', class: '', hint: '全屏', opcode: 'chartfullscreen' }]; changeChartToolbar(self, buttonsList); }); } PageReport.prototype.getDetailRows = function() { var self = this; var rows = this.gridadp.getRows(); if (self.dataManager.groupFields.length == 0) return rows; var detailRows = _.where(rows, {'isRptGroupRow': '0'}); return detailRows; }; /** * 获取设置的图表展示格式等数据 * @param {string} rptFormatId 报表样式ID */ function getRptFormatChart(rptFormatId) { var params = { rptFormatId: rptFormatId, sync: true }; var data = ER.services.formatchart(params); return data; // initChartsOptions(data.rows); } PageReport.prototype.initChartsContent = function() { var self = this; if (!self.chartFormat) self.chartFormat = getRptFormatChart(self.dataManager.rptFormatId); if ( self.chartFormat.rows.length == 0 ) { self.chartsContainer.css('display', 'none'); return; } var rows = self.getDetailRows(); if (rows.length == 0) { self.chartsContainer.find('.chart-content').css('display', 'none'); self.chartsContainer.find('.chart-toolbar').css('border-bottom', '1px solid #d6d6d6'); // ER.messager.tip('没有数据可以展示!'); return; } else { self.chartsContainer.find('.chart-toolbar').css('border-bottom', 'none'); self.chartsContainer.find('.chart-content').css({ 'border-bottom': '1px solid #d6d6d6', 'display': 'block' }); } this.chartsadapter = new EchartsAdapter({ dataManager: self.dataManager, rptFormatId: self.dataManager.rptFormatId, chartFormat: self.chartFormat, rows: rows, cb: function(options) { if (!options || options.length ===0) { self.chartsContainer.css('display', 'none'); return; } $('.chart-show-container').empty(); $('.chart-disp').empty(); self.addSVG(options); for (var i = 0; i < options.length; i++) { self.addChart(options[i], i); } $svg = $('.chart-show-container > svg'); var svglen = $svg.length; chartRemarkHeightAutofit(svglen); for (var i = 0; i < svglen; i++) { var classname = $svg[i].getAttribute('data-name'); $('.' + classname).on('click', function(e) { $('.chart-disp > svg').remove(); $svg.addClass('icon-chart-selected'); $(this).removeClass('icon-chart-selected'); var chartclass = e.currentTarget.getAttribute('data-name').split('-')[1]; var chartid = $('.chart-disp .' + chartclass)[0].id; var serialno = chartid.split('-')[0]; changeChartRemarkAndName(options, parseInt(serialno)); $('.chart-disp > div').css("display", "none"); $('.chart-disp .' + chartclass)[0].style.display = "block"; var opLen = $('.' + chartclass).length; if (opLen > 1) { $('.chart-disp > svg').remove(); $('.chart-disp').prepend(''); $('.chart-disp').append(''); $('.chart-disp .last').on('click', function() { var index = 0; var $div = $('.chart-disp').children(); for (var i = 0; i < $div.length; i++) { if ($div[i].style.display === "block") { index = parseInt($div[i].id.charAt($div[i].id.length - 1)); } } if (index === 0) { return; } --index; if (index === opLen - 2) { $('.chart-disp .next').removeClass('chart-arrow-disabled'); $('.chart-disp .next').addClass('chart-arrow-enabled'); } var chartid = $('.chart-disp .' + chartclass)[index].id; var serialno = chartid.split('-')[0]; changeChartRemarkAndName(options, parseInt(serialno)); $('.chart-disp > div').css("display", "none"); $('.' + chartclass)[index].style.display = "block"; if (index === 0) { $('.chart-disp .last').removeClass('chart-arrow-enabled'); $('.chart-disp .last').addClass('chart-arrow-disabled'); return; } }); $('.chart-disp .next').on('click', function() { var index = 0; var $div = $('.chart-disp').children(); for (var i = 0; i < $div.length; i++) { if ($div[i].style.display === "block") { index = parseInt($div[i].id.charAt($div[i].id.length - 1)); } } if (index === opLen - 1) { return; } ++index; if (index === 1) { $('.chart-disp .last').removeClass('chart-arrow-disabled'); $('.chart-disp .last').addClass('chart-arrow-enabled'); } var chartid = $('.chart-disp .' + chartclass)[index].id; var serialno = chartid.split('-')[0]; changeChartRemarkAndName(options, parseInt(serialno)); $('.chart-disp > div').css("display", "none"); $('.' + chartclass)[index].style.display = "block"; if (index === opLen - 1) { $('.chart-disp .next').removeClass('chart-arrow-enabled'); $('.chart-disp .next').addClass('chart-arrow-disabled'); return; } }); } }); } var classname = $svg[0].getAttribute('data-name'); $('.' + classname).click(); $('.chart-show-container > svg:eq(0)').removeClass('icon-chart-selected'); changeChartRemarkAndName(options, 0); } }); }; PageReport.prototype.parseVK = function() { $.parser.parse('.vk-window'); } PageReport.prototype.initPrintOption = function() { var self = this; var printData = getPrintData(self.dataManager.rptId); self.extraPrintSubMenus = makePrintMenuButtons(printData.rows) if (printData.rows.length > 0) { self.defaultPrintObj = _.where(printData.rows, {isdefault: '1'})[0]; } }; PageReport.prototype.initButtonEvent = function() { var self = this; self.queryContainer.find('.area-hide-button').on('click', function(e){ showToolbarAndQuerypanel(); }) self.queryContainer.find('.page-fresh-button').on('click', function(e) { setTimeout(function() { if (!self.beforeSearch()) return; self.searchData({ pageIndex: 0, buttonClass: e.target }); }, 600); }); }; PageReport.prototype.fillPageBody = function() { this.container = $('
'); $('body').append(this.container); this.rptFormatContainer = $(rptFormatDomStr); this.toolContainer = $('
'); this.toolContainerFullScreen = $('
'); this.queryContainer = $('
'); this.gridContainer = $('
'); this.paginationContainer = $('
'); this.chartsContainer = $('
'); this.chartToolbar = $('
'); this.chartContent = $('
'+ '
'+ '
'+ '
'+ '
'+ '
图形说明
'+ '
'+ '
'+ '
'); this.chartToolbar.append('图表展示' + ''+ '' + '' + '' + ''+ '展开'+ ''+ '' + '' + '' + ''+ '收起'+ ''); this.chartsContainer.append(this.chartToolbar) .append(this.chartContent); this.container .append(this.queryContainer) .append(this.chartsContainer) .append(this.toolContainer) .append(this.toolContainerFullScreen) // .append(this.rptFormatContainer) .append(this.gridContainer) .append(this.paginationContainer); }; PageReport.prototype.initRptFormats = function() { this.queryContainer.find('.querypanel-container') // .prepend($(rptFormatDomStr)); $.parser.parse($('.page-rptformt-select')) var self = this; var seDom = this.container.find('.rptformat-selector'); seDom.combobox({ valueField: 'rptformatid', textField: 'formatname', onChange: function(nv, ov) { if (nv == '' || nv == ov) return; if (nv == self.dataManager.rptFormatId) return; ER.services.searchSchema({ rptId: self.dataManager.rptId, rptFormatId: nv }, function (isok, data) { if (isok) { self.makeDataFromSchema(data, self.dataManager.rptFormats); self.removeRptFormat(); self.removeQueryPanel(); self.removeDatagrid(); self.initQueryPanel(); self.initGrid(); if (self.paginited) { self.removePagination(); // self.initPagination(); } } }); } }) .combobox('loadData', self.dataManager.rptFormats) .combobox('setValue', self.dataManager.rptFormatId); seDom.next('span').find('input:eq(0)').attr('readonly', true); }; PageReport.prototype.getGridFooterShowInfo = function() { var show = true; for (var i = 0; i < this.dataManager.rptResultCols.length; i++) { show = show && this.dataManager.rptResultCols[i].statType == '0' } this.showFooter = !show; }; PageReport.prototype.showGridFooter = function() { if (this.showFooter) this.gridadp.setFooterFirstColumnContent('统计'); }; PageReport.prototype.initGrid = function() { var self = this; var columnMoving = self.dataManager.groupFields.length > 0 ? false : true; var imgcols = _.where(self.dataManager.rptResultCols, {'isImgColumn': true}); if (imgcols && imgcols.length > 0) { if (self.gridContainer) { self.gridContainer.addClass('page-grid-hasimgcol'); } } this.gridadp = new GridAdapter({ id: this.id, name: '', data: this.dataManager, opts: { columnMoving: columnMoving }, actions: { onDblClickCell: function(index, field, value) { self.onDblClickCell(index, field, value); }, onLoadSuccess: function(data) { resetImgSize(); } } }); this.getGridFooterShowInfo(); var gridHeight = this.calGridHeight(); this.gridadp.makeGridRowStyler(); this.gridadp.makeGridProperties({ // height: gridHeight, // singleSelect: true, showFooter: this.showFooter, rownumbers: true, ctrlSelect: true }); this.gridadp.init(this.gridContainer); }; function resetImgSize() { var colImgs = $('.frr-imgcol-img'); var length = colImgs.length; if (length > 0) ER.loading(); _.each(colImgs, function(item, index) { item.onload = function() { var h = $(this).height() / $(this).parent().height(); var w = $(this).width() / $(this).parent().width(); $(this).data({ width: w, height: h }); if (h > w) { $(this).css({ width: 'auto', height: 'inherit', display: 'block' }); } else { $(this).css({ width: 'inherit', height: 'auto', display: 'block' }); } } if (index == length - 1) { ER.loaded(); } }); } PageReport.prototype.initQpHideButton = function() { this.queryContainer.find('.querypanel-container') .append($(refreshallButton)) .append($(areaHideButton)); }; PageReport.prototype.initToolbar = function() { var self = this; var rptNameDiv = $('
'+ self.dataManager.dataObjName +'
'); this.toolContainer.append(rptNameDiv); var menuButtons = [ { fieldname: 'export', dispname: '导出', icon: 'icon-print', class: '', hint: '退出', opcode: 'export', subButtons: [ { fieldname: 'exportcurrent', dispname: '导出当前页', icon: 'icon-print', class: '', hint: '导出当前页', opcode: 'exportcurrent' }, { fieldname: 'exportall', dispname: '导出全部', icon: 'icon-print', class: '', hint: '导出全部', opcode: 'exportall' } ] }, { fieldname: 'fitcolumn', dispname: '表格自适应', icon: 'icon-print', class: '', hint: '表格自适应', opcode: 'fitcolumn', subButtons: [ { fieldname: 'fitcolumnauto', dispname: '自动铺满', icon: 'icon-print', class: '', hint: '自动铺满', opcode: 'fitcolumnauto' }, { fieldname: 'fitcolumnset', dispname: '按后台设置', icon: 'icon-print', class: '', hint: '按后台设置', opcode: 'fitcolumnset' } ] } ]; if (self.extraPrintSubMenus) menuButtons.push(self.extraPrintSubMenus); this.tooladp = new ToolbarAdapter({ pageId: this.id, container: this.toolContainer, buttons: [ { fieldname: 'printset', dispname: '打印设置', // icon: 'icon-print', class: '', hint: '打印设置', opcode: 'printset' }, { fieldname: 'girdstyleset', dispname: '表格样式设置', // icon: 'icon-print', class: '', hint: '表格样式设置', opcode: 'girdstyleset' }, { fieldname: 'girdstylesave', dispname: '表格样式保存', // icon: 'icon-print', class: '', hint: '表格样式保存', opcode: 'girdstylesave' }, { fieldname: 'rptremark', dispname: '报表说明', // icon: 'icon-detail', class: '', hint: '报表说明', opcode: 'rptremark' }, { fieldname: 'gridfullScreen', dispname: '全屏', // icon: 'icon-remove', class: '', hint: '全屏', opcode: 'gridfullScreen' }], menuButtons: menuButtons, actions: { click: function(opcode) { self.opRouter(opcode); } } }); this.tooladp.init(); this.charttooladp = new ToolbarAdapter({ pageId: this.id, container: this.chartToolbar.find('.chart-in-toolbar'), buttons: [{ fieldname: 'chartfullscreen', dispname: '全屏', // icon: 'icon-remove', class: '', hint: '全屏', opcode: 'chartfullscreen' }], actions: { click: function(opcode) { self.opRouter(opcode); } } }); this.charttooladp.init(); }; PageReport.prototype.initFullScreenToolbar = function() { var self = this; var rptNameDiv = $('
'+ self.dataManager.dataObjName +'
'); this.toolContainerFullScreen.append(rptNameDiv); var menuButtons = [ { fieldname: 'export', dispname: '导出', icon: 'icon-print', class: '', hint: '退出', opcode: 'export', subButtons: [ { fieldname: 'exportcurrent', dispname: '导出当前页', icon: 'icon-print', class: '', hint: '导出当前页', opcode: 'exportcurrent' }, { fieldname: 'exportall', dispname: '导出全部', icon: 'icon-print', class: '', hint: '导出全部', opcode: 'exportall' } ] }, { fieldname: 'fitcolumn', dispname: '表格自适应', icon: 'icon-print', class: '', hint: '表格自适应', opcode: 'fitcolumn', subButtons: [ { fieldname: 'fitcolumnauto', dispname: '自动铺满', icon: 'icon-print', class: '', hint: '自动铺满', opcode: 'fitcolumnauto' }, { fieldname: 'fitcolumnset', dispname: '按后台设置', icon: 'icon-print', class: '', hint: '按后台设置', opcode: 'fitcolumnset' } ] } ]; if (self.extraPrintSubMenus) menuButtons.push(self.extraPrintSubMenus); this.tooladpFullScreen = new ToolbarAdapter({ pageId: this.id, container: this.toolContainerFullScreen, buttons: [{ fieldname: 'switchtochart', dispname: '切换到图形', class: '', hint: '切换到图形', opcode: 'switchtochart' }, { fieldname: 'refresh', dispname: '刷新', // icon: 'icon-refresh', class: '', hint: '刷新', opcode: 'refresh' }, { fieldname: 'printset', dispname: '打印设置', // icon: 'icon-print', class: '', hint: '打印设置', opcode: 'printset' }, { fieldname: 'girdstyleset', dispname: '表格样式设置', // icon: 'icon-print', class: '', hint: '表格样式设置', opcode: 'girdstyleset' }, { fieldname: 'girdstylesave', dispname: '表格样式保存', // icon: 'icon-print', class: '', hint: '表格样式保存', opcode: 'girdstylesave' }, { fieldname: 'rptremark', dispname: '报表说明', // icon: 'icon-detail', class: '', hint: '报表说明', opcode: 'rptremark' }, { fieldname: 'closeFullScreen', dispname: '关闭', // icon: 'icon-remove', class: '', hint: '关闭', opcode: 'closeFullScreen' }], menuButtons: menuButtons, actions: { click: function(opcode) { self.opRouter(opcode); } } }); this.tooladpFullScreen.init(); }; PageReport.prototype.initQueryPanel = function() { this.qpanel = new QueryPanelAdapter({ pageId: this.id, container: this.queryContainer, data: this.dataManager.rptResultCols, opts: { needFilter: true } }); this.initRptFormats(); }; PageReport.prototype.initPagination = function() { var self = this; if (this.paginited) { return ; } else { this.paginited = true; } this.pagepanel = new PaginationAdapter({ pageSize: this.dataManager.pageSize, totalRows: this.dataManager.totalRows, container: this.paginationContainer, actions: { click: function(opcode, pageIndex) { self.pageopRouter(opcode, pageIndex); // if ($('.chart-fold').css("display") !=='none') { // self.initChartsContent(); // } } } }); }; PageReport.prototype.removeQueryPanel = function() { this.container.find('.page-querypanel').empty(); }; PageReport.prototype.removeRptFormat = function() { this.container.find('.page-rptformt-select').remove(); }; PageReport.prototype.removeDatagrid = function() { this.container.find('.page-grid').empty(); }; PageReport.prototype.removePagination = function() { this.container.find('.page-pagination').empty(); this.paginited = false; }; PageReport.prototype.opRouter = function(opcode) { var self = this; if ( opcode.indexOf('printdata') > -1 ) { var serialno = opcode.split('-')[1]; self.activePrinter(serialno, 0); return; } switch (opcode) { case 'cancel': break; case 'printdefault': if (self.defaultPrintObj) { self.activePrinter(self.defaultPrintObj.serialno, 0); } else { ER.messager.tip('没有默认打印格式!'); return; } break; case 'refresh': setTimeout(function() { if (!self.beforeSearch()) return; self.searchData({ pageIndex: 0 }); }, 600); break; case 'exportcurrent': if (!self.paginited) return; var pageIndex = self.pagepanel.getPageInfo().pageIndex - 1; self.getExportDatas(pageIndex) break; case 'exportall': if (!self.paginited) return; self.getExportDatas(-1); break; case 'fitcolumnauto': if (self.columnfitstyle === opcode) return; self.columnfitstyle = opcode; self.gridadp.fitColumns() if (!self.paginited) return; var groupField = _.where(self.dataManager.groupFields, {'isGroupField': '1'})[0]; self.searchData({ isSearch: groupField ? '1': '0', pageIndex: self.pagepanel.getPageInfo().pageIndex - 1 }); break; case 'fitcolumnset': if (self.columnfitstyle === opcode) return; self.columnfitstyle = opcode; self.gridadp.resetColumns() if (!self.paginited) return; var groupField = _.where(self.dataManager.groupFields, {'isGroupField': '1'})[0]; self.searchData({ isSearch: groupField ? '1': '0', pageIndex: self.pagepanel.getPageInfo().pageIndex - 1 }); break; case 'printset': var pwin = new Printwindow(self.makePrintData()); pwin.open(); break; case 'rptremark': if ($('.remark-window-container').length == 0) { $('body').append(remarkWindowStr); $('.fdpr-rpt-remark-window .remark-text').append(self.dataManager.remark) $('.fdpr-rpt-remark-window') .window({ width:600, height:400, modal:true }); } $('.fdpr-rpt-remark-window .button-ok').off('click').on('click', function(e) { $('.fdpr-rpt-remark-window').window('close'); }); $('.fdpr-rpt-remark-window').window('open'); break; case 'chartfullscreen': // if (!self.dataManager.nowRows || self.dataManager.nowRows.length == 0) { // ER.messager.tip('没有数据可以展示!'); // return; // } // new EchartsAdapter({ // dataManager: self.dataManager, // rptFormatId: self.dataManager.rptFormatId, // cb: function(options) { // var cw = new ChartWindow(options); // cw.open(); // } // }); var fullScreenArgs = { fullScreenGrid: FullScreenGrid, fullScreenChart: FullScreenChart, gridfullscreenArgs: { toolbar: self.toolContainerFullScreen, grid: self.gridContainer, pagination: self.paginationContainer }, chartfullscreenArgs: { dataManager: self.dataManager, rptFormatId: self.dataManager.rptFormatId, chartFormat: self.chartFormat }, container: self.container, gridContainer: self.gridContainer, paginationContainer: self.paginationContainer, toolContainerFullScreen: self.toolContainerFullScreen }; // var fullScreenChartArgs = { // dataManager: self.dataManager, // rptFormatId: self.dataManager.rptFormatId // }; var fullScreenChart = new FullScreenChart(fullScreenArgs, function() { }); fullScreenChart.open(); self.toolContainerFullScreen.css('display', '-webkit-flex') break; case 'girdstyleset': var gridOp = self.getGridOptions(), cols = makeGridStyleCols(self), gridStyleArgs = { cols: cols, dataManager: self.dataManager }; var gwindow = new GridStyleWindow(gridStyleArgs); gwindow.open(); break; case 'girdstylesave': saveGridStyle(self); break; case 'hidetandq': showToolbarAndQuerypanel(); // showHideBar() break; case 'gridfullScreen': var fullScreenArgs = { fullScreenGrid: FullScreenGrid, fullScreenChart: FullScreenChart, gridfullscreenArgs: { toolbar: self.toolContainerFullScreen, grid: self.gridContainer, pagination: self.paginationContainer }, chartfullscreenArgs: { dataManager: self.dataManager, rptFormatId: self.dataManager.rptFormatId, chartFormat: self.chartFormat }, container: self.container, gridContainer: self.gridContainer, paginationContainer: self.paginationContainer, toolContainerFullScreen: self.toolContainerFullScreen }; // var fullScreenArgs = { // toolbar: self.toolContainerFullScreen, // grid: self.gridContainer, // pagination: self.paginationContainer // }; var fullScreenGrid = new FullScreenGrid(fullScreenArgs, function() { self.container .append(self.gridContainer) .append(self.paginationContainer) .append(self.toolContainerFullScreen); }); fullScreenGrid.open(); self.toolContainerFullScreen.css('display', '-webkit-flex') break; case 'download': var $div = $('.chart-disp').children(); for (var i = 0; i < $div.length; i++) { if ($div[i].style.display === "block") { var idname = $div[i].id; html2canvas($('#'+idname), { allowTaint: true, taintTest: false, onrendered: function(canvas) { // Canvas2Image.saveAsImage(canvas); var canvasname = $('.chart-name').text(); $('.canvas-image-container').attr('href', Canvas2Image.convertToImage(canvas).src) .attr('download', canvasname + '.jpg'); $('.canvas-image-container')[0].click() } }); } } break; default: break; } }; PageReport.prototype.remakePrintButton = function() { var self = this; var printData = getPrintData(self.dataManager.rptId); self.extraPrintSubMenus = makePrintMenuButtons(printData.rows); if (printData.rows.length > 0) { self.defaultPrintObj = _.where(printData.rows, {isdefault: '1'})[0]; } var printButton = this.toolContainer.find('.menu-printdefault'); var preButton = printButton.prev(); self.tooladp.destroyButton(printButton); self.tooladp.addMenuButtons([self.extraPrintSubMenus], preButton); //全屏按钮 var fullPrintButton = this.toolContainerFullScreen.find('.menu-printdefault'); var fullPreButton = fullPrintButton.prev(); self.tooladpFullScreen.destroyButton(fullPrintButton); self.tooladpFullScreen.addMenuButtons([self.extraPrintSubMenus], fullPreButton); }; PageReport.prototype.makePrintData = function() { var self = this; var rows = self.gridadp.getRows(); var qparams = self.getAllQueryParams(); return { selectRows: rows, printObj: self.dataManager, qParams: qparams, columns: self.gridadp.usefulColumns, cb: function() { self.remakePrintButton(); } } }; PageReport.prototype.getPrintData = function() { var self = this; var ds = self.dataManager; var data = { uiObjCode: ds.uiObjCode, uiObjName: ds.uiObjName || '打印报表', isMaster: true, fieldList: [], forPrint: [] }; var columns = self.gridadp.usefulColumns; for (var i = 0; i < columns.length; i++) { var col = columns[i]; data.fieldList.push({ fieldName: col.fieldName, fieldDes: col.dispName, dataType: col.dataType, dataWidth: col.headerWidth, dataDec: col.dataDec }); } var fArrayData = []; var rows = self.gridadp.getRows(); for (var k = 0; k < rows.length; k++) { var tempData = {}; for (var j = 0; j < data.fieldList.length; j++) { var fieldName = data.fieldList[j].fieldName; tempData[fieldName] = rows[k][fieldName]; } fArrayData.push(tempData); } data.forPrint = data.forPrint.concat(fArrayData); return [data]; }; PageReport.prototype.activePrinter = function(serialno, mod) { var self = this; var rows = self.gridadp.getRows(); if (rows.length == 0) { ER.messager.tip('沒有要打印的数据!'); return; } try { var pd = self.getPrintData(); var pv = _.extend(self.getAllQueryParams(), ER.Cache.logon); ER.services.print(self.dataManager.rptId, serialno, mod, pd, pv); return; } finally { } } PageReport.prototype.getExportDatas = function(pageNum) { var self = this; var params = { rptId: self.dataManager.rptId, rptFormatId: self.dataManager.rptFormatId, searchId: self.dataManager.searchId, pageNum: pageNum }; ER.services.exportReport(params, function(isok, data) { }) } PageReport.prototype.beforeSearch = function() { if (this.qpanel.checkRequiredEditors()) { return true; } return false; }; PageReport.prototype.searchData = function(options) { var self = this; var qparams = self.getQueryParams(); var groupField = _.where(self.dataManager.groupFields, {'isGroupField': '1'})[0]; var paras = { rptId: self.dataManager.rptId, rptFormatId: self.dataManager.rptFormatId, userCode: ER.Cache.logon.userCode, pageIndex: options.pageIndex,// isSearch: options.isSearch || '1', queryParams: qparams, groupField: groupField ? groupField.fieldName : '' }; self.dataManager.makeDataParams(paras); self.dataManager.search(function(data) { if (data.errMsg) { ER.messager.tip(data.errMsg); } self.dataManager.searchId = data[self.dataManager.rptKey].searchId || self.dataManager.searchId; if (data[self.dataManager.rptKey].totalRows === undefined) { self.dataManager.totalRows = self.dataManager.totalRows; } else { self.dataManager.totalRows = data[self.dataManager.rptKey].totalRows; } if (self.dataManager.totalRows == 0 ) { ER.messager.tip('没有数据可以展示!'); return; } var footerRow = _.where(data[self.dataManager.rptKey].rows, { 'isRptTotal': '1' }); data[self.dataManager.rptKey].rows = _.reject(data[self.dataManager.rptKey].rows, function(item) { return item.isRptTotal != undefined; }) self.initPagination(); self.loadGridData({ 'total': data[self.dataManager.rptKey].rows.length, 'rows': data[self.dataManager.rptKey].rows }); self.dataManager.nowRows = data[self.dataManager.rptKey].rows; self.pagepanel.setRefreshPages(options.pageIndex, self.dataManager.pageSize, self.dataManager.totalRows); if (self.showFooter) { self.gridadp.setFooterRow(footerRow); self.showGridFooter(); // self.gridadp.setFooterFirstColumnContent('统计'); } self.toolContainer.css('display', '-webkit-flex'); self.gridContainer.show(); self.gridadp.grid.$grid.datagrid('resize'); //刷新数据时,图形展示部分展开 self.chartToolbar.show(); if ($(options.buttonClass).text() === '刷新') { $('.chart-unfold').click(); } //分页操作时,更新图形展示部分显示数据 if ($('.chart-fold').css("display") !== 'none' && options.pageReChart == true) { self.initChartsContent(); } // 重新设置表格行高度自适应 self.gridadp.fixRowHeight(); //判断隐藏分页 if (self.dataManager.groupFields.length > 0) { self.paginationContainer.hide(); } }); } PageReport.prototype.pageopRouter = function(opcode, pageIndex) { var self = this; switch (opcode) { case 'firstPage': case 'prevPage': case 'nextPage': case 'lastPage': case 'linkPage': self.searchData({ isSearch: '0', pageIndex: pageIndex, pageReChart: true }); break; } } PageReport.prototype.getQueryParams = function() { return this.qpanel.getQueryParams(); }; PageReport.prototype.getAllQueryParams = function() { return this.qpanel.getAllQueryParams(); }; PageReport.prototype.loadGridData = function(data) { this.gridadp.loadData(data); } PageReport.prototype.fillGrid = function(first_argument) { // body... }; function makeDataManager(data) { var key = Object.keys(data)[0]; return new DataManager(data[key]); } function getkey(Obj) { var key = null, keys = Object.keys(Obj) if (keys[0] === 'Message') { key = keys[1]; } else { key = keys[0]; } return key; } PageReport.prototype.makeDataFromSchema = function(data, rptFormats, rptFormatAlarm) { var dataManager = makeDataManager(data); dataManager.rptKey = getkey(data); dataManager.rptFormatAlarm = rptFormatAlarm; if (rptFormats) dataManager.rptFormats = rptFormats; dataManager.addRptResultCol(data[dataManager.rptKey].columns); this.dataManager = dataManager; } PageReport.prototype.listenResize = function() { var self = this; window.addResizeListener(document.body, function() { self.gridadp.resize(); }) }; PageReport.prototype.calGridHeight = function() { var toolbarHeight = parseInt($('.page-toolbar').height()); var querypanelHeight = parseInt($('.page-querypanel').height()); var paginationHeight = parseInt($('.page-pagination').height() || 50); var gridHeight = window.innerHeight - toolbarHeight - querypanelHeight - paginationHeight; // $('.page-grid').height(gridHeight); $('.page-grid').css('min-height', '50px'); return gridHeight; }; PageReport.prototype.getGridOptions = function() { var options = this.gridadp.getGridOptions(); }; PageReport.prototype.addSVG = function(options) { var iconStr = ""; for (var i = 0; i < options.length; i++) { var chart = options[i]; var type = chart.type; switch (chart.type) { case 'barchart': iconStr = "histogram"; break; case 'linechart': iconStr = "line"; break; case 'areachart': iconStr = "stack"; break; case 'piechart': iconStr = "pie"; break; case 'barlinechart': iconStr = "complex"; break; } if ($('.chart-show-container .icon-'+type).length > 0) { continue; } $('.chart-show-container').append(''); } }; /** * 添加图表 * @param {object} chart 图表对象包含图表类型与对应的option */ PageReport.prototype.addChart = function(chart, index) { var container = $('.chart-disp'), className = null, idName = null, chartWidth = 800, //chartHeight = 250, chartObj = null; var i1 = $('.chart-disp .barchart').length, i2 = $('.chart-disp .linechart').length, i3 = $('.chart-disp .areachart').length, i4 = $('.chart-disp .piechart').length, i5 = $('.chart-disp .barlinechart').length; switch (chart.type) { case 'barchart': className = 'barchart'; idName = index + '-' + i1; break; case 'linechart': className = 'linechart'; idName = index + '-' + i2; break; case 'areachart': className = 'areachart'; idName = index + '-' + i3; break; case 'piechart': className = 'piechart'; idName = index + '-' + i4; break; case 'barlinechart': className = 'barlinechart'; idName = index + '-' + i5; break; } // if (chart.type != 'piechart' && chart.option.yAxis.length >= 3) { // chartWidth = chartWidth + 110 + ( (chart.option.yAxis.length - 3) * 110 ); // } // chartWidth = window.innerWidth - $('.chart-content-right').width() - 40 * 2 - 10 - 15; container.append('
'); // $('#' + idName).css('width', chartWidth); chartObj = echarts.init($('#' + idName)[0]); chartObj.setOption(chart.option); $('#'+idName).hide(); $('.chart-disp > div div:nth-child(1)').css('overflow', 'inherit'); }; PageReport.prototype.chartResize = function() { window.onresize = function() { var percent = (window.innerWidth - 240) / $('.chart-disp').width(); $('canvas').css({ 'width': function() { return window.innerWidth - 240; }, 'height': function() { if ($('.chart-disp').height() * percent > $('.chart-disp').height()) { return $('.chart-disp').height(); } else { return $('.chart-disp').height() * percent; } } }); }; }; PageReport.prototype.onDblClickCell = function(index, field, value) { // 展开时insertRow,记录插入的行数后update当前行(记录行数) // 关闭时deleteRow,这个需要删除其下所有的子行,是不是要递归了,因为不知道具体有多少子。。。 // 先递归查出所有的数据,然后删除之。。 if (_.where(this.dataManager.groupFields, {fieldName: field}).length == 0 || !value) return; var colOp = this.gridadp.getColumnOption(field), row = this.gridadp.getSelected(), allRows = this.gridadp.getRows(), rowIndex = this.gridadp.getRowIndex(row), groupValues = row.parGroupValues || '', parGroupValues = '', delValues = '' + field + '":"' + value + '', expandcell = row.expandcell || '', self = this; if (!row.expand) { parGroupValues = groupValues ? (groupValues + '","' + field + '":"' + value + '') : ('' + field + '":"' + value + ''); this.getSubRows(colOp.subGroupField, JSON.parse('{"' + parGroupValues + '"}'), function (rows) { for (var i = rows.length - 1; i >= 0; i--) { rows[i].parGroupValues = parGroupValues; rows[i].parentRow = row; // self.gridadp.insertRow(rowIndex + 1, rows[i]); } row.expand = true; row.isparent = true; row.parentField = field; row.delValues = delValues; ER.loading(); var _rows1 = allRows.splice(0, rowIndex + 1); var __rows = _rows1.concat(rows).concat(allRows); self.gridadp.loadData(__rows); resetImgSize(); self.gridadp.updateRow(rowIndex, row); self.showGridFooter(); // self.mergeCells(rowIndex, field, rows.length + 1, 'body'); var parentRows = _.where(__rows, {isparent: true}); mergeAllCells(parentRows, __rows, self); ER.loaded(); self.initChartsContent(); }) } if (row.expand) { var length = 0; for (j = allRows.length - 1; j >= 0; j--) { if (allRows[j].parGroupValues && allRows[j].parGroupValues.indexOf(delValues) > -1) { // self.gridadp.deleteRow(j); length += 1; } } row.expand = false; allRows.splice(rowIndex + 1, length); self.gridadp.loadData(allRows); self.gridadp.updateRow(rowIndex, row); var parentRows = _.where(allRows, {isparent: true}); mergeAllCells(parentRows, allRows, self); self.showGridFooter(); self.initChartsContent(); // mergeCells(self, row, rowIndex, field, 1, 'body') } }; function mergeAllCells(parentRows, allRows, self) { for (var k = 0; k < parentRows.length; k++) { var _rowIndex = self.gridadp.getRowIndex(parentRows[k]); var _length = 0; var _delValues = '' + parentRows[k].parentField + '":"' + parentRows[k][parentRows[k].parentField] + '' for (var l = allRows.length - 1; l >= 0; l--) { var flag = null; if (allRows[l].parGroupValues && allRows[l].parGroupValues.indexOf(parentRows[k].delValues) > -1) { flag = true; if (parentRows[k].parentRow && parentRows[k].parentRow.parentRow && !allRows[l].parGroupValues.indexOf(parentRows[k].parentRow.parentRow.delValues) == -1) { flag = false; } if (parentRows[k].parentRow && allRows[l].parGroupValues.indexOf(parentRows[k].parentRow.delValues) == -1) { flag = false; } if (flag) _length += 1; } } mergeCells(self, parentRows[k], _rowIndex, parentRows[k].parentField, _length + 1, 'body') } } function mergeCells(self, row, index, field, length, type){ var rows = self.gridadp.getRows(); var parentRow = []; var rowField = null; if (row.parGroupValues) { parentRow = _.filter(rows, function(item) { var flag = true; var groupArray = row.parGroupValues.split('","'); rowField = groupArray[groupArray.length - 1].split('":')[0]; for (var i = 0; i < groupArray.length; i++) { var fields = groupArray[i].split('":"'); if (item[fields[0]] != fields[1]) { flag = false; } } if (item.parGroupValues && item.parGroupValues.indexOf(groupArray[groupArray.length - 1]) > -1) { flag = false; } return flag; }); if (parentRow[0]) { var rowIndex = self.gridadp.getRowIndex(parentRow[0]); var rowsLength = _.filter(rows, function(item) { return item.parGroupValues && item.parGroupValues.indexOf(row.parGroupValues) > -1; }).length; mergeCells(self, parentRow[0], rowIndex, rowField, rowsLength + 1, type); } } self.gridadp.mergeCells(index, field, length, 'body'); } PageReport.prototype.getSubRows = function(groupField, groupFieldsValue, cb) { var dataManager = this.dataManager, dataParams = $.extend({}, dataManager.dataParams, true), datapara = dataParams['searchData'][dataManager.rptKey]; datapara.isSearch = '0'; datapara.searchId = dataManager.searchId; datapara.pageIndex = 0; datapara.groupField = groupField; datapara.groupFieldsValue = groupFieldsValue; ER.services.searchData(dataParams, function(isok, data) { if (isok) { console.log(data[dataManager.rptKey].rows); cb(data[dataManager.rptKey].rows); } }); } function getPrintData(rptId) { var params = { op: 'search', rptId: rptId, sync: true } return ER.services.setPrn(params); } function makePrintMenuButtons(rows) { var menubtn = { fieldname: 'printdefault', dispname: '打印', icon: 'icon-print', class: '', hint: '打印', opcode: 'printdefault', subButtons: [] }; for (var i = 0; i < rows.length; i++) { var row = rows[i]; var data = { fieldname: 'printdata-' + row.serialno, dispname: row.prnname, icon: 'icon-print', class: '', hint: '打印', opcode: 'printdata-' + row.serialno, } menubtn.subButtons.push(data); } return menubtn; } /** * 给gridStylewindow需要的columns数据 * @param {[type]} self [description] * @return {[type]} [description] */ function makeGridStyleCols(self) { var cols = self.dataManager.rptResultCols, _columns = []; for (var i = 0; i < cols.length; i++) { var _temp = cols[i]; if (_temp.procParaType === '0') { _columns.push(_temp); } } return _columns; } function saveGridStyle(self) { var options = self.gridadp.getGridOptions(), columns = [], frozenCols = options.frozenColumns[0], _col = null, params = {}, data = []; for (var j = 0 ; j < options.columns.length; j ++) { for (var k = 0; k < options.columns[j].length; k++) { if (!options.columns[j][k].boxWidth) { continue; } columns.push(options.columns[j][k]); } } columns = columns.concat(frozenCols); for (var i = 0; i < columns.length; i++) { _col = columns[i]; data.push({ fieldname: _col.field, dispindex: i, dispwidth: _col.boxWidth, viewable: '1' }); } params.rptId = self.dataManager.rptId; params.rptFormatId = self.dataManager.rptFormatId; params.styleList = data; ER.services.privatefmt(params, function (isok, data) { if (isok) { ER.messager.tip('保存成功,刷新界面生效!'); } }); } /** * 显示/隐藏toolbar与querypanel */ function showToolbarAndQuerypanel() { $('.page-back-show-tandp').animate({height: 'toggle', opacity: 'toggle'}, 'fast', function() { if($('.page-back-show-tandp').is(':visible')) { $(this).css('display', 'block'); } }); $('.querypanel-container').animate({height: 'toggle', opacity: 'toggle'}, 'fast'); } function addHideButton() { $('body').prepend(backShowTandQStr); $('.page-back-show-tandp .area-show-button').off('click').on('click', function(e) { showToolbarAndQuerypanel(); }) ; } function changeChartToolbar(self, buttonsList) { self.chartToolbar.find('.chart-in-toolbar').empty(); self.charttooladp = new ToolbarAdapter({ pageId: self.id, container: self.chartToolbar.find('.chart-in-toolbar'), buttons: buttonsList, actions: { click: function(opcode) { self.opRouter(opcode); } } }); self.charttooladp.init(); } function changeChartRemarkAndName(options, index) { var name = options[index].name; var remark = options[index].remark; $('.chart-name').text(name); $('.chart-remark').text(remark); } function chartRemarkHeightAutofit(svglen) { $('.chart-show-container').css({ "height": Math.ceil(svglen/2) *55 }); $('.chart-remark').css({ "height": $('.chart-content-right').height() - $('.chart-show-container').height() - 10 }); } return PageReport; });