|
|
@@ -13,7 +13,7 @@ Ext.define('saas.view.core.report.ReportPanel', {
|
|
|
|
|
|
layout: 'vbox',
|
|
|
autoScroll: true,
|
|
|
- bodyBorder:false,
|
|
|
+ bodyBorder: false,
|
|
|
bodyPadding: 5,
|
|
|
|
|
|
groupField: null, // 分组字段
|
|
|
@@ -21,162 +21,124 @@ Ext.define('saas.view.core.report.ReportPanel', {
|
|
|
defaultCondition: null, // 默认查询条件
|
|
|
searchItems: [], // 查询字段
|
|
|
reportTitle: '报表',
|
|
|
- autoLoad:true,
|
|
|
+ autoLoad: true,
|
|
|
allowPaging: true,
|
|
|
printAble: true,
|
|
|
exportAble: true,
|
|
|
+ showMySummary: true,
|
|
|
queryMode: 'DETAIL',
|
|
|
|
|
|
- initComponent: function() {
|
|
|
+ initComponent: function () {
|
|
|
var me = this;
|
|
|
var printAble = me.printAble;
|
|
|
var exportAble = me.exportAble;
|
|
|
var store = me.initStore();
|
|
|
columnWidth: 0.25,
|
|
|
- Ext.apply(me, {
|
|
|
- items: [{
|
|
|
- xtype: 'form',
|
|
|
- width: '100%',
|
|
|
- layout: 'column',
|
|
|
- defaults:{
|
|
|
- margin: '0 5 5 0',
|
|
|
- labelAlign: 'right',
|
|
|
- labelWidth: 90,
|
|
|
- columnWidth: 0.25,
|
|
|
- },
|
|
|
- items: me.initSearchItems().concat([{
|
|
|
- xtype: 'container',
|
|
|
- columnWidth: me.QueryWidth || 0.5,
|
|
|
- items: [{
|
|
|
- xtype: 'button',
|
|
|
- text: '查询',
|
|
|
- handler: 'onQuery',
|
|
|
- formBind:true
|
|
|
- },{
|
|
|
- xtype:'button',
|
|
|
- text:'打印',
|
|
|
- hidden: !printAble,
|
|
|
- style: {
|
|
|
- float: 'right'
|
|
|
- },
|
|
|
- handler: 'exportTo',
|
|
|
- cfg: {
|
|
|
- type: 'html',
|
|
|
- includeGroups: true,
|
|
|
- includeSummary: true,
|
|
|
- isPrint:true
|
|
|
- }
|
|
|
- },{
|
|
|
- xtype: 'button',
|
|
|
- style: {
|
|
|
- float: 'right'
|
|
|
- },
|
|
|
- text: '导出',
|
|
|
- hidden: !exportAble,
|
|
|
- menu: {
|
|
|
- defaults: {
|
|
|
- handler: 'exportTo'
|
|
|
+ Ext.apply(me, {
|
|
|
+ items: [{
|
|
|
+ xtype: 'form',
|
|
|
+ width: '100%',
|
|
|
+ layout: 'column',
|
|
|
+ defaults: {
|
|
|
+ margin: '0 5 5 0',
|
|
|
+ labelAlign: 'right',
|
|
|
+ labelWidth: 90,
|
|
|
+ columnWidth: 0.25,
|
|
|
+ },
|
|
|
+ items: me.initSearchItems().concat([{
|
|
|
+ xtype: 'container',
|
|
|
+ columnWidth: me.QueryWidth || 0.5,
|
|
|
+ items: [{
|
|
|
+ xtype: 'button',
|
|
|
+ text: '查询',
|
|
|
+ handler: 'onQuery',
|
|
|
+ formBind: true
|
|
|
+ }, {
|
|
|
+ xtype: 'button',
|
|
|
+ text: '打印',
|
|
|
+ hidden: !printAble,
|
|
|
+ style: {
|
|
|
+ float: 'right'
|
|
|
},
|
|
|
- items: [{
|
|
|
- text: 'Excel xlsx',
|
|
|
- cfg: {
|
|
|
- type: 'excel07',
|
|
|
- ext: 'xlsx'
|
|
|
- }
|
|
|
- }, {
|
|
|
- text: 'Excel xlsx (包含分组合计)',
|
|
|
- cfg: {
|
|
|
- type: 'excel07',
|
|
|
- ext: 'xlsx',
|
|
|
- includeGroups: true,
|
|
|
- includeSummary: true
|
|
|
- }
|
|
|
- }, {
|
|
|
- // text: 'Excel xml',
|
|
|
- // cfg: {
|
|
|
- // type: 'excel03',
|
|
|
- // ext: 'xml'
|
|
|
- // }
|
|
|
- // }, {
|
|
|
- // text: 'Excel xml (包含分组合计)',
|
|
|
- // cfg: {
|
|
|
- // type: 'excel03',
|
|
|
- // ext: 'xml',
|
|
|
- // includeGroups: true,
|
|
|
- // includeSummary: true
|
|
|
- // }
|
|
|
- // }, {
|
|
|
- text: 'CSV',
|
|
|
- cfg: {
|
|
|
- type: 'csv'
|
|
|
- }
|
|
|
- }, {
|
|
|
- text: 'CSV (包含分组合计)',
|
|
|
- cfg: {
|
|
|
- type: 'csv',
|
|
|
- includeGroups: true,
|
|
|
- includeSummary: true
|
|
|
- }
|
|
|
- // text: 'TSV',
|
|
|
- // cfg: {
|
|
|
- // type: 'tsv',
|
|
|
- // ext: 'csv'
|
|
|
- // }
|
|
|
- // }, {
|
|
|
- // text: 'HTML',
|
|
|
- // cfg: {
|
|
|
- // type: 'html'
|
|
|
- // }
|
|
|
- // }, {
|
|
|
- // text: 'HTML (包含分组合计)',
|
|
|
- // cfg: {
|
|
|
- // type: 'html',
|
|
|
- // includeGroups: true,
|
|
|
- // includeSummary: true
|
|
|
- // }
|
|
|
- }]
|
|
|
- }
|
|
|
- }]
|
|
|
- }])
|
|
|
- }, {
|
|
|
- xtype: 'grid',
|
|
|
- width: '100%',
|
|
|
- cls: 'x-report-grid',
|
|
|
- flex: 1,
|
|
|
- border: 0,
|
|
|
- sortableColumns: false,
|
|
|
- enableColumnHide: false,
|
|
|
- rowLines: false,
|
|
|
- plugins: [{
|
|
|
- ptype: 'gridexporter',
|
|
|
- }, {
|
|
|
- ptype: 'menuclipboard'
|
|
|
- }],
|
|
|
- features: [{
|
|
|
- ftype: 'groupingsummary',
|
|
|
- hideGroupedHeader: false,
|
|
|
- enableGroupingMenu: false,
|
|
|
- collapsible: false
|
|
|
+ handler: 'exportTo',
|
|
|
+ cfg: {
|
|
|
+ type: 'html',
|
|
|
+ includeGroups: true,
|
|
|
+ includeSummary: true,
|
|
|
+ isPrint: true
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ xtype: 'button',
|
|
|
+ style: {
|
|
|
+ float: 'right'
|
|
|
+ },
|
|
|
+ text: '导出',
|
|
|
+ hidden: !exportAble,
|
|
|
+ menu: {
|
|
|
+ defaults: {
|
|
|
+ handler: 'exportTo'
|
|
|
+ },
|
|
|
+ items: [{
|
|
|
+ text: 'Excel xlsx',
|
|
|
+ cfg: {
|
|
|
+ type: 'excel07',
|
|
|
+ ext: 'xlsx'
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ text: 'Excel xlsx (包含分组合计)',
|
|
|
+ cfg: {
|
|
|
+ type: 'excel07',
|
|
|
+ ext: 'xlsx',
|
|
|
+ includeGroups: true,
|
|
|
+ includeSummary: true
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ text: 'CSV',
|
|
|
+ cfg: {
|
|
|
+ type: 'csv'
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ text: 'CSV (包含分组合计)',
|
|
|
+ cfg: {
|
|
|
+ type: 'csv',
|
|
|
+ includeGroups: true,
|
|
|
+ includeSummary: true
|
|
|
+ }
|
|
|
+ }]
|
|
|
+ }
|
|
|
+ }]
|
|
|
+ }])
|
|
|
}, {
|
|
|
- ftype: 'mysummary',
|
|
|
- dock: 'bottom'
|
|
|
- }],
|
|
|
- store: store,
|
|
|
- columns: me.initColumns(),
|
|
|
- dockedItems: [me.allowPaging ? {
|
|
|
- xtype: 'pagingtoolbar',
|
|
|
- dock: 'bottom',
|
|
|
- displayInfo: true,
|
|
|
- store: store
|
|
|
- } : null],
|
|
|
- }]
|
|
|
- });
|
|
|
+ xtype: 'grid',
|
|
|
+ width: '100%',
|
|
|
+ cls: 'x-report-grid',
|
|
|
+ flex: 1,
|
|
|
+ border: 0,
|
|
|
+ sortableColumns: false,
|
|
|
+ enableColumnHide: false,
|
|
|
+ rowLines: false,
|
|
|
+ plugins: [{
|
|
|
+ ptype: 'gridexporter',
|
|
|
+ }, {
|
|
|
+ ptype: 'menuclipboard'
|
|
|
+ }],
|
|
|
+ features: me.initFeatures(),
|
|
|
+ store: store,
|
|
|
+ columns: me.initColumns(),
|
|
|
+ dockedItems: [me.allowPaging ? {
|
|
|
+ xtype: 'pagingtoolbar',
|
|
|
+ dock: 'bottom',
|
|
|
+ displayInfo: true,
|
|
|
+ store: store
|
|
|
+ } : null],
|
|
|
+ }]
|
|
|
+ });
|
|
|
|
|
|
me.callParent(arguments);
|
|
|
},
|
|
|
|
|
|
listeners: {
|
|
|
- boxready: function(p) {
|
|
|
+ boxready: function (p) {
|
|
|
var allowPaging = p.allowPaging;
|
|
|
var grid = p.down('grid');
|
|
|
var store = grid.getStore();
|
|
|
@@ -189,14 +151,34 @@ Ext.define('saas.view.core.report.ReportPanel', {
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- getListGrid: function() {
|
|
|
+ getListGrid: function () {
|
|
|
var me = this,
|
|
|
- grid = me.items.items[1];
|
|
|
+ grid = me.items.items[1];
|
|
|
|
|
|
return grid;
|
|
|
},
|
|
|
|
|
|
- initStore: function() {
|
|
|
+ initFeatures: function () {
|
|
|
+ var me = this;
|
|
|
+ var f = [{
|
|
|
+ ftype: 'groupingsummary',
|
|
|
+ hideGroupedHeader: false,
|
|
|
+ enableGroupingMenu: false,
|
|
|
+ collapsible: false
|
|
|
+ }];
|
|
|
+
|
|
|
+ if (me.showMySummary) {
|
|
|
+ f.push({
|
|
|
+ ftype: 'mysummary',
|
|
|
+ dock: 'bottom',
|
|
|
+ hidden: !me.showMySummary
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ return f;
|
|
|
+ },
|
|
|
+
|
|
|
+ initStore: function () {
|
|
|
var me = this;
|
|
|
var store = Ext.create('Ext.data.Store', {
|
|
|
fields: me.getFields(),
|
|
|
@@ -207,57 +189,67 @@ Ext.define('saas.view.core.report.ReportPanel', {
|
|
|
proxy: {
|
|
|
type: 'ajax',
|
|
|
url: me.listUrl,
|
|
|
- timeout: 8000,
|
|
|
+ timeout: 30000,
|
|
|
actionMethods: {
|
|
|
read: 'GET'
|
|
|
},
|
|
|
reader: {
|
|
|
type: 'json',
|
|
|
// rootProperty: 'data.list',
|
|
|
- rootProperty: function(data) {
|
|
|
+ rootProperty: function (data) {
|
|
|
try {
|
|
|
var grid = me.items.items[1],
|
|
|
- columns = grid.columns,
|
|
|
- summaryData = data.data ? (data.data.calculate || []) : [];
|
|
|
-
|
|
|
- Ext.Array.each(columns, function(c) {
|
|
|
+ store = grid.store,
|
|
|
+ columns = grid.columns,
|
|
|
+ summaryData = data.data ? (data.data.calculate || []) : [],
|
|
|
+ datas = data.data ? (data.data.list ? data.data.list.list : []) : [];
|
|
|
+
|
|
|
+ Ext.Array.each(columns, function (c) {
|
|
|
var type = c.summaryType,
|
|
|
- name = c.dataIndex;
|
|
|
-
|
|
|
- var d = Ext.Array.findBy(summaryData, function(s) {
|
|
|
+ name = c.dataIndex;
|
|
|
+
|
|
|
+ var d = Ext.Array.findBy(summaryData, function (s) {
|
|
|
return s.hasOwnProperty(name);
|
|
|
})
|
|
|
- if(type && d) {
|
|
|
- if(type == 'count') {
|
|
|
+ if (type && d) {
|
|
|
+ if(typeof c.mySummaryRenderer == 'function') {
|
|
|
+ c.summaryValue = c.mySummaryRenderer(grid, datas);
|
|
|
+ }else if (type == 'count') {
|
|
|
c.summaryValue = Ext.util.Format.number(d[name], c.format || '0');
|
|
|
- }else if(typeof c.summaryRenderer == 'function') {
|
|
|
+ } else if (typeof c.summaryRenderer == 'function') {
|
|
|
c.summaryValue = c.summaryRenderer(d[name]);
|
|
|
- }else if(typeof c.renderer == 'function') {
|
|
|
+ } else if (typeof c.renderer == 'function') {
|
|
|
c.summaryValue = c.renderer(d[name]);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
c.summaryValue = Ext.util.Format.number(d[name], c.format || '0.00');
|
|
|
}
|
|
|
- }else {
|
|
|
- c.summaryValue = 0;
|
|
|
+ } else if(type && !d) {
|
|
|
+ if(typeof c.mySummaryRenderer == 'function') {
|
|
|
+ c.summaryValue = c.mySummaryRenderer(grid, c, datas);
|
|
|
+ }else {
|
|
|
+ c.summaryValue = me.getSummaryValue(datas, c);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ c.summaryValue = null;
|
|
|
}
|
|
|
});
|
|
|
- return data.data ? (data.data.list ? data.data.list.list : []) : [];
|
|
|
- }catch(e) {
|
|
|
+ return datas;
|
|
|
+ } catch (e) {
|
|
|
saas.util.BaseUtil.showErrorToast(e.message);
|
|
|
}
|
|
|
},
|
|
|
totalProperty: 'data.list.total',
|
|
|
},
|
|
|
listeners: {
|
|
|
- exception: function(proxy, response, operation, eOpts) {
|
|
|
- if(operation.success) {
|
|
|
- if(response.timedout) {
|
|
|
+ exception: function (proxy, response, operation, eOpts) {
|
|
|
+ if (operation.success) {
|
|
|
+ if (response.timedout) {
|
|
|
saas.util.BaseUtil.showErrorToast('请求超时');
|
|
|
}
|
|
|
- }else {
|
|
|
- if(response.timedout) {
|
|
|
+ } else {
|
|
|
+ if (response.timedout) {
|
|
|
saas.util.BaseUtil.showErrorToast('请求超时');
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
saas.util.BaseUtil.showErrorToast('查询失败:' + response.responseJson.message);
|
|
|
}
|
|
|
}
|
|
|
@@ -267,10 +259,10 @@ Ext.define('saas.view.core.report.ReportPanel', {
|
|
|
listeners: {
|
|
|
beforeload: function (store, op) {
|
|
|
var condition = me.getConditions(),
|
|
|
- defaultCondition = me.defaultCondition,
|
|
|
- summarys = me.summarys;
|
|
|
-
|
|
|
- if(defaultCondition) {
|
|
|
+ defaultCondition = me.defaultCondition,
|
|
|
+ summarys = me.summarys;
|
|
|
+
|
|
|
+ if (defaultCondition) {
|
|
|
condition.push({
|
|
|
type: 'condition',
|
|
|
value: defaultCondition
|
|
|
@@ -278,19 +270,19 @@ Ext.define('saas.view.core.report.ReportPanel', {
|
|
|
}
|
|
|
|
|
|
var params = me.applyParams({
|
|
|
- number: store.exportNumber?store.exportNumber:op._page,
|
|
|
- size: store.exportPageSize?store.exportPageSize:store.pageSize,
|
|
|
+ number: store.exportNumber ? store.exportNumber : op._page,
|
|
|
+ size: store.exportPageSize ? store.exportPageSize : store.pageSize,
|
|
|
mode: me.queryMode || 'DETAIL',
|
|
|
condition: JSON.stringify(condition),
|
|
|
calculateFields: JSON.stringify(summarys)
|
|
|
});
|
|
|
Ext.apply(store.proxy.extraParams, params);
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- if(me.groupField) {
|
|
|
+ if (me.groupField) {
|
|
|
store.setGrouper({
|
|
|
property: me.groupField
|
|
|
});
|
|
|
@@ -299,26 +291,26 @@ Ext.define('saas.view.core.report.ReportPanel', {
|
|
|
return store;
|
|
|
},
|
|
|
|
|
|
- getFields: function() {
|
|
|
+ getFields: function () {
|
|
|
var me = this;
|
|
|
- return me.reportColumns.filter(function(c) {
|
|
|
+ return me.reportColumns.filter(function (c) {
|
|
|
return !!c.dataIndex;
|
|
|
- }).map(function(c) {
|
|
|
+ }).map(function (c) {
|
|
|
return c.dataIndex;
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- initColumns: function() {
|
|
|
+ initColumns: function () {
|
|
|
var me = this,
|
|
|
- columns = me.reportColumns,
|
|
|
- summarys = [];
|
|
|
+ columns = me.reportColumns,
|
|
|
+ summarys = [];
|
|
|
|
|
|
- Ext.Array.each(columns, function(c) {
|
|
|
+ Ext.Array.each(columns, function (c) {
|
|
|
c.columns || Ext.applyIf(c, {
|
|
|
width: 110
|
|
|
});
|
|
|
|
|
|
- if(c.xtype == 'datecolumn') {
|
|
|
+ if (c.xtype == 'datecolumn') {
|
|
|
Ext.applyIf(c, {
|
|
|
// 这两个都要写上,才能控制到不同类型的导出格式,原因不明- -!
|
|
|
format: 'Y-m-d',
|
|
|
@@ -330,14 +322,14 @@ Ext.define('saas.view.core.report.ReportPanel', {
|
|
|
return Ext.Date.format(new Date(value), 'Y-m-d');
|
|
|
},
|
|
|
// 下面这个方法不写会造成日期列求和,原因不明- -!
|
|
|
- exportSummaryRenderer: function(v) {
|
|
|
+ exportSummaryRenderer: function (v) {
|
|
|
return v;
|
|
|
}
|
|
|
})
|
|
|
- }else if(c.xtype == 'numbercolumn') {
|
|
|
+ } else if (c.xtype == 'numbercolumn') {
|
|
|
Ext.applyIf(c, {
|
|
|
align: 'end', // 数字右对齐
|
|
|
- renderer : function(v) {
|
|
|
+ renderer: function (v) {
|
|
|
var arr = (v + '.').split('.');
|
|
|
var xr = (new Array(arr[1].length)).fill('0');
|
|
|
var format = '0.' + xr.join();
|
|
|
@@ -346,11 +338,11 @@ Ext.define('saas.view.core.report.ReportPanel', {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- if(c.summaryType) {
|
|
|
+ if (c.summaryType) {
|
|
|
me.initSummaryType(c);
|
|
|
summarys.push({
|
|
|
field: c.dataIndex,
|
|
|
- operation: c.summaryTypeName,
|
|
|
+ operation: c.summaryType == 'last' ? 'sum' : c.summaryType,
|
|
|
});
|
|
|
}
|
|
|
})
|
|
|
@@ -360,64 +352,69 @@ Ext.define('saas.view.core.report.ReportPanel', {
|
|
|
return columns;
|
|
|
},
|
|
|
|
|
|
- initSummaryType: function(column) {
|
|
|
+ initSummaryType: function (column) {
|
|
|
var summaryType = column.summaryType;
|
|
|
- if(Ext.isString(summaryType)) {
|
|
|
+ if (Ext.isString(summaryType)) {
|
|
|
column.summaryTypeName = summaryType;
|
|
|
}
|
|
|
- if(summaryType == 'sum') {
|
|
|
+ if (summaryType == 'sum') {
|
|
|
column._summaryType = 'sum';
|
|
|
// 原生的求和方法使用的是Store.sum,在数据存在null时计算结果为NaN,这里重写一下
|
|
|
- column.summaryType = function(records, values) {
|
|
|
+ column.summaryType = function (records, values) {
|
|
|
return Ext.Array.sum(values);
|
|
|
}
|
|
|
+ } else if(summaryType == 'last') {
|
|
|
+ column._summaryType = 'last';
|
|
|
+ column.summaryType = function (records, values) {
|
|
|
+ return values[values.length - 1];
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- initSearchItems: function() {
|
|
|
+ initSearchItems: function () {
|
|
|
var me = this,
|
|
|
- queryItems = [],
|
|
|
- items = me.searchItems,
|
|
|
- viewModel = me.getViewModel();
|
|
|
+ queryItems = [],
|
|
|
+ items = me.searchItems,
|
|
|
+ viewModel = me.getViewModel();
|
|
|
|
|
|
- Ext.Array.each(items, function(item) {
|
|
|
+ Ext.Array.each(items, function (item) {
|
|
|
var bind = item.bind,
|
|
|
- name = item.name,
|
|
|
- ignore = item.ignore,
|
|
|
- defaultValue = item.defaultValue;
|
|
|
+ name = item.name,
|
|
|
+ ignore = item.ignore,
|
|
|
+ defaultValue = item.defaultValue;
|
|
|
|
|
|
- if(item.allowBlank==false){
|
|
|
+ if (item.allowBlank == false) {
|
|
|
// TODO 需要判断类型
|
|
|
item.beforeLabelTextTpl = "<font color=\"red\" style=\"position:relative; top:2px;right:2px; font-weight: bolder;\">*</font>";
|
|
|
}
|
|
|
|
|
|
- if(!ignore) {
|
|
|
+ if (!ignore) {
|
|
|
queryItems.push(name);
|
|
|
}
|
|
|
|
|
|
- if(item.xtype == 'numberfield') {
|
|
|
+ if (item.xtype == 'numberfield') {
|
|
|
Ext.applyIf(item, {
|
|
|
hideTrigger: true, // 隐藏trigger
|
|
|
mouseWheelEnabled: false // 取消滚轮事件
|
|
|
});
|
|
|
}
|
|
|
// 设置model绑定
|
|
|
- if(bind) {
|
|
|
- if(!Ext.isString(bind)) {
|
|
|
+ if (bind) {
|
|
|
+ if (!Ext.isString(bind)) {
|
|
|
bind = name;
|
|
|
Ext.apply(bind, {
|
|
|
value: '{form.' + bind + '}'
|
|
|
});
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
bind = name;
|
|
|
item.bind = '{form.' + bind + '}';
|
|
|
}
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
bind = name;
|
|
|
item.bind = '{form.' + bind + '}';
|
|
|
}
|
|
|
// 设置默认值
|
|
|
- if(defaultValue) {
|
|
|
+ if (defaultValue) {
|
|
|
viewModel.set('form.' + bind, defaultValue);
|
|
|
}
|
|
|
|
|
|
@@ -425,11 +422,11 @@ Ext.define('saas.view.core.report.ReportPanel', {
|
|
|
item.listeners = item.listeners || {};
|
|
|
Ext.applyIf(item.listeners, {
|
|
|
keydown: {
|
|
|
- fn: function(th, e, eOpts) {
|
|
|
- if(e.keyCode == 13) {
|
|
|
- if(!th.fireEvent('beforequery', th)) {
|
|
|
+ fn: function (th, e, eOpts) {
|
|
|
+ if (e.keyCode == 13) {
|
|
|
+ if (!th.fireEvent('beforequery', th)) {
|
|
|
return;
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
var p = this.up('core-report-reportpanel');
|
|
|
p.getController().onQuery()
|
|
|
}
|
|
|
@@ -444,42 +441,60 @@ Ext.define('saas.view.core.report.ReportPanel', {
|
|
|
return items;
|
|
|
},
|
|
|
|
|
|
- getConditions: function() {
|
|
|
+ getSummaryValue: function(datas, c) {
|
|
|
+ var dataIndex = c.dataIndex,
|
|
|
+ type = c.summaryType,
|
|
|
+ values = datas.map(function(d) {
|
|
|
+ return d[c.dataIndex];
|
|
|
+ }),
|
|
|
+ sum = Ext.Array.sum(values);
|
|
|
+ if (type == 'count') {
|
|
|
+ return Ext.util.Format.number(values.length, '0');
|
|
|
+ } else if (typeof c.summaryRenderer == 'function') {
|
|
|
+ return c.summaryRenderer(sum);
|
|
|
+ } else if (typeof c.renderer == 'function') {
|
|
|
+ return c.renderer(sum);
|
|
|
+ } else {
|
|
|
+ return Ext.util.Format.number(sum, c.format || '0.00');
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ getConditions: function () {
|
|
|
var me = this,
|
|
|
- form = me.down('form'),
|
|
|
- formItems = form.items.items,
|
|
|
- viewModel = me.getViewModel(),
|
|
|
- viewModelData = viewModel.getData(),
|
|
|
- formData = viewModelData['form'] || {},
|
|
|
- queryItems = me.queryItems,
|
|
|
- condition,
|
|
|
- conditions = [];
|
|
|
-
|
|
|
- for(var i = 0; i < queryItems.length; i++) {
|
|
|
+ form = me.down('form'),
|
|
|
+ formItems = form.items.items,
|
|
|
+ viewModel = me.getViewModel(),
|
|
|
+ viewModelData = viewModel.getData(),
|
|
|
+ formData = viewModelData['form'] || {},
|
|
|
+ queryItems = me.queryItems,
|
|
|
+ condition,
|
|
|
+ conditions = [];
|
|
|
+
|
|
|
+ for (var i = 0; i < queryItems.length; i++) {
|
|
|
var n = queryItems[i];
|
|
|
- var item = Ext.Array.findBy(formItems, function(i) {
|
|
|
+ var item = Ext.Array.findBy(formItems, function (i) {
|
|
|
return i.name == n;
|
|
|
});
|
|
|
var field = item.name,
|
|
|
- func = item.getCondition,
|
|
|
- value = formData[n],
|
|
|
- condition;
|
|
|
+ func = item.getCondition,
|
|
|
+ value = formData[n],
|
|
|
+ condition;
|
|
|
|
|
|
- if(!value) {
|
|
|
+ if (!value) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- if(typeof func == 'function') {
|
|
|
+ if (typeof func == 'function') {
|
|
|
condition = {
|
|
|
type: 'condition',
|
|
|
value: func(value)
|
|
|
}
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
type = item.fieldType || me.getDefaultFieldType(item),
|
|
|
- operation = item.operation || me.getDefaultFieldOperation(item),
|
|
|
- conditionValue = me.getConditionValue(item, value);
|
|
|
-
|
|
|
- if(!conditionValue) {
|
|
|
+ operation = item.operation || me.getDefaultFieldOperation(item),
|
|
|
+ conditionValue = me.getConditionValue(item, value);
|
|
|
+
|
|
|
+ if (!conditionValue) {
|
|
|
continue;
|
|
|
}
|
|
|
condition = {
|
|
|
@@ -495,24 +510,24 @@ Ext.define('saas.view.core.report.ReportPanel', {
|
|
|
return me.myGetConditions(conditions);
|
|
|
},
|
|
|
|
|
|
- myGetConditions: function(conditions) {
|
|
|
+ myGetConditions: function (conditions) {
|
|
|
return conditions;
|
|
|
},
|
|
|
|
|
|
- getDefaultFieldType: function(field) {
|
|
|
+ getDefaultFieldType: function (field) {
|
|
|
var me = this,
|
|
|
- xtypes = field.getXTypes().split('/'),
|
|
|
- type;
|
|
|
+ xtypes = field.getXTypes().split('/'),
|
|
|
+ type;
|
|
|
|
|
|
- if(me.isContainsAny(xtypes, ['numberfield'])) {
|
|
|
+ if (me.isContainsAny(xtypes, ['numberfield'])) {
|
|
|
type = 'number';
|
|
|
- }else if(me.isContainsAny(xtypes, ['datefield', 'condatefield', 'conmonthfield'])) {
|
|
|
+ } else if (me.isContainsAny(xtypes, ['datefield', 'condatefield', 'conmonthfield'])) {
|
|
|
type = 'date';
|
|
|
- }else if(me.isContainsAny(xtypes, ['dbfindtrigger'])) {
|
|
|
+ } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
|
|
|
type = 'string';
|
|
|
- }else if(me.isContainsAny(xtypes, ['combobox', 'multicombo', 'combo', 'radiofield', 'radio'])) {
|
|
|
+ } else if (me.isContainsAny(xtypes, ['combobox', 'multicombo', 'combo', 'radiofield', 'radio'])) {
|
|
|
type = 'enum';
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
type = 'string';
|
|
|
}
|
|
|
|
|
|
@@ -522,28 +537,30 @@ Ext.define('saas.view.core.report.ReportPanel', {
|
|
|
/**
|
|
|
* 只要arr1和arr2中存在相同项即返回真
|
|
|
*/
|
|
|
- isContainsAny: function(arr1, arr2) {
|
|
|
- for(var i = 0; i < arr2.length; i++) {
|
|
|
+ isContainsAny: function (arr1, arr2) {
|
|
|
+ for (var i = 0; i < arr2.length; i++) {
|
|
|
var a2 = arr2[i];
|
|
|
- if(!!arr1.find(function(a1) {return a1==a2})) {
|
|
|
+ if (!!arr1.find(function (a1) {
|
|
|
+ return a1 == a2
|
|
|
+ })) {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
},
|
|
|
|
|
|
- getDefaultFieldOperation: function(field) {
|
|
|
+ getDefaultFieldOperation: function (field) {
|
|
|
var me = this,
|
|
|
- xtypes = field.getXTypes().split('/'),
|
|
|
- operation;
|
|
|
+ xtypes = field.getXTypes().split('/'),
|
|
|
+ operation;
|
|
|
|
|
|
- if(me.isContainsAny(xtypes, ['numberfield', 'datefield', 'dbfindtrigger'])) {
|
|
|
+ if (me.isContainsAny(xtypes, ['numberfield', 'datefield', 'dbfindtrigger'])) {
|
|
|
operation = '=';
|
|
|
- }else if(me.isContainsAny(xtypes, ['condatefield', 'conmonthfield'])) {
|
|
|
+ } else if (me.isContainsAny(xtypes, ['condatefield', 'conmonthfield'])) {
|
|
|
operation = 'between';
|
|
|
- }else if(me.isContainsAny(xtypes, ['multidbfindtrigger', 'combobox', 'multicombo', 'combo'])) {
|
|
|
+ } else if (me.isContainsAny(xtypes, ['multidbfindtrigger', 'combobox', 'multicombo', 'combo'])) {
|
|
|
operation = 'in';
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
operation = 'like';
|
|
|
}
|
|
|
|
|
|
@@ -553,38 +570,38 @@ Ext.define('saas.view.core.report.ReportPanel', {
|
|
|
/**
|
|
|
* 处理部分字段值
|
|
|
*/
|
|
|
- getConditionValue: function(field, value) {
|
|
|
+ getConditionValue: function (field, value) {
|
|
|
var me = this,
|
|
|
- xtypes = field.getXTypes().split('/'),
|
|
|
- conditionValue;
|
|
|
- if(me.isContainsAny(xtypes, ['datefield'])) {
|
|
|
+ xtypes = field.getXTypes().split('/'),
|
|
|
+ conditionValue;
|
|
|
+ if (me.isContainsAny(xtypes, ['datefield'])) {
|
|
|
conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
|
|
|
- }else if(me.isContainsAny(xtypes, ['conmonthfield'])) {
|
|
|
+ } else if (me.isContainsAny(xtypes, ['conmonthfield'])) {
|
|
|
var from = value.from,
|
|
|
- to = value.to;
|
|
|
+ to = value.to;
|
|
|
|
|
|
conditionValue = from + ',' + to;
|
|
|
- }else if(me.isContainsAny(xtypes, ['condatefield'])) {
|
|
|
+ } else if (me.isContainsAny(xtypes, ['condatefield'])) {
|
|
|
var from = value.from,
|
|
|
- to = value.to;
|
|
|
+ to = value.to;
|
|
|
|
|
|
conditionValue = Ext.Date.format(new Date(from), 'Y-m-d 00:00:00') + ',' + Ext.Date.format(new Date(to), 'Y-m-d 23:59:59');
|
|
|
- }else if(me.isContainsAny(xtypes, ['dbfindtrigger'])) {
|
|
|
+ } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
|
|
|
conditionValue = value;
|
|
|
- }else if(me.isContainsAny(xtypes, ['combobox', 'combo'])) {
|
|
|
+ } else if (me.isContainsAny(xtypes, ['combobox', 'combo'])) {
|
|
|
conditionValue = '\'' + value + '\'';
|
|
|
- }else if(me.isContainsAny(xtypes, ['multicombo'])) {
|
|
|
- conditionValue = value.map ? value.map(function(v) {
|
|
|
+ } else if (me.isContainsAny(xtypes, ['multicombo'])) {
|
|
|
+ conditionValue = value.map ? value.map(function (v) {
|
|
|
return '\'' + v.value + '\'';
|
|
|
}).join(',') : '';
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
conditionValue = value;
|
|
|
}
|
|
|
|
|
|
return conditionValue;
|
|
|
},
|
|
|
|
|
|
- applyParams: function(p) {
|
|
|
+ applyParams: function (p) {
|
|
|
return p;
|
|
|
}
|
|
|
});
|