ATPOpDetailGridPanel3.js.svn-base 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. Ext.define('erp.view.pm.atp.ATPOpDetailGridPanel3',{
  2. extend: 'Ext.grid.Panel',
  3. requires: ['erp.view.core.plugin.CopyPasteMenu'],
  4. alias: 'widget.ATPOpDetailGridPanel3',
  5. emptyText : $I18N.common.grid.emptyText,
  6. columnLines : true,
  7. autoScroll : true,
  8. height:height,
  9. id:'grid3',
  10. frame:true,
  11. store: [],
  12. columns: new Array(),
  13. bodyStyle:'background-color:#f1f1f1;',
  14. selModel: Ext.create('Ext.selection.CheckboxModel',{
  15. headerWidth: 0
  16. }),
  17. verticalScrollerType: 'paginggridscroller',
  18. BaseUtil: Ext.create('erp.util.BaseUtil'),
  19. GridUtil: Ext.create('erp.util.GridUtil'),
  20. RenderUtil:Ext.create('erp.util.RenderUtil'),
  21. loadMask: true,
  22. disableSelection: true,
  23. invalidateScrollerOnRefresh: false,
  24. LastCondition:"",
  25. gridcondition:"",
  26. viewConfig: {
  27. trackOver: false
  28. },
  29. dockedItems: [{
  30. id : 'pagingtoolbar3',
  31. xtype: 'erpMpsToolbar',
  32. dock: 'bottom',
  33. displayInfo: true
  34. }],
  35. GridUtil: Ext.create('erp.util.GridUtil'),
  36. BaseUtil: Ext.create('erp.util.BaseUtil'),
  37. plugins: [Ext.create('Ext.ux.grid.GridHeaderFilters'), Ext.create('erp.view.core.plugin.CopyPasteMenu')],
  38. initComponent : function(){
  39. caller='Desk!MakeCommit';
  40. this.getCount(caller,"");
  41. this.callParent(arguments);
  42. },
  43. getCount: function(c, condition){
  44. c=c||caller;
  45. condition=this.getCondition(condition);
  46. var me = this;
  47. Ext.Ajax.request({//拿到grid的数据总数count
  48. url : basePath + '/common/datalistCount.action',
  49. params: {
  50. caller: c,
  51. condition: condition
  52. },
  53. method : 'post',
  54. callback : function(options,success,response){
  55. var res = new Ext.decode(response.responseText);
  56. if(res.exception || res.exceptionInfo){
  57. showError(res.exceptionInfo);
  58. return;
  59. }
  60. dataCount = res.count;
  61. me.getColumnsAndStore(caller, condition, page, pageSize);
  62. }
  63. });
  64. },
  65. getCondition:function(condition){
  66. condition =(!condition || condition=="")?"":condition;
  67. if(condition!="" && BaseQueryCondition!=""){
  68. condition=condition+" AND "+BaseQueryCondition;
  69. }else if(condition==""){
  70. condition=BaseQueryCondition;
  71. }
  72. condition=condition.replace(/pr_code/g,'mm_prodcode');
  73. if(!Ext.isEmpty(this.defaultCondition)) {
  74. condition = this.defaultCondition;
  75. }
  76. if(!Ext.isEmpty(this.filterCondition)) {
  77. if(condition == '' ) {
  78. condition = this.filterCondition;
  79. } else {
  80. condition = '(' + condition + ') AND (' + this.filterCondition + ')';
  81. }
  82. }
  83. return condition;
  84. },
  85. listeners: {
  86. 'headerfiltersapply': function(grid, filters) {
  87. if(this.allowFilter){
  88. var querycondition = null;
  89. for(var fn in filters){
  90. var value = filters[fn],f = grid.getHeaderFilterField(fn);
  91. if(!Ext.isEmpty(value)){
  92. if(f.filtertype) {
  93. if (f.filtertype == 'numberfield') {
  94. value = fn + "=" + value + " ";
  95. }
  96. } else {
  97. if(Ext.isDate(value)){
  98. value = Ext.Date.toString(value);
  99. value = "to_char(" + fn + ",'yyyy-MM-dd')='" + value + "' ";
  100. } else {
  101. var exp_t = /^(\d{4})\-(\d{2})\-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/,
  102. exp_d = /^(\d{4})\-(\d{2})\-(\d{2})$/;
  103. if(exp_d.test(value)){
  104. value = "to_char(" + fn + ",'yyyy-MM-dd')='" + value + "' ";
  105. } else if(exp_t.test(value)){
  106. value = "to_char(" + fn + ",'yyyy-MM-dd')='" + value.substr(0, 10) + "' ";
  107. } else{
  108. if(!f.autoDim) {
  109. value = fn + " LIKE '" + value + "%' ";
  110. } else {
  111. value = fn + " LIKE '%" + value + "%' ";
  112. }
  113. }
  114. }
  115. }
  116. if(querycondition == null){
  117. querycondition = value;
  118. } else {
  119. querycondition = querycondition + " AND " + value;
  120. }
  121. }
  122. }
  123. this.filterCondition = querycondition;
  124. page = 1;
  125. this.getCount(caller,"");
  126. } else {
  127. this.allowFilter = true;
  128. }
  129. return false;
  130. }
  131. },
  132. getColumnsAndStore: function(caller, condition, page, pageSize){
  133. var me = this;
  134. me.gridcondition=condition;
  135. me.BaseUtil.getActiveTab().setLoading(true);//loading...
  136. Ext.Ajax.request({//拿到grid的columns
  137. url : basePath + 'common/datalist.action',
  138. params: {
  139. caller: caller,
  140. condition: condition,
  141. page: page,
  142. pageSize: pageSize,
  143. _noc:1
  144. },
  145. method : 'post',
  146. callback : function(options,success,response){
  147. me.BaseUtil.getActiveTab().setLoading(false);
  148. var res = new Ext.decode(response.responseText);
  149. if(res.exception || res.exceptionInfo){
  150. showError(res.exceptionInfo);
  151. return;
  152. }
  153. var data = res.data != null ? Ext.decode(res.data.replace(/,}/g, '}').replace(/,]/g, ']')) : [];//一定要去掉多余逗号,ie对此很敏感
  154. var grid = this;
  155. if(me.columns && me.columns.length > 2){
  156. me.store.loadData(data);
  157. }else {
  158. var store = Ext.create('Ext.data.Store', {
  159. fields: res.fields,
  160. data: data
  161. });
  162. Ext.Array.each(res.columns, function(column, y) {
  163. if(!column.haveRendered && column.renderer != null && column.renderer != ""){
  164. if(!grid.RenderUtil){
  165. grid.RenderUtil = Ext.create('erp.util.RenderUtil');
  166. }
  167. var renderName = column.renderer;
  168. if(contains(column.renderer, ':', true)){
  169. var args = new Array();
  170. Ext.each(column.renderer.split(':'), function(a, index){
  171. if(index == 0){
  172. renderName = a;
  173. } else {
  174. args.push(a);
  175. }
  176. });
  177. if(!grid.RenderUtil.args[renderName]){
  178. grid.RenderUtil.args[renderName] = new Object();
  179. }
  180. grid.RenderUtil.args[renderName][column.dataIndex] = args;
  181. //这里只能用column.dataIndex来标志,不能用x,y,index等,
  182. //grid在render时,checkbox占一列
  183. }
  184. column.renderer = grid.RenderUtil[renderName];
  185. column.haveRendered = true;
  186. }
  187. });
  188. Ext.getCmp('grid3').reconfigure(store, res.columns);
  189. }
  190. Ext.getCmp("pagingtoolbar3").afterOnLoad();
  191. Ext.Ajax.request({//拿到grid的columns
  192. url : basePath + 'pm/mps/getSum.action',
  193. params: {
  194. caller: caller,
  195. condition:condition,
  196. fields:'mm_qty-mm_havegetqty',
  197. _noc:1
  198. },
  199. method : 'post',
  200. callback : function(options,success,response){
  201. me.BaseUtil.getActiveTab().setLoading(false);
  202. var res = new Ext.decode(response.responseText);
  203. if(res.exception || res.exceptionInfo){
  204. showError(res.exceptionInfo);
  205. return;
  206. }else if(res.success){
  207. var obj=new Ext.decode(res.data);
  208. var text=Ext.getCmp('text3');
  209. if(text){
  210. text.setText('未领数量 :'+obj['mm_qty-mm_havegetqty']);
  211. }else {
  212. Ext.getCmp('pagingtoolbar3').insert(16,{
  213. xtype:'tbtext',
  214. id:'text3',
  215. text:'未领数量 :'+obj['mm_qty-mm_havegetqty']
  216. });
  217. }
  218. }
  219. }
  220. });
  221. }
  222. });
  223. }
  224. });