reportTemplate.js
4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/**
* 查询配置模板
*/
var ReportTemplate = function() {
var me;
return {
init : function() {
me = this;
var params = $('#reportConfigId').val();
params = params.split('=');
$('#reportConfigId').val(params[1]);
$.getJSON('/report/config/queryById', {
id : params[1]
}, function(data) {
me.parseSearchTable(data.terms);
me.parseDataGrid(params[1], data.fields);
});
},
/** 解析查询条件 */
parseSearchTable : function(terms) {
var tab = [];
for (var i = 0; i < terms.length; i++) {
var term = terms[i];
var className = '', addition = '';
var required = term.required == 1 ? 'true' : 'false';
tab.push('<li style="float: left; margin: 5px 0px;">');
tab.push('<span style="display: inline-block; width: 80px; text-align: right;">');
tab.push(term.title + ':</span>');
tab.push('<input type="text" name="' + term.sqlField + '" ');
switch (term.pageFieldType) {
case 'text':
className = 'easyui-textbox';
break;
case 'number':
className = 'easyui-numberbox';
break;
case 'calendar':
className = 'easyui-datebox';
break;
case 'select':
className = 'easyui-combobox';
addition = ', editable:false, valueField:\'sysKey\',textField:\'sysValue\',url:\'/report/config/querySysConfig?parentCode=' + term.selectKey + '\'';
break;
}
tab.push('<input type="text" name="' + term.sqlField + '"');
tab.push(' class="search-input ' + className + '"');
tab.push(' data-options="required:' + required + addition + '"');
tab.push(' />');
tab.push('</li>');
}
tab.push('<li style="float: left; margin: 5px 0px;">');
tab.push(' <a href="javascript:ReportTemplate.search()" class="easyui-linkbutton search-button" data-options="iconCls:\'icon-search\'">搜索</a>');
tab.push(' <a href="javascript:ReportTemplate.exportExcel()" class="easyui-linkbutton search-button" data-options="iconCls:\'icon-save\'">导出</a></li>');
$('#search-table').append(tab.join(''));
$.parser.parse('#search-table');
},
/**解析查询结果*/
parseDataGrid: function(id, fields) {
var columns = new Array();
for (var i = 0; i < fields.length; i++) {
var column = {}, field = fields[i];
column.field = field.fieldName;
column.title = field.title;
if (field.fieldWidth > 0) {
column.width = field.fieldWidth;
}
if (field.fieldShow == '0') {
column.hidden = true;
}
/*
* formatter方法要写成以下的格式:
(function(value, row, index) {
return value;
})
*/
if (field.formatter != '') {
column.formatter = eval(field.formatter);
}
if (field.styler != '') {
column.styler = eval(field.styler);
}
columns.push(column);
}
$('#data-grid').datagrid({
//url : '/report/config/templateQuery',
queryParams : App.dataGridQueryParams('search-form'),
columns : [columns],
showFooter : true,
onLoadSuccess : function (data) {
//-1时表示后台报错
if (data.total <= 0) {
var firstField = fields[0].fieldName;
var appendRow = new Object();
var mergeCells = { index: 0, field: firstField, colspan: fields.length };
var message = data.total == 0 ? '没有查询到数据!' : data.rows;
appendRow[firstField] = '<div style="text-align:center;color:red"><span title="' + message + '">' + message + '</span></div>';
//$(this).datagrid('deleteRow', 0);
//添加一个新数据行,第一列的值为你需要的提示信息,然后将其他列合并到第一列来,注意修改colspan参数为你columns配置的总列数
$(this).datagrid('appendRow', appendRow).datagrid('mergeCells', mergeCells);
//隐藏分页导航条,这个需要熟悉datagrid的html结构,直接用jquery操作DOM对象,easyui datagrid没有提供相关方法隐藏导航条
$(this).closest('div.datagrid-wrap').find('div.datagrid-pager').hide();
} else {
//如果通过调用reload方法重新加载数据有数据时显示出分页导航容器
$(this).closest('div.datagrid-wrap').find('div.datagrid-pager').show();
}
}
});
},
search : function() {
if ($('#search-form').form('validate')) {
$('#data-grid').datagrid({
url : '/report/config/templateQuery',
queryParams : App.dataGridQueryParams('search-form')
});
}
},
exportExcel : function() {
//jquery form表单.serialize()序列化后中文乱码,是因为.serialize()自动调用了encodeURIComponent方法将数据编码了
//调用decodeURIComponent(xxx, true);将数据解码
//http://ollevere.iteye.com/blog/1554355
var params = $('#search-form').serialize();
params = decodeURIComponent(params, true);
params = encodeURI(encodeURI(params));
window.open('/report/config/templateExport?' + params);
}
}
}();
$(function() {
ReportTemplate.init();
});