productApprovalDetailGrid.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /**
  2. * ERP项目gridpanel通用样式2
  3. */
  4. Ext.define('erp.view.scm.product.ProductApprovals.productApprovalDetailGrid',{
  5. extend: 'Ext.grid.Panel',
  6. alias: 'widget.productApprovalDetailGrid',
  7. requires: ['erp.view.core.toolbar.Toolbar'],
  8. region: 'south',
  9. layout : 'fit',
  10. id: 'productApprovalDetailGrid',
  11. emptyText : $I18N.common.grid.emptyText,
  12. columnLines : true,
  13. autoScroll : true,
  14. loadMask: true,
  15. store: [],
  16. columns: [],
  17. bodyStyle: 'background-color:#f1f1f1;',
  18. plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
  19. clicksToEdit: 1
  20. })],
  21. features : [Ext.create('Ext.grid.feature.Grouping',{
  22. //startCollapsed: true,
  23. groupHeaderTpl: '{name} (Count:{rows.length})'
  24. }),{
  25. ftype : 'summary',
  26. showSummaryRow : false,//不显示默认合计行
  27. generateSummaryData: function(){
  28. // 避开在grid reconfigure后的计算,节约加载时间50~600ms
  29. return {};
  30. }
  31. }],
  32. bbar: {xtype: 'erpToolbar',id:'productApprovalDetailGridbar'},
  33. GridUtil: Ext.create('erp.util.GridUtil'),
  34. BaseUtil: Ext.create('erp.util.BaseUtil'),
  35. necessaryField: '',//必填字段
  36. detno: '',//编号字段
  37. keyField: '',//主键字段
  38. mainField: '',//对应主表主键的字段
  39. dbfinds: [],
  40. caller: null,
  41. condition: null,
  42. gridCondition:null,
  43. initComponent : function(){
  44. var urlCondition = this.BaseUtil.getUrlParam('formCondition');
  45. //定义通过IS拆分后的数值
  46. var cons=null;
  47. //存在urlCondition的情况下
  48. if(urlCondition){
  49. //对urlCondition进行拆分 urlCondition的格式一半为pp_idIS1
  50. if(urlCondition.indexOf('IS')>=0){
  51. cons = urlCondition.split("IS");
  52. }else{
  53. cons = urlCondition.split("=");
  54. if(cons[1].indexOf('\'')>=0){
  55. cons[1]=cons[1].slice(1,cons[1].length-1);
  56. }
  57. }
  58. }
  59. var pp_id=0;
  60. if(cons!=null){
  61. if(cons[0]&&cons[1]){
  62. if(cons[0]!=null&&cons[0]!=''){
  63. if(cons[1]>0){
  64. pp_id=cons[1];
  65. }else{
  66. pp_id=0;
  67. }
  68. }
  69. }
  70. }
  71. var condition = this.mainField+"='"+pp_id+"'";
  72. var gridParam = {caller: this.caller || caller, condition: this.gridCondition||condition, _m: 0};
  73. var master = getUrlParam('newMaster');
  74. if(master){
  75. gridParam.master = master;
  76. }
  77. this.GridUtil.getGridColumnsAndStore(this, 'common/singleGridPanel.action', gridParam, "");//从后台拿到gridpanel的配置及数据
  78. this.on('summary', this.generateSummaryData, this, {single: true, delay: 1000});
  79. this.callParent(arguments);
  80. },
  81. getEffectiveData: function(){
  82. var me = this;
  83. var effective = new Array();
  84. var s = this.store.data.items;
  85. for(var i=0;i<s.length;i++){
  86. var data = s[i].data;
  87. if(data[me.keyField] != null && data[me.keyField] != ""){
  88. effective.push(data);
  89. }
  90. }
  91. return effective;
  92. },
  93. setReadOnly: function(bool){
  94. this.readOnly = bool;
  95. },
  96. reconfigure: function(store, columns){
  97. var me = this,
  98. view = me.getView(),
  99. originalDeferinitialRefresh,
  100. oldStore = me.store,
  101. headerCt = me.headerCt,
  102. oldColumns = headerCt ? headerCt.items.getRange() : me.columns;
  103. if (columns) {
  104. columns = Ext.Array.slice(columns);
  105. }
  106. me.fireEvent('beforereconfigure', me, store, columns, oldStore, oldColumns);
  107. if (me.lockable) {
  108. me.reconfigureLockable(store, columns);
  109. } else {
  110. Ext.suspendLayouts();
  111. if (columns) {
  112. delete me.scrollLeftPos;
  113. headerCt.removeAll();
  114. headerCt.add(columns);
  115. }
  116. if (store && (store = Ext.StoreManager.lookup(store)) !== oldStore) {
  117. originalDeferinitialRefresh = view.deferInitialRefresh;
  118. view.deferInitialRefresh = false;
  119. try {
  120. me.bindStore(store);
  121. } catch ( e ) {
  122. }
  123. view.deferInitialRefresh = originalDeferinitialRefresh;
  124. } else {
  125. me.getView().refresh();
  126. }
  127. Ext.resumeLayouts(true);
  128. }
  129. me.fireEvent('reconfigure', me, store, columns, oldStore, oldColumns);
  130. this.fireEvent("summary", this);
  131. },
  132. generateSummaryData : function() {
  133. var store = this.store,
  134. columns = this.columns, s = this.features[1],
  135. i = 0, length = columns.length, comp, bar = this.down('erpToolbar');
  136. if (!bar) return;
  137. //将feature的data打印在toolbar上面
  138. for (; i < length; i++ ) {
  139. comp = columns[i];
  140. if(comp.summaryType) {
  141. var tb = Ext.getCmp(comp.dataIndex + '_' + comp.summaryType);
  142. if(!tb){
  143. bar.add('-');
  144. tb = bar.add({
  145. id: comp.dataIndex + '_' + comp.summaryType,
  146. itemId: comp.dataIndex,
  147. xtype: 'tbtext'
  148. });
  149. }
  150. var val = s.getSummary(store, comp.summaryType, comp.dataIndex, false);
  151. if(comp.xtype == 'numbercolumn') {
  152. val = Ext.util.Format.number(val, (comp.format || '0,000.000'));
  153. }
  154. tb.setText(comp.text + ':' + val);
  155. }
  156. }
  157. },
  158. /**
  159. * Grid上一条
  160. */
  161. prev: function(grid, record){
  162. grid = grid || Ext.getCmp('grid');
  163. record = record || grid.selModel.lastSelected;
  164. if(record){
  165. //递归查找上一条,并取到数据
  166. var d = grid.store.getAt(record.index - 1);
  167. if(d){
  168. try {
  169. grid.selModel.select(d);
  170. return d;
  171. } catch (e){
  172. }
  173. } else {
  174. if(record.index - 1 > 0){
  175. return this.prev(grid, d);
  176. } else {
  177. return null;
  178. }
  179. }
  180. }
  181. },
  182. /**
  183. * Grid下一条
  184. */
  185. next: function(grid, record){
  186. grid = grid || Ext.getCmp('grid');
  187. record = record || grid.selModel.lastSelected;
  188. if(record){
  189. //递归查找下一条,并取到数据
  190. var d = grid.store.getAt(record.index + 1);
  191. if(d){
  192. try {
  193. grid.selModel.select(d);
  194. return d;
  195. } catch (e){
  196. }
  197. } else {
  198. if(record.index + 1 < grid.store.data.items.length){
  199. return this.next(grid, d);
  200. } else {
  201. return null;
  202. }
  203. }
  204. }
  205. },
  206. listeners: {
  207. afterrender: function(grid){
  208. var me = this;
  209. if(Ext.isIE){
  210. document.body.attachEvent('onkeydown', function(){
  211. if(window.event.ctrlKey && window.event.keyCode == 67){//Ctrl + C
  212. var e = window.event;
  213. if(e.srcElement) {
  214. window.clipboardData.setData('text', e.srcElement.innerHTML);
  215. }
  216. }
  217. });
  218. } else {
  219. document.body.addEventListener("mouseover", function(e){
  220. if(Ext.isFF5){
  221. e = e || window.event;
  222. }
  223. window.mouseoverData = e.target.value;
  224. });
  225. document.body.addEventListener("keydown", function(e){
  226. if(Ext.isFF5){
  227. e = e || window.event;
  228. }
  229. if(e.ctrlKey && e.keyCode == 67){
  230. me.copyToClipboard(window.mouseoverData);
  231. }
  232. if(e.ctrlKey && e.keyCode == 67){
  233. me.copyToClipboard(window.mouseoverData);
  234. }
  235. });
  236. }
  237. }
  238. },
  239. copyToClipboard: function(txt) {
  240. if(window.clipboardData) {
  241. window.clipboardData.clearData();
  242. window.clipboardData.setData('text', txt);
  243. } else if (navigator.userAgent.indexOf('Opera') != -1) {
  244. window.location = txt;
  245. } else if (window.netscape) {
  246. try {
  247. netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
  248. } catch (e) {
  249. alert("您的firefox安全限制限制您进行剪贴板操作,请打开'about:config'将signed.applets.codebase_principal_support'设置为true'之后重试");
  250. return false;
  251. }
  252. }
  253. }
  254. });