/**
* 报表展示界面,获取报表相关数据并展示在界面上
* 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 = $('