Panel2.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /**
  2. * ERP项目gridpanel通用样式2
  3. */
  4. Ext.define('erp.view.core.grid.Panel2',{
  5. extend: 'Ext.grid.Panel',
  6. alias: 'widget.erpGridPanel2',
  7. requires: ['erp.view.core.toolbar.Toolbar', 'erp.view.core.plugin.CopyPasteMenu'],
  8. region: 'south',
  9. layout : 'fit',
  10. id: 'grid',
  11. emptyText : $I18N.common.grid.emptyText,
  12. columnLines : true,
  13. autoScroll : true,
  14. store: [],
  15. columns: [],
  16. bodyStyle: 'background-color:#f1f1f1;',
  17. plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
  18. clicksToEdit: 1
  19. }), Ext.create('erp.view.core.plugin.CopyPasteMenu')],
  20. features : [Ext.create('Ext.grid.feature.GroupingSummary',{
  21. startCollapsed: true,
  22. groupHeaderTpl: '{name} (共:{rows.length}条)'
  23. }),{
  24. ftype : 'summary',
  25. showSummaryRow : false,//不显示默认合计行
  26. generateSummaryData: function(){
  27. // 避开在grid reconfigure后的计算,节约加载时间50~600ms
  28. return {};
  29. }
  30. }],
  31. bbar: {xtype: 'erpToolbar',id:'toolbar'},
  32. GridUtil: Ext.create('erp.util.GridUtil'),
  33. BaseUtil: Ext.create('erp.util.BaseUtil'),
  34. necessaryField: '',//必填字段
  35. detno: '',//编号字段
  36. keyField: '',//主键字段
  37. mainField: '',//对应主表主键的字段
  38. dbfinds: [],
  39. caller: null,
  40. condition: null,
  41. gridCondition:null,
  42. initComponent : function(){
  43. var condition = this.condition;
  44. if(!condition){
  45. var urlCondition = this.BaseUtil.getUrlParam('gridCondition');
  46. urlCondition = urlCondition == null || urlCondition == "null" ? "" : urlCondition;
  47. gridCondition = (gridCondition == null || gridCondition == "null") ? "" : gridCondition;
  48. gridCondition = gridCondition + urlCondition;
  49. gridCondition = gridCondition.replace(/IS/g, "=");
  50. condition = gridCondition;
  51. }
  52. var gridParam = {caller: this.caller || caller, condition: this.gridCondition||condition, _m: 0};
  53. var master = getUrlParam('newMaster');
  54. if(master){
  55. gridParam.master = master;
  56. }
  57. this.GridUtil.getGridColumnsAndStore(this, 'common/singleGridPanel.action', gridParam, "");//从后台拿到gridpanel的配置及数据
  58. this.callParent(arguments);
  59. if(this.allowExtraButtons)// 加载其它按钮
  60. this.on('reconfigure', this.loadExtraButton, this, {single: true, delay: 1000});
  61. this.on('summary', this.generateSummaryData, this, {single: true, delay: 1000});
  62. },
  63. getEffectiveData: function(){
  64. var me = this;
  65. var effective = new Array();
  66. var s = this.store.data.items;
  67. for(var i=0;i<s.length;i++){
  68. var data = s[i].data;
  69. if(data[me.keyField] != null && data[me.keyField] != ""){
  70. effective.push(data);
  71. }
  72. }
  73. return effective;
  74. },
  75. setReadOnly: function(bool){
  76. this.readOnly = bool;
  77. },
  78. reconfigure: function(store, columns){
  79. var me = this,
  80. view = me.getView(),
  81. originalDeferinitialRefresh,
  82. oldStore = me.store,
  83. headerCt = me.headerCt,
  84. oldColumns = headerCt ? headerCt.items.getRange() : me.columns;
  85. if (columns) {
  86. columns = Ext.Array.slice(columns);
  87. }
  88. me.fireEvent('beforereconfigure', me, store, columns, oldStore, oldColumns);
  89. if (me.lockable) {
  90. me.reconfigureLockable(store, columns);
  91. } else {
  92. Ext.suspendLayouts();
  93. if (columns) {
  94. delete me.scrollLeftPos;
  95. headerCt.removeAll();
  96. headerCt.add(columns);
  97. }
  98. if (store && (store = Ext.StoreManager.lookup(store)) !== oldStore) {
  99. originalDeferinitialRefresh = view.deferInitialRefresh;
  100. view.deferInitialRefresh = false;
  101. try {
  102. me.bindStore(store);
  103. } catch ( e ) {
  104. }
  105. view.deferInitialRefresh = originalDeferinitialRefresh;
  106. } else {
  107. me.getView().refresh();
  108. }
  109. Ext.resumeLayouts(true);
  110. }
  111. me.fireEvent('reconfigure', me, store, columns, oldStore, oldColumns);
  112. this.fireEvent("summary", this);
  113. },
  114. generateSummaryData : function() {
  115. var store = this.store,
  116. columns = this.columns, s = this.features[this.features.length - 1],
  117. i = 0, length = columns.length, comp, bar = this.down('erpToolbar');
  118. if (!bar) return;
  119. //将feature的data打印在toolbar上面
  120. for (; i < length; i++ ) {
  121. comp = columns[i];
  122. if(comp.summaryType) {
  123. var tb = Ext.getCmp(comp.dataIndex + '_' + comp.summaryType);
  124. if(!tb){
  125. bar.add('-');
  126. tb = bar.add({
  127. id: comp.dataIndex + '_' + comp.summaryType,
  128. itemId: comp.dataIndex,
  129. xtype: 'tbtext'
  130. });
  131. }
  132. var val = s.getSummary(store, comp.summaryType, comp.dataIndex, false);
  133. if(comp.xtype == 'numbercolumn') {
  134. val = Ext.util.Format.number(val, (comp.format || '0,000.000'));
  135. }
  136. tb.setText(comp.text + ':' + val);
  137. }
  138. }
  139. },
  140. /**
  141. * Grid上一条
  142. */
  143. prev: function(grid, record){
  144. grid = grid || Ext.getCmp('grid');
  145. record = record || grid.selModel.lastSelected;
  146. if(record){
  147. //递归查找上一条,并取到数据
  148. var d = grid.store.getAt(record.index - 1);
  149. if(d){
  150. try {
  151. grid.selModel.select(d);
  152. return d;
  153. } catch (e){
  154. }
  155. } else {
  156. if(record.index - 1 > 0){
  157. return this.prev(grid, d);
  158. } else {
  159. return null;
  160. }
  161. }
  162. }
  163. },
  164. /**
  165. * Grid下一条
  166. */
  167. next: function(grid, record){
  168. grid = grid || Ext.getCmp('grid');
  169. record = record || grid.selModel.lastSelected;
  170. if(record){
  171. //递归查找下一条,并取到数据
  172. var d = grid.store.getAt(record.index + 1);
  173. if(d){
  174. try {
  175. grid.selModel.select(d);
  176. return d;
  177. } catch (e){
  178. }
  179. } else {
  180. if(record.index + 1 < grid.store.data.items.length){
  181. return this.next(grid, d);
  182. } else {
  183. return null;
  184. }
  185. }
  186. }
  187. },
  188. allowExtraButtons: false,// 加载其它按钮,从GridButton加载
  189. loadExtraButton: function() {
  190. var me = this;
  191. Ext.Ajax.request({
  192. url : basePath + "common/gridButton.action",
  193. params: {
  194. caller: caller
  195. },
  196. method : 'post',
  197. async: false,
  198. callback : function(options, success, response){
  199. var r = new Ext.decode(response.responseText);
  200. if(r.exceptionInfo){
  201. showError(r.exceptionInfo);
  202. }
  203. if(r.buttons){
  204. var buttons = Ext.decode(r.buttons), tb = me.down('#toolbar');
  205. if(tb) {
  206. Ext.each(buttons, function(b){
  207. try {
  208. tb.add({xtype: b.xtype, disabled: true});
  209. } catch(e) {
  210. tb.add({
  211. text: $I18N.common.button[b.xtype],
  212. id: b.xtype,
  213. cls: 'x-btn-gray',
  214. disabled: true,
  215. style: {
  216. marginLeft: '10px'
  217. }
  218. });
  219. }
  220. });
  221. }
  222. }
  223. }
  224. });
  225. }
  226. });