123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- Ext.define('saas.view.core.base.GridPanel', {
- extend: 'Ext.grid.Panel',
- xtype: 'core-base-gridpanel',
- requires: [
- 'Ext.grid.plugin.Exporter'
- ],
- plugins: [{
- ptype: 'gridexporter',
- }, {
- ptype: 'menuclipboard'
- }],
- cls:'core-base-gridpanel',
-
- dataUrl: '',
- dbSearchFields: [],
- condition:'',
- rootProperty: 'data.list',
- totalProperty: 'data.total',
- flexColumn: [{
- flex: 1,
- dataIndex:'',
- initHidden: true,
- allowBlank: true
- }],
- initComponent: function() {
- var me = this;
- me.frame = false;
- if(me._columns){
- var fields = me._columns.map(column => column.dataIndex);
- me.store = Ext.create('Ext.data.Store',{
- fields:fields,
- autoLoad: true,
- pageSize: 10,
- data: [],
- proxy: {
- timeout:8000,
- type: 'ajax',
- url: me.dataUrl,
- actionMethods: {
- read: 'GET'
- },
- reader: {
- type: 'json',
- rootProperty: me.rootProperty,
- totalProperty: me.totalProperty,
- },
- listeners: {
- exception: function(proxy, response, operation, eOpts) {
- if(operation.success) {
- if(response.timedout) {
- saas.util.BaseUtil.showErrorToast('请求超时');
- }
- }else {
- console.error('exception: ', response);
- saas.util.BaseUtil.showErrorToast('查询失败:' + (response.responseJson?response.responseJson.message:'请求超时'));
- }
- }
- }
- },
- listeners: {
- beforeload: function (store, op) {
- var basePanel = me.up('core-base-basepanel');
- var condition = basePanel.getConditions();
- if (Ext.isEmpty(condition)) {
- condition = "";
- }
- var obj = basePanel.getExtraParams(store, op, condition);
- Ext.apply(store.proxy.extraParams, obj);
- }
- }
- });
- Ext.apply(me, {
- dockedItems:[{
- xtype: 'pagingtoolbar',
- dock: 'bottom',
- cls:'x-basepanel-pagingtoolbar',
- displayInfo: true,
- store: me.store
- }]
- });
- }
- me.callParent(arguments);
- me.refreshColumns();
- },
- listeners:{
- boxready: function(grid, width, height, eOpts) {
- var store = grid.getStore(),
- gridBodyBox = grid.body.dom.getBoundingClientRect(),
- gridBodyBoxHeight = gridBodyBox.height;//可能有滚动条
- var pageSize = Math.floor(gridBodyBoxHeight / 33);
- store.setPageSize(pageSize);
- }
- },
- refreshColumns: function() {
- var me = this,
- basePanel = me.up('core-base-basepanel');
- me.reconfigure(me.store, Ext.Array.merge(Ext.Array.clone(basePanel.gridConfig.columns), me.flexColumn));
- me.applyScrollable(true)
- },
- onLoad:function(){
- this.ownerCt.ownerCt.store.load();
- },
- onImport:function(){
- var grid = this.ownerCt.ownerCt;
- var form = grid.ownerCt,panelEl = form.getEl();
- var box = panelEl.getBox();
- var height = box.height;
- var width = box.width;
- var win = form.add(Ext.create('saas.view.core.base.ImportWindow', {
- cls:'x-window-dbfind',
- belong:form,
- modal:true,
- height: height * 0.8,
- width: width * 0.8,
- title: form._title + '导入',
- scrollable: true,
- bodyPadding: 10,
- constrain: true,
- closable: true,
- layout:'fit',
- renderTo:form.getEl()
- }));
- win.show();
- },
- onExport:function(me){
- var grid = me.ownerCt.ownerCt;
- //导出接口权限设置
- var url = '/api/commons/'+grid.ownerCt.caller+'/export';
- saas.util.BaseUtil.request({
- url: url,
- params: '',
- method: 'GET',
- })
- .then(function(localJson) {
- if(localJson.success){
- grid.store.exportPageSize = 5000;
- grid.store.exportNumber = 1;
- grid.store.load(function(records, operation, success) {
- grid.saveDocumentAs({
- type: 'xlsx',
- title: grid.ownerCt._title + '列表',
- fileName: grid.ownerCt._title + '列表'+Ext.Date.format(new Date(),'Y-m-d_H-i-s')+'.xlsx'
- });
- grid.store.exportPageSize = null;
- grid.store.exportNumber = null;
- grid.store.load(function(records, operation, success) {
- });
- });
- }
- })
- .catch(function(e) {
- saas.util.BaseUtil.showErrorToast('导出失败: ' + e.message);
- });
- },
- onVastDeal:function(url,type){
- var form = this.ownerCt;
- var grid = this;
- var data = grid.getGridSelected(type);
- if(!data){
- saas.util.BaseUtil.showErrorToast('请勾选符合条件的行进行操作。');
- return false;
- }
- if(data&&data.length>0){
- var params = JSON.stringify({baseDTOs:data});
- saas.util.BaseUtil.request({
- url: url,
- params: params,
- method: 'POST',
- async:false
- })
- .then(function() {
- saas.util.BaseUtil.showSuccessToast('操作成功');
- grid.store.load();
- grid.selModel.deselectAll();
- })
- .catch(function(e) {
- saas.util.BaseUtil.showErrorToast('操作失败: ' + e.message);
- });
- }else{
- saas.util.BaseUtil.showErrorToast('请勾选至少一条明细');
- }
- },
- getGridSelected:function(type){
- var isErrorSelect = false;
- var checkField = this.statusCodeField;
- var me = this,
- items = me.selModel.getSelection(),
- data = new Array() ;
- Ext.each(items, function(item, index){
- if(!Ext.isEmpty(item.data[me.idField])){
- var o = new Object();
- if(me.idField){
- o['id'] = item.data[me.idField];
- }
- if(me.codeField){
- o['code'] = item.data[me.codeField];
- }
- if(type&&type==item.data[checkField]){
- isErrorSelect = true
- }
- data.push(o);
- }
- });
- if(isErrorSelect){
- return false;
- }
- return data;
- },
- });
|