ApplyGrid.js 6.5 KB

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