DeskProductGridPanel1.js 7.0 KB

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