/*通用表报对象*/
function Reporter(url, queryButton, container, companyid, hotelname) {
this.elements.btnQuery = queryButton;
this.elements.Container = container;
this.url = url;
//this.systemParameter.CompanyID = CompanyID;
//this.systemParameter.HotelName = hotelName;
}
Reporter.prototype = {
viewer: null,
systemParameter: {
// CompanyID: null,
// HotelName: null
},
url: null,
elements: {
Container: null,
btnQuery: null,
},
options: {},
//需要实现 初始化请求参数
onBeforQuery: null,
//需要实现 查询验证
validate: null,
//需要实现 查询完成后事件
onAfterQuery: null,
//需要实现 页面事件绑定
bindPageEvent: null,
init: function () { //初始化加载
if (this.bindPageEvent) this.bindPageEvent();
// this.bindQuery();
this.query();
this.ReplaceExportLink(); //重新替换下载按钮名称,解决条件查询后下载文件名字未变
this.RemoveSidebar(true); //移除手动输入参数框
},
bindQuery: function () { //查询按钮
/* var context = this;
$(this.elements.btnQuery).click(function () {
// var isRun = true;
// if (context.validate) isRun = context.validate();
// if (!isRun) return; //验证查询参数
context.query();
context.ReplaceExportLink(); //重新替换下载按钮名称,解决条件查询后下载文件名字未变
context.RemoveSidebar(true); //移除手动输入参数框
});*/
},
query: function () {
var context = this;
if (context.onBeforQuery) context.onBeforQuery();
context.createViewer();
if (context.onAfterQuery) context.onAfterQuery();
},
createViewer: function (callback) {
var context = this;
context.viewer = GrapeCity.ActiveReports.Viewer({
element: context.elements.Container,
reportService: {
url: "/ActiveReports.ReportService.asmx"
},
uiType: "desktop",
report: {
id: context.url, //报表文件路径
parameters: context.getParameters() //查询参数
},
availableExports: ['Xls', 'Pdf', 'Word'], //导出显示按钮
// availableExports: ['Xls', 'Pdf', 'Word', 'Image', 'Mht'],
//localeUri: '../../Scripts/Report/i18n/zh.txt',
documentLoaded: function (rrr, rer) {
if (callback) callback();
},
reportLoaded: function (info) {
}
});
// reportviewer = context.viewer;
},
getParameters: function () {
var context = this;
var params = context.options;
// var sysParams = [
//{ 'name': 'CompanyID', 'value': context.systemParameter.CompanyID },
//{ 'name': 'HotelName', 'value': context.systemParameter.HotelName },
//{'name': 'Lang', 'value': _language}
// ];
//合并系统参数和业务参数
var result = params; // .concat(sysParams);
return result;
},
print: function () {
var context = this;
if (context.onBeforQuery) context.onBeforQuery();
if (context.viewer) {
context.viewer.print();
} else {
context.createViewer(function () { context.viewer.print() });
}
},
//替换下载链接
ReplaceExportLink: function () {
var list = ["PDF Document", "Excel Workbook", "Word Document", "Image File"];
for (var i = 0; i < list.length; i++) {
var excelLink = $('a:contains("' + list[i] + '")');
ko.cleanNode(excelLink[0]);
excelLink.removeAttr('data-bind');
excelLink.removeAttr('disabled');
excelLink.attr('target', '_blank');
excelLink.attr('href', 'javascript: customExport(\"' + list[i] + '\")');
}
},
//替换下载文件名字
ReplaceExportFileName: function (extype) {
var context = this;
switch (extype) {
case 'PDF Document':
context.viewer.export("Pdf", function (uri) { window.open(uri); }, true, { FileName: vm.FileName });
break
case 'Excel Workbook':
context.viewer.export("Xls", function (uri) { window.open(uri); }, true, { FileName: vm.FileName });
break;
case 'Word Document':
context.viewer.export("Word", function (uri) { window.open(uri); }, true, { FileName: vm.FileName });
break;
case 'Image File':
context.viewer.export("Image", function (uri) { window.open(uri); }, true, { FileName: vm.FileName });
break;
}
},
//删除手动输入参数框,连续加载
RemoveSidebar: function (ishide) {
if (ishide) {
// $(".btn-toolbar.toolbar.toolbar-top div:first").hide();
//$(".btn-toolbar.toolbar.toolbar-top div:first").remove();
$(".btn-toolbar.toolbar.toolbar-top div").eq(0).remove();
$(".btn-toolbar.toolbar.toolbar-top div").eq(2).remove();
$(".btn-toolbar.toolbar.toolbar-top div").eq(3).remove();
$(".btn-toolbar.toolbar.toolbar-top div").eq(3).remove();
}
}
}
function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) return decodeURI(r[2]); return null;
} |