var Birt = (function () {
var _this;
var rptDesignJsonData;
var $birt;
function Birt(designJsonData) {
_this = this;
rptDesignJsonData = designJsonData;
$birt = $('.birt');
}
/**
* 获取报表数据
* @param rptDesignName
*/
Birt.prototype.getRetDesign = function (rptDesignName) {
$.birtLoading();
$.ajax(
{
url: '/birt/api.json?_report={0}'.format(rptDesignName),
type: 'GET',
success: function (data) {
$.birtLoading('hide');
rptDesignJsonData = data.rpt_design;
_this.showDisplayName();
console.log(data.rpt_design.tables);
var tables = data.rpt_design.tables;
for (var i = 0; i < tables.length; i++) {
var table = tables[i];
_this.showTable(table);
}
},
error: function (data) {
$.birtLoading('hide');
}
}
);
};
Birt.prototype.showDisplayName = function () {
$birt.append('
{0}
'.format(rptDesignJsonData.display_name));
};
/**
* 显示行
* @param rowData
* @param cellName
* @returns {string}
*/
Birt.prototype.showTableRow = function (rowData, cellName) {
var row_html = '';
for (var i = 0; i < rowData.length; i++) {
if (cellName == 'th') {
row_html += "{0} | ".format(rowData[i]);
} else {
row_html += "{0} | ".format(rowData[i]);
}
}
row_html += '
';
return row_html;
};
/**
* 显示表格
* @param table
* @returns {string}
*/
Birt.prototype.showTable = function (table) {
var table_html = '';
for (var i = 0; i < table.header.length; i++) {
table_html += _this.showTableRow(table.header[i], 'th');
}
for (var i = 0; i < table.detail.length; i++) {
table_html += _this.showTableRow(table.detail[i], 'td');
}
table_html += "
";
$(".birt").append(table_html);
console.log(table);
return table_html;
};
return Birt;
})();