ATPOpDetailGridPanel4.js.svn-base 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. Ext.define('erp.view.pm.atp.ATPOpDetailGridPanel4',{
  2. extend: 'Ext.grid.Panel',
  3. requires: ['erp.view.core.plugin.CopyPasteMenu'],
  4. alias: 'widget.ATPOpDetailGridPanel4',
  5. emptyText : $I18N.common.grid.emptyText,
  6. columnLines : true,
  7. autoScroll : true,
  8. height:height,
  9. id:'grid4',
  10. gridcondition:"",
  11. store: [],
  12. columns: new Array(),
  13. bodyStyle:'background-color:#f1f1f1;',
  14. selModel: Ext.create('Ext.selection.CheckboxModel',{
  15. headerWidth: 0
  16. }),
  17. layout:'fit',
  18. LastCondition:"",
  19. dockedItems: [{
  20. id : 'pagingtoolbar4',
  21. xtype: 'erpMpsToolbar',
  22. dock: 'bottom',
  23. displayInfo: true
  24. }],
  25. caller:'ATPDATA',
  26. GridUtil: Ext.create('erp.util.GridUtil'),
  27. BaseUtil: Ext.create('erp.util.BaseUtil'),
  28. plugins: [Ext.create('Ext.ux.grid.GridHeaderFilters'), Ext.create('erp.view.core.plugin.CopyPasteMenu')],
  29. initComponent : function(){
  30. this.getCount(caller,"");
  31. this.callParent(arguments);
  32. },
  33. getCount: function(c, condition){
  34. var me = this;
  35. c=c||caller;
  36. var findcondition=me.getCondition(condition);
  37. Ext.Ajax.request({//拿到grid的数据总数count
  38. url : basePath + '/common/datalistCount.action',
  39. params: {
  40. caller: caller,
  41. condition: findcondition,
  42. _noc:1
  43. },
  44. method : 'post',
  45. callback : function(options,success,response){
  46. var res = new Ext.decode(response.responseText);
  47. if(res.exception || res.exceptionInfo){
  48. showError(res.exceptionInfo);
  49. return;
  50. }
  51. dataCount = res.count;
  52. me.getColumnsAndStore(caller, findcondition, page, pageSize);
  53. }
  54. });
  55. },
  56. getCondition:function(condition){
  57. condition =(!condition || condition=="")?atpcondition:condition+" AND "+atpcondition;
  58. condition+=" AND ad_kind='NEED'";
  59. condition =BaseQueryCondition==""?condition:condition+" AND "+BaseQueryCondition;
  60. condition=condition.replace(/pr_code/g,'ad_prodcode');
  61. if(!Ext.isEmpty(this.defaultCondition)) {
  62. condition = this.defaultCondition;
  63. }
  64. if(!Ext.isEmpty(this.filterCondition)) {
  65. if(condition == '' ) {
  66. condition = this.filterCondition;
  67. } else {
  68. condition = '(' + condition + ') AND (' + this.filterCondition + ')';
  69. }
  70. }
  71. condition =BaseQueryCondition==""?condition:condition+" AND "+BaseQueryCondition;
  72. return condition;
  73. },
  74. listeners: {
  75. 'headerfiltersapply': function(grid, filters) {
  76. if(this.allowFilter){
  77. var condition = null;
  78. for(var fn in filters){
  79. var value = filters[fn],f = grid.getHeaderFilterField(fn);
  80. if(!Ext.isEmpty(value)){
  81. if(f.filtertype) {
  82. if (f.filtertype == 'numberfield') {
  83. value = fn + "=" + value + " ";
  84. }
  85. } else {
  86. if(Ext.isDate(value)){
  87. value = Ext.Date.toString(value);
  88. value = "to_char(" + fn + ",'yyyy-MM-dd')='" + value + "' ";
  89. } else {
  90. var exp_t = /^(\d{4})\-(\d{2})\-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/,
  91. exp_d = /^(\d{4})\-(\d{2})\-(\d{2})$/;
  92. if(exp_d.test(value)){
  93. value = "to_char(" + fn + ",'yyyy-MM-dd')='" + value + "' ";
  94. } else if(exp_t.test(value)){
  95. value = "to_char(" + fn + ",'yyyy-MM-dd')='" + value.substr(0, 10) + "' ";
  96. } else{
  97. if (f.xtype == 'combo' || f.xtype == 'combofield') {
  98. if (value == '-所有-') {
  99. continue;
  100. } else if (value == '-无-') {
  101. value = 'nvl(' + fn + ',\' \')=\' \'';
  102. } else {
  103. value = fn + " LIKE '" + value + "%' ";
  104. }
  105. } else {
  106. if(f.ignoreCase) {// 忽略大小写
  107. fn = 'upper(' + fn + ')';
  108. value = value.toUpperCase();
  109. }
  110. if(!f.autoDim) {
  111. value = fn + " LIKE '" + value + "%' ";
  112. } else {
  113. value = fn + " LIKE '%" + value + "%' ";
  114. }
  115. }
  116. }
  117. }
  118. }
  119. if(condition == null){
  120. condition = value;
  121. } else {
  122. condition = condition + " AND " + value;
  123. }
  124. }
  125. }
  126. this.filterCondition = condition;
  127. page = 1;
  128. this.getCount(caller,"");
  129. } else {
  130. this.allowFilter = true;
  131. }
  132. return false;
  133. }
  134. },
  135. getColumnsAndStore: function(caller, condition, page, pageSize){
  136. var me = this;
  137. me.gridcondition=condition;
  138. me.BaseUtil.getActiveTab().setLoading(true);//loading...
  139. Ext.Ajax.request({//拿到grid的columns
  140. url : basePath + 'common/datalist.action',
  141. params: {
  142. caller: caller,
  143. condition: condition,
  144. page: page,
  145. pageSize: pageSize,
  146. _noc:1
  147. },
  148. method : 'post',
  149. callback : function(options,success,response){
  150. me.BaseUtil.getActiveTab().setLoading(false);
  151. var res = new Ext.decode(response.responseText);
  152. if(res.exception || res.exceptionInfo){
  153. showError(res.exceptionInfo);
  154. return;
  155. }
  156. var data = res.data != null ? Ext.decode(res.data.replace(/,}/g, '}').replace(/,]/g, ']')) : [];//一定要去掉多余逗号,ie对此很敏感
  157. if(me.columns && me.columns.length > 2){
  158. me.store.loadData(data);
  159. }else {
  160. var store = Ext.create('Ext.data.Store', {
  161. fields: res.fields,
  162. data: data
  163. });
  164. Ext.getCmp('grid4').reconfigure(store, res.columns);
  165. }
  166. Ext.getCmp("pagingtoolbar4").afterOnLoad();
  167. Ext.Ajax.request({//拿到grid的columns
  168. url : basePath + 'pm/mps/getSum.action',
  169. params: {
  170. caller: caller,
  171. condition:condition,
  172. fields:'ad_needqty',
  173. _noc:1
  174. },
  175. method : 'post',
  176. callback : function(options,success,response){
  177. me.BaseUtil.getActiveTab().setLoading(false);
  178. var res = new Ext.decode(response.responseText);
  179. if(res.exception || res.exceptionInfo){
  180. showError(res.exceptionInfo);
  181. return;
  182. }else if(res.success){
  183. var obj=new Ext.decode(res.data);
  184. var text=Ext.getCmp('text4');
  185. if(text){
  186. text.setText('需求数:'+obj.md_Needqty);
  187. }else {
  188. Ext.getCmp('pagingtoolbar4').insert(16,{
  189. xtype:'tbtext',
  190. id:'text4',
  191. text:'需求数 :'+obj.md_Needqty
  192. });
  193. }
  194. }
  195. }
  196. });
  197. }
  198. });
  199. },
  200. });