GridPanel.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. Ext.define('saas.view.core.base.GridPanel', {
  2. extend: 'Ext.grid.Panel',
  3. xtype: 'core-base-gridpanel',
  4. requires: [
  5. 'Ext.grid.plugin.Exporter'
  6. ],
  7. plugins: [{
  8. ptype: 'gridexporter',
  9. }, {
  10. ptype: 'menuclipboard'
  11. }],
  12. cls:'core-base-gridpanel',
  13. dataUrl: '',
  14. dbSearchFields: [],
  15. condition:'',
  16. rootProperty: 'data.list',
  17. totalProperty: 'data.total',
  18. flexColumn: [{
  19. flex: 1,
  20. dataIndex:'',
  21. initHidden: true,
  22. allowBlank: true
  23. }],
  24. initComponent: function() {
  25. var me = this;
  26. me.frame = false;
  27. if(me._columns){
  28. var fields = me._columns.map(column => column.dataIndex);
  29. me.store = Ext.create('Ext.data.Store',{
  30. fields:fields,
  31. autoLoad: true,
  32. pageSize: 10,
  33. data: [],
  34. proxy: {
  35. timeout:8000,
  36. type: 'ajax',
  37. url: me.dataUrl,
  38. actionMethods: {
  39. read: 'GET'
  40. },
  41. reader: {
  42. type: 'json',
  43. rootProperty: me.rootProperty,
  44. totalProperty: me.totalProperty,
  45. },
  46. listeners: {
  47. exception: function(proxy, response, operation, eOpts) {
  48. if(operation.success) {
  49. if(response.timedout) {
  50. saas.util.BaseUtil.showErrorToast('请求超时');
  51. }
  52. }else {
  53. console.error('exception: ', response);
  54. saas.util.BaseUtil.showErrorToast('查询失败:' + (response.responseJson?response.responseJson.message:'请求超时'));
  55. }
  56. }
  57. }
  58. },
  59. listeners: {
  60. beforeload: function (store, op) {
  61. var basePanel = me.up('core-base-basepanel');
  62. var condition = basePanel.getConditions();
  63. if (Ext.isEmpty(condition)) {
  64. condition = "";
  65. }
  66. var obj = basePanel.getExtraParams(store, op, condition);
  67. Ext.apply(store.proxy.extraParams, obj);
  68. }
  69. }
  70. });
  71. Ext.apply(me, {
  72. dockedItems:[{
  73. xtype: 'pagingtoolbar',
  74. dock: 'bottom',
  75. cls:'x-basepanel-pagingtoolbar',
  76. displayInfo: true,
  77. store: me.store
  78. }]
  79. });
  80. }
  81. me.callParent(arguments);
  82. me.refreshColumns();
  83. },
  84. listeners:{
  85. boxready: function(grid, width, height, eOpts) {
  86. var store = grid.getStore(),
  87. gridBodyBox = grid.body.dom.getBoundingClientRect(),
  88. gridBodyBoxHeight = gridBodyBox.height;//可能有滚动条
  89. var pageSize = Math.floor(gridBodyBoxHeight / 33);
  90. store.setPageSize(pageSize);
  91. }
  92. },
  93. refreshColumns: function() {
  94. var me = this,
  95. basePanel = me.up('core-base-basepanel');
  96. me.reconfigure(me.store, Ext.Array.merge(Ext.Array.clone(basePanel.gridConfig.columns), me.flexColumn));
  97. me.applyScrollable(true)
  98. },
  99. onLoad:function(){
  100. this.ownerCt.ownerCt.store.load();
  101. },
  102. onImport:function(){
  103. var grid = this.ownerCt.ownerCt;
  104. var form = grid.ownerCt,panelEl = form.getEl();
  105. var box = panelEl.getBox();
  106. var height = box.height;
  107. var width = box.width;
  108. var win = form.add(Ext.create('saas.view.core.base.ImportWindow', {
  109. cls:'x-window-dbfind',
  110. belong:form,
  111. modal:true,
  112. height: height * 0.8,
  113. width: width * 0.8,
  114. title: form._title + '导入',
  115. scrollable: true,
  116. bodyPadding: 10,
  117. constrain: true,
  118. closable: true,
  119. layout:'fit',
  120. renderTo:form.getEl()
  121. }));
  122. win.show();
  123. },
  124. onExport:function(me){
  125. var grid = me.ownerCt.ownerCt;
  126. //导出接口权限设置
  127. var url = '/api/commons/'+grid.ownerCt.caller+'/export';
  128. saas.util.BaseUtil.request({
  129. url: url,
  130. params: '',
  131. method: 'GET',
  132. })
  133. .then(function(localJson) {
  134. if(localJson.success){
  135. grid.store.exportPageSize = 5000;
  136. grid.store.exportNumber = 1;
  137. grid.store.load(function(records, operation, success) {
  138. grid.saveDocumentAs({
  139. type: 'xlsx',
  140. title: grid.ownerCt._title + '列表',
  141. fileName: grid.ownerCt._title + '列表'+Ext.Date.format(new Date(),'Y-m-d_H-i-s')+'.xlsx'
  142. });
  143. grid.store.exportPageSize = null;
  144. grid.store.exportNumber = null;
  145. grid.store.load(function(records, operation, success) {
  146. });
  147. });
  148. }
  149. })
  150. .catch(function(e) {
  151. saas.util.BaseUtil.showErrorToast('导出失败: ' + e.message);
  152. });
  153. },
  154. onVastDeal:function(url,type){
  155. var form = this.ownerCt;
  156. var grid = this;
  157. var data = grid.getGridSelected(type);
  158. if(!data){
  159. saas.util.BaseUtil.showErrorToast('请勾选符合条件的行进行操作。');
  160. return false;
  161. }
  162. if(data&&data.length>0){
  163. var params = JSON.stringify({baseDTOs:data});
  164. saas.util.BaseUtil.request({
  165. url: url,
  166. params: params,
  167. method: 'POST',
  168. async:false
  169. })
  170. .then(function() {
  171. saas.util.BaseUtil.showSuccessToast('操作成功');
  172. grid.store.load();
  173. grid.selModel.deselectAll();
  174. })
  175. .catch(function(e) {
  176. saas.util.BaseUtil.showErrorToast('操作失败: ' + e.message);
  177. });
  178. }else{
  179. saas.util.BaseUtil.showErrorToast('请勾选至少一条明细');
  180. }
  181. },
  182. getGridSelected:function(type){
  183. var isErrorSelect = false;
  184. var checkField = this.statusCodeField;
  185. var me = this,
  186. items = me.selModel.getSelection(),
  187. data = new Array() ;
  188. Ext.each(items, function(item, index){
  189. if(!Ext.isEmpty(item.data[me.idField])){
  190. var o = new Object();
  191. if(me.idField){
  192. o['id'] = item.data[me.idField];
  193. }
  194. if(me.codeField){
  195. o['code'] = item.data[me.codeField];
  196. }
  197. if(type&&type==item.data[checkField]){
  198. isErrorSelect = true
  199. }
  200. data.push(o);
  201. }
  202. });
  203. if(isErrorSelect){
  204. return false;
  205. }
  206. return data;
  207. },
  208. });