StenilCanUseProGrid.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /**
  2. * 钢网对应产品
  3. */
  4. Ext.define('erp.view.pm.mes.StenilCanUseProGrid',{
  5. extend: 'Ext.grid.Panel',
  6. alias: 'widget.stenilCanUsePro',
  7. requires: ['erp.view.core.toolbar.Toolbar', 'erp.view.core.plugin.CopyPasteMenu'],
  8. region: 'south',
  9. layout : 'fit',
  10. id: 'stenilCanUseProGrid',
  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:'toolbar1'},
  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. /**
  62. * 修改为selection改变时,summary也动态改变
  63. */
  64. getMultiSelected: function(){
  65. var grid = this;
  66. var items = grid.selModel.getSelection();
  67. Ext.each(items, function(item, index){
  68. if(this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  69. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0){
  70. grid.multiselected.push(item);
  71. }
  72. });
  73. return Ext.Array.unique(grid.multiselected);
  74. },
  75. initComponent : function(){
  76. if(!this.boxready) {
  77. if(this._buttons)
  78. this.bbar._buttons = this._buttons;// 在toolbar加入grid固定按钮
  79. var condition = this.condition;
  80. if(!condition){
  81. var urlCondition = this.BaseUtil.getUrlParam('gridCondition');
  82. urlCondition = urlCondition == null || urlCondition == "null" ? "" : urlCondition;
  83. gridCondition2 = (gridCondition == null || gridCondition == "null") ? "" : gridCondition;
  84. gridCondition2 = gridCondition2 + urlCondition;
  85. gridCondition2 = gridCondition2.replace('su_stid','sp_stid');
  86. gridCondition2 = gridCondition2.replace(/IS/g, "=");
  87. condition = gridCondition2;
  88. }
  89. var gridParam = {caller: (this.caller&&this.caller!='')?this.caller:'stenilCanUsePro' || caller, condition: this.gridCondition2||condition, _m: 0};
  90. var master = getUrlParam('newMaster'),_config=getUrlParam('_config');
  91. if(master){
  92. gridParam.master = master;
  93. }
  94. if(_config)gridParam._config=_config;
  95. var _copyConf=getUrlParam('_copyConf');
  96. if(_copyConf!=null){//复制来源单据的条件
  97. gridParam._copyConf=_copyConf;
  98. }
  99. this.GridUtil.getGridColumnsAndStore(this, 'common/singleGridPanel.action', gridParam, "");//从后台拿到gridpanel的配置及数据
  100. }
  101. this.condition = "";
  102. this.gridCondition2 ="";
  103. this.callParent(arguments);
  104. if(!this.boxready) {
  105. if(this.allowExtraButtons)// 加载其它按钮
  106. this.on('reconfigure', this.loadExtraButton, this, {single: true, delay: 1000});
  107. this.on('summary', this.generateSummaryData, this, {single: true, delay: 1000});
  108. }
  109. },
  110. getEffectiveData: function(){
  111. var me = this;
  112. var effective = new Array();
  113. var s = this.store.data.items;
  114. for(var i=0;i<s.length;i++){
  115. var data = s[i].data;
  116. if(data[me.keyField] != null && data[me.keyField] != ""){
  117. effective.push(data);
  118. }
  119. }
  120. return effective;
  121. },
  122. setReadOnly: function(bool){
  123. this.readOnly = bool;
  124. },
  125. reconfigure: function(store, columns){
  126. var me = this,
  127. view = me.getView(),
  128. originalDeferinitialRefresh,
  129. oldStore = me.store,
  130. headerCt = me.headerCt,
  131. oldColumns = headerCt ? headerCt.items.getRange() : me.columns;
  132. if (columns) {
  133. columns = Ext.Array.slice(columns);
  134. }
  135. me.fireEvent('beforereconfigure', me, store, columns, oldStore, oldColumns);
  136. if (me.lockable) {
  137. me.reconfigureLockable(store, columns);
  138. } else {
  139. Ext.suspendLayouts();
  140. if (columns) {
  141. delete me.scrollLeftPos;
  142. headerCt.removeAll();
  143. headerCt.add(columns);
  144. }
  145. if (store && (store = Ext.StoreManager.lookup(store)) !== oldStore) {
  146. originalDeferinitialRefresh = view.deferInitialRefresh;
  147. view.deferInitialRefresh = false;
  148. try {
  149. me.bindStore(store);
  150. } catch ( e ) {
  151. }
  152. view.deferInitialRefresh = originalDeferinitialRefresh;
  153. } else {
  154. me.getView().refresh();
  155. }
  156. Ext.resumeLayouts(true);
  157. }
  158. me.fireEvent('reconfigure', me, store, columns, oldStore, oldColumns);
  159. this.fireEvent("summary", this);
  160. },
  161. generateSummaryData : function() {
  162. var store = this.store,
  163. columns = this.columns, s = this.features[this.features.length - 1],
  164. i = 0, length = columns.length, comp, bar = this.down('erpToolbar');
  165. if (!bar) return;
  166. //将feature的data打印在toolbar上面
  167. for (; i < length; i++ ) {
  168. comp = columns[i];
  169. if(comp.summaryType) {
  170. var tb = Ext.getCmp(comp.dataIndex + '_' + comp.summaryType);
  171. if(!tb){
  172. bar.add('-');
  173. tb = bar.add({
  174. id: comp.dataIndex + '_' + comp.summaryType,
  175. itemId: comp.dataIndex,
  176. xtype: 'tbtext'
  177. });
  178. }
  179. var val = s.getSummary(store, comp.summaryType, comp.dataIndex, false);
  180. if(comp.xtype == 'numbercolumn') {
  181. val = Ext.util.Format.number(val, (comp.format || '0,000.000'));
  182. }
  183. tb.setText(comp.text + ':' + val);
  184. }
  185. }
  186. },
  187. /**
  188. * Grid上一条
  189. */
  190. prev: function(grid, record){
  191. grid = grid || Ext.getCmp('grid');
  192. record = record || grid.selModel.lastSelected;
  193. if(record){
  194. //递归查找上一条,并取到数据
  195. var d = grid.store.getAt(record.index - 1);
  196. if(d){
  197. try {
  198. grid.selModel.select(d);
  199. return d;
  200. } catch (e){
  201. }
  202. } else {
  203. if(record.index - 1 > 0){
  204. return this.prev(grid, d);
  205. } else {
  206. return null;
  207. }
  208. }
  209. }
  210. },
  211. /**
  212. * Grid下一条
  213. */
  214. next: function(grid, record){
  215. grid = grid || Ext.getCmp('grid');
  216. record = record || grid.selModel.lastSelected;
  217. if(record){
  218. //递归查找下一条,并取到数据
  219. var d = grid.store.getAt(record.index + 1);
  220. if(d){
  221. try {
  222. grid.selModel.select(d);
  223. return d;
  224. } catch (e){
  225. }
  226. } else {
  227. if(record.index + 1 < grid.store.data.items.length){
  228. return this.next(grid, d);
  229. } else {
  230. return null;
  231. }
  232. }
  233. }
  234. },
  235. allowExtraButtons: false,// 加载其它按钮,从GridButton加载
  236. loadExtraButton: function() {
  237. var me = this;
  238. Ext.Ajax.request({
  239. url : basePath + "common/gridButton.action",
  240. params: {
  241. caller: caller
  242. },
  243. method : 'post',
  244. async: false,
  245. callback : function(options, success, response){
  246. var r = new Ext.decode(response.responseText);
  247. if(r.exceptionInfo){
  248. showError(r.exceptionInfo);
  249. }
  250. if(r.buttons){
  251. var buttons = Ext.decode(r.buttons), tb = me.down('#toolbar1');
  252. if(tb) {
  253. Ext.each(buttons, function(b){
  254. try {
  255. tb.add({
  256. xtype: b.xtype,
  257. disabled: true,
  258. style: {
  259. marginLeft: '0'
  260. }
  261. });
  262. } catch(e) {
  263. tb.add({
  264. text: $I18N.common.button[b.xtype],
  265. id: b.xtype,
  266. cls: 'x-btn-gray',
  267. disabled: true
  268. });
  269. }
  270. });
  271. }
  272. }
  273. }
  274. });
  275. }
  276. });