Panel2.js 7.1 KB

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