DecomSettingGrid.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. Ext.define('erp.view.pm.make.DecomSettingGrid',{
  2. extend: 'Ext.grid.Panel',
  3. requires: ['erp.view.core.plugin.CopyPasteMenu'],
  4. alias: 'widget.DecomSettingGridPanel',
  5. emptyText : $I18N.common.grid.emptyText,
  6. columnLines : true,
  7. autoScroll : true,
  8. id:'grid1',
  9. ilid:0,
  10. deleteBeforeImport:true,
  11. frame:true,
  12. store: [],
  13. columns: new Array(),
  14. bodyStyle:'background-color:#f1f1f1;',
  15. selModel: Ext.create('Ext.selection.CheckboxModel',{
  16. headerWidth: 0
  17. }),
  18. dockedItems: [{
  19. id : 'pagingtoolbar',
  20. xtype: 'erpDatalistToolbar',
  21. dock: 'bottom',
  22. displayInfo: true
  23. }],
  24. LastCondition:"",
  25. gridcondition:"",
  26. GridUtil: Ext.create('erp.util.GridUtil'),
  27. BaseUtil: Ext.create('erp.util.BaseUtil'),
  28. constructor: function(cfg) {
  29. if(cfg) {
  30. cfg.plugins = cfg.plugins || [Ext.create('Ext.ux.grid.GridHeaderFilters'), Ext.create('erp.view.core.plugin.CopyPasteMenu')];
  31. Ext.apply(this, cfg);
  32. }
  33. this.callParent(arguments);
  34. },
  35. initComponent : function(){
  36. caller = this.caller || this.BaseUtil.getUrlParam('whoami');
  37. if(!condition){
  38. var urlCondition = this.BaseUtil.getUrlParam('gridCondition');
  39. urlCondition = urlCondition == null || urlCondition == "null" ? "" : urlCondition;
  40. gridCondition = (gridCondition == null || gridCondition == "null") ? "" : gridCondition;
  41. gridCondition = gridCondition + urlCondition;
  42. gridCondition = gridCondition.replace(/IS/g, "=");
  43. condition = gridCondition;
  44. }
  45. this.getCount(caller, condition);
  46. this.callParent(arguments);
  47. },
  48. getCondition:function(condition){
  49. if(!Ext.isEmpty(this.defaultCondition)) {
  50. condition = this.defaultCondition;
  51. }
  52. condition=!condition?"":condition;
  53. if(!Ext.isEmpty(this.filterCondition)) {
  54. if(!condition || condition == '' ) {
  55. condition = this.filterCondition;
  56. } else {
  57. condition = '(' + condition + ') AND (' + this.filterCondition + ')';
  58. }
  59. }
  60. condition =BaseQueryCondition==""?condition:condition+" AND "+BaseQueryCondition;
  61. return condition;
  62. },
  63. getCount: function(c, d, m){
  64. c = c || caller;
  65. d = d || this.getCondition();
  66. var me = this;
  67. var f = d;
  68. if(!me.filterCondition && !me.searchGrid && !m) {// 大数据如果没有筛选条件
  69. var _f = me._f || getUrlParam('_f');
  70. if(_f == 1) {
  71. dataCount = 1000*pageSize;// 直接作1000页数据处理
  72. me.noCount = true;
  73. me.getColumnsAndStore(c, d);
  74. return;
  75. }
  76. }
  77. Ext.Ajax.request({//拿到grid的数据总数count
  78. url : basePath + 'common/datalistCount.action',
  79. params: {
  80. caller: c,
  81. condition: f
  82. },
  83. method : 'post',
  84. callback : function(options,success,response){
  85. var res = new Ext.decode(response.responseText);
  86. if(res.exception || res.exceptionInfo){
  87. showError(res.exceptionInfo);
  88. return;
  89. }
  90. dataCount = res.count;
  91. me.getColumnsAndStore(c, d);
  92. }
  93. });
  94. },
  95. listeners: {
  96. 'headerfiltersapply': function(grid, filters) {
  97. if(this.allowFilter){
  98. var condition = null;
  99. for(var fn in filters){
  100. var value = filters[fn],f = grid.getHeaderFilterField(fn);
  101. if(!Ext.isEmpty(value)){
  102. if(f.filtertype) {
  103. if (f.filtertype == 'numberfield') {
  104. value = fn + "=" + value + " ";
  105. }
  106. } else {
  107. if(Ext.isDate(value)){
  108. value = Ext.Date.toString(value);
  109. value = "to_char(" + fn + ",'yyyy-MM-dd')='" + value + "' ";
  110. } else {
  111. var exp_t = /^(\d{4})\-(\d{2})\-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/,
  112. exp_d = /^(\d{4})\-(\d{2})\-(\d{2})$/;
  113. if(exp_d.test(value)){
  114. value = "to_char(" + fn + ",'yyyy-MM-dd')='" + value + "' ";
  115. } else if(exp_t.test(value)){
  116. value = "to_char(" + fn + ",'yyyy-MM-dd')='" + value.substr(0, 10) + "' ";
  117. } else{
  118. if(!f.autoDim) {
  119. value = fn + " LIKE '" + value + "%' ";
  120. } else {
  121. value = fn + " LIKE '%" + value + "%' ";
  122. }
  123. }
  124. }
  125. }
  126. if(condition == null){
  127. condition = value;
  128. } else {
  129. condition = condition + " AND " + value;
  130. }
  131. }
  132. }
  133. this.filterCondition = condition;
  134. page = 1;
  135. this.getCount(caller,"");
  136. } else {
  137. this.allowFilter = true;
  138. }
  139. return false;
  140. }
  141. },
  142. getColumnsAndStore: function(caller, d, g, s){
  143. var me = this;
  144. d = d || this.getCondition();
  145. g = g || page;
  146. s = s || pageSize;
  147. me.gridcondition=condition;
  148. me.BaseUtil.getActiveTab().setLoading(true);
  149. Ext.Ajax.request({//拿到grid的columns
  150. url : basePath + 'common/datalist.action',
  151. params: {
  152. caller: caller,
  153. condition: condition,
  154. page: g,
  155. pageSize: s,
  156. _noc:1
  157. },
  158. method : 'post',
  159. callback : function(options,success,response){
  160. me.BaseUtil.getActiveTab().setLoading(false);
  161. var res = new Ext.decode(response.responseText);
  162. if(res.exception || res.exceptionInfo){
  163. showError(res.exceptionInfo);
  164. return;
  165. }
  166. var data = res.data != null ? Ext.decode(res.data.replace(/,}/g, '}').replace(/,]/g, ']')) : [];//一定要去掉多余逗号,ie对此很敏感
  167. if(me.columns && me.columns.length > 2){
  168. me.store.loadData(data);
  169. }else {
  170. var store = Ext.create('Ext.data.Store', {
  171. fields: res.fields,
  172. data: data
  173. });
  174. Ext.getCmp('grid1').reconfigure(store, res.columns);
  175. me.down('erpDatalistToolbar').afterOnLoad(page);
  176. }
  177. }
  178. });
  179. },
  180. });