GridPanel.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. Ext.define('erp.view.fa.ars.cmCopQuery.GridPanel',{
  2. extend: 'Ext.grid.Panel',
  3. alias: 'widget.erpCmCopQueryGridPanel',
  4. id: 'cmcopquerygrid',
  5. emptyText : '无数据',
  6. columnLines : true,
  7. autoScroll : true,
  8. store: [],
  9. columns: [],
  10. chkumio:false,
  11. tbar: [{
  12. name: 'query',
  13. text: $I18N.common.button.erpQueryButton,
  14. iconCls: 'x-button-icon-query',
  15. cls: 'x-btn-gray'
  16. }, '->', {
  17. name: 'export',
  18. text: $I18N.common.button.erpExportButton,
  19. iconCls: 'x-button-icon-excel',
  20. cls: 'x-btn-gray',
  21. handler: function(btn){
  22. var grid = Ext.getCmp('cmcopquerygrid');
  23. grid.BaseUtil.exportGrid(grid, '应收总账');
  24. }
  25. }, '-',{
  26. name: 'refresh',
  27. text: $I18N.common.button.erpRefreshButton,
  28. iconCls: 'x-button-icon-check',
  29. cls: 'x-btn-gray'
  30. },'-', {
  31. text: $I18N.common.button.erpCloseButton,
  32. iconCls: 'x-button-icon-close',
  33. cls: 'x-btn-gray',
  34. handler: function(){
  35. var main = parent.Ext.getCmp("content-panel");
  36. main.getActiveTab().close();
  37. }
  38. }],
  39. GridUtil: Ext.create('erp.util.GridUtil'),
  40. selModel: Ext.create('Ext.selection.CheckboxModel',{
  41. headerWidth: 0
  42. }),
  43. plugins: Ext.create('Ext.grid.plugin.CellEditing', {
  44. clicksToEdit: 1
  45. }),
  46. BaseUtil: Ext.create('erp.util.BaseUtil'),
  47. FormUtil: Ext.create('erp.util.FormUtil'),
  48. RenderUtil: Ext.create('erp.util.RenderUtil'),
  49. features : [Ext.create('Ext.grid.feature.Grouping',{
  50. hideGroupedHeader: true,
  51. groupHeaderTpl: '{name} (Count:{rows.length})'
  52. }),{
  53. ftype : 'summary',
  54. showSummaryRow : false,//不显示默认合计行
  55. generateSummaryData: function(){
  56. var me = this,
  57. data = {},
  58. store = me.view.store,
  59. columns = me.view.headerCt.getColumnsForTpl(),
  60. i = 0,
  61. length = columns.length,
  62. //fieldData,
  63. //key,
  64. comp;
  65. for (i = 0, length = columns.length; i < length; ++i) {
  66. comp = Ext.getCmp(columns[i].id);
  67. data[comp.id] = me.getSummary(store, comp.summaryType, comp.dataIndex, false);
  68. var tb = Ext.getCmp(columns[i].dataIndex + '_' + comp.summaryType);
  69. if(tb){
  70. tb.setText(tb.text.split(':')[0] + ':' + data[comp.id]);
  71. }
  72. }
  73. return data;
  74. }
  75. }],
  76. initComponent : function(){
  77. condition = this.BaseUtil.getUrlParam('urlcondition');
  78. condition = (condition == null) ? "" : condition;
  79. condition = condition.replace(/@/,"'%").replace(/@/,"%'");
  80. this.defaultCondition = condition;
  81. var gridParam = {caller: caller, condition: condition};
  82. this.GridUtil.getGridColumnsAndStore(this, 'common/singleGridPanel.action', gridParam, "");
  83. this.callParent(arguments);
  84. //给页面加上ctrl+alt+s键盘事件,自动跳转form配置界面
  85. this.addKeyBoardEvents();//监听Ctrl+Alt+S事件
  86. },
  87. setDefaultStore: function(d, f){
  88. var me = this;
  89. var data = [];
  90. if(!d || d.length == 2){
  91. me.GridUtil.add10EmptyData(me.detno, data);
  92. me.GridUtil.add10EmptyData(me.detno, data);
  93. } else {
  94. data = Ext.decode(d.replace(/,}/g, '}').replace(/,]/g, ']'));
  95. }
  96. var store = Ext.create('Ext.data.Store', {
  97. fields: f,
  98. data: data,
  99. groupField: me.groupField,
  100. getSum: function(field) {
  101. var records = me.selModel.getSelection(),
  102. total = 0,
  103. i = 0,
  104. len = records.length;
  105. for (; i < len; ++i) {
  106. total += records[i].get(field);
  107. }
  108. return total;
  109. },
  110. getCount: function() {
  111. var records = me.selModel.getSelection(),
  112. count = 0;
  113. Ext.each(records, function(item){
  114. count++;
  115. });
  116. return count;
  117. },
  118. getAverage: function(field) {
  119. var records = me.selModel.getSelection(),
  120. count = 0,
  121. sum = 0;
  122. Ext.each(records, function(item){
  123. if(item.data[me.necessaryField] != null && item.data[me.necessaryField] != ''){
  124. count++;sum += item.data[field];
  125. }
  126. });
  127. return Ext.Number.format(sum/count, '0.00');
  128. }
  129. });
  130. return store;
  131. },
  132. setLogicType: function(column, logic, y){
  133. var grid = this;
  134. if(logic == 'detno'){
  135. grid.detno = column.dataIndex;
  136. } else if(logic == 'keyField'){
  137. grid.keyField = column.dataIndex;
  138. } else if(logic == 'mainField'){
  139. grid.mainField = column.dataIndex;
  140. } else if(logic == 'necessaryField'){
  141. grid.necessaryField = column.dataIndex;
  142. if(!grid.necessaryFields){
  143. grid.necessaryFields = new Array();
  144. }
  145. grid.necessaryFields.push(column.dataIndex);
  146. if(!column.haveRendered){
  147. column.renderer = function(val, meta, record, x, y, store, view){
  148. var c = this.columns[y];
  149. if(val != null && val.toString().trim() != ''){
  150. if(c.xtype == 'datecolumn'){
  151. val = Ext.Date.format(val, 'Y-m-d');
  152. }
  153. return val;
  154. } else {
  155. if(c.xtype == 'datecolumn'){
  156. val = '';
  157. }
  158. return '<img src="' + basePath + 'resource/images/icon/need.png" title="必填字段">' +
  159. '<span style="color:blue;padding-left:2px;" title="必填字段">' + val + '</span>';
  160. }
  161. };
  162. }
  163. } else if(logic == 'groupField'){
  164. grid.groupField = column.dataIndex;
  165. }
  166. },
  167. initRecords: function(){
  168. var records = this.store.data.items;
  169. var count = 0;
  170. Ext.each(records, function(record){
  171. if(!record.index){
  172. record.index = count++;
  173. }
  174. });
  175. },
  176. setRenderer: function(column){
  177. var grid = this;
  178. if(!column.haveRendered && column.renderer != null && column.renderer != ""){
  179. var renderName = column.renderer;
  180. if(contains(column.renderer, ':', true)){
  181. var args = new Array();
  182. Ext.each(column.renderer.split(':'), function(a, index){
  183. if(index == 0){
  184. renderName = a;
  185. } else {
  186. args.push(a);
  187. }
  188. });
  189. if(!grid.RenderUtil.args[renderName]){
  190. grid.RenderUtil.args[renderName] = new Object();
  191. }
  192. grid.RenderUtil.args[renderName][column.dataIndex] = args;
  193. }
  194. column.renderer = grid.RenderUtil[renderName];
  195. column.haveRendered = true;
  196. }
  197. },
  198. setToolbar: function(columns){
  199. var grid = this;
  200. var items = [];
  201. Ext.each(columns, function(column){
  202. if(column.summaryType == 'sum'){
  203. items.push('-',{
  204. id: column.dataIndex + '_sum',
  205. itemId: column.dataIndex,
  206. xtype: 'tbtext',
  207. text: column.header + '(sum):0'
  208. });
  209. } else if(column.summaryType == 'average') {
  210. items.push('-',{
  211. id: column.dataIndex + '_average',
  212. itemId: column.dataIndex,
  213. xtype: 'tbtext',
  214. text: column.header + '(average):0'
  215. });
  216. } else if(column.summaryType == 'count') {
  217. items.push('-',{
  218. id: column.dataIndex + '_count',
  219. itemId: column.dataIndex,
  220. xtype: 'tbtext',
  221. text: column.header + '(count):0'
  222. });
  223. }
  224. });
  225. grid.bbar = {
  226. xtype: 'toolbar',
  227. dock: 'bottom',
  228. items: items
  229. };
  230. },
  231. summary: function(){
  232. var me = this,
  233. store = this.store,
  234. value;
  235. Ext.each(me.columns, function(c){
  236. if(c.summaryType == 'sum'){
  237. value = store.getSum(store.data.items, c.dataIndex);
  238. me.down('tbtext[id=' + c.dataIndex + '_sum]').setText(c.header + '(sum):' + value);
  239. } else if(c.summaryType == 'count'){
  240. value = store.getCount();
  241. me.down('tbtext[id=' + c.dataIndex + '_count]').setText(c.header + '(count):' + value);
  242. } else if(c.summaryType == 'average'){
  243. value = store.getAverage(c.dataIndex);
  244. me.down('tbtext[id=' + c.dataIndex + '_average]').setText(c.header + '(average):' + value);
  245. }
  246. });
  247. },
  248. listeners: {
  249. 'afterrender':function(){
  250. var me = this;
  251. var grids = [me, me.lockedGrid, me.normalGrid];
  252. for(var i in grids) {
  253. if(grids[i]) {
  254. grids[i].addListener('itemclick',function(grid,record){
  255. if(Number(record.data.cm_id)>0){
  256. me.FormUtil.onAdd('showCmCopDetail'+record.data.cm_id, "查询明细("+record.data.cm_id+")", 'jsps/fa/ars/showCmCopDetail.jsp?showtype='+record.data.cm_showtype+'&cmid='+record.data.cm_id+'&currency='+record.data.cm_currency+'&custcode='+record.data.cm_custcode+'&custname='+record.data.cu_name+'&yearmonth='+record.data.cm_yearmonth+'&chkumio='+me.chkumio+'&cop='+record.data.cm_cop);
  257. }
  258. });
  259. }
  260. }
  261. }
  262. }, /**
  263. * 监听一些事件,
  264. * 如Ctrl+Alt+S
  265. */
  266. addKeyBoardEvents: function(){
  267. var me = this;
  268. if(Ext.isIE){
  269. document.body.attachEvent('onkeydown', function(){//ie的事件名称不同,也不支持addEventListener
  270. if(window.event.altKey && window.event.ctrlKey && window.event.keyCode == 83){
  271. if(Ext.ComponentQuery.query('gridpanel').length > 0){//有grid
  272. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/multiform.jsp?formCondition=fo_idIS" + me.fo_id +
  273. "&gridCondition=fd_foidIS" + me.fo_id + "&whoami=" + caller);
  274. }else if(Ext.ComponentQuery.query('formpanel').length == 0){
  275. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/multiform.jsp?formCondition=fo_idIS" + me.fo_id +
  276. "&gridCondition=fd_foidIS" + me.fo_id + "&whoami=" + caller);
  277. } else {
  278. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/form.jsp?formCondition=fo_idIS" + me.fo_id +
  279. "&gridCondition=fd_foidIS" + me.fo_id);
  280. }
  281. }
  282. });
  283. document.body.attachEvent("onmouseover", function(){
  284. if(window.event.ctrlKey){
  285. var e = window.event;
  286. me.Contextvalue = e.target.textContent == "" ? e.target.value : e.target.textContent;
  287. textarea_text = parent.document.getElementById("textarea_text");
  288. textarea_text.value = me.Contextvalue;
  289. textarea_text.focus();
  290. textarea_text.select();
  291. }
  292. });
  293. } else {
  294. document.body.addEventListener("keydown", function(e){
  295. if(Ext.isFF5){//firefox不支持window.event
  296. e = e || window.event;
  297. }
  298. if(e.altKey && e.ctrlKey && e.keyCode == 83){
  299. if(Ext.ComponentQuery.query('gridpanel').length > 0&&Ext.ComponentQuery.query('formpanel').length > 0){//有grid
  300. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/multiform.jsp?formCondition=fo_idIS" + me.fo_id +
  301. "&gridCondition=fd_foidIS" + me.fo_id + "&whoami=" + caller);
  302. }else if(Ext.ComponentQuery.query('formpanel').length == 0&&Ext.ComponentQuery.query('gridpanel').length > 0){//只有form
  303. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/multigrid.jsp?formCondition=fo_idIS" + me.fo_id +
  304. "&gridCondition=fd_foidIS" + me.fo_id + "&whoami=" + caller);
  305. } else {
  306. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/form.jsp?formCondition=fo_idIS" + me.fo_id +
  307. "&gridCondition=fd_foidIS" + me.fo_id);
  308. }
  309. }
  310. });
  311. document.body.addEventListener("mouseover", function(e){
  312. if(Ext.isFF5){
  313. e = e || window.event;
  314. }
  315. if(e.ctrlKey){
  316. me.Contextvalue = e.target.textContent == "" ? e.target.value : e.target.textContent;
  317. textarea_text = parent.document.getElementById("textarea_text");
  318. textarea_text.value = me.Contextvalue;
  319. textarea_text.focus();
  320. textarea_text.select();
  321. }
  322. });
  323. }
  324. },
  325. cls: 'custom-grid',
  326. viewConfig: {
  327. getRowClass: function(record) {
  328. if(record.get('cm_showtype')=='1'){
  329. return 'custom';
  330. }else if(record.get('cm_showtype')=='3'){
  331. return 'custom-blank';
  332. }else{
  333. return 'custom-alt';
  334. }
  335. // return record.get('cm_showtype')=='1'?'custom':'custom-alt';
  336. // return record.get('index')%2 == 0 ? (!Ext.isEmpty(record.get('cm_id')) ? 'custom-first' : 'custom') :
  337. // (!Ext.isEmpty(record.get('cm_id')) ? 'custom-alt-first' : 'custom-alt');
  338. }
  339. }
  340. });