ProductWhmonthWareproduct.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.scm.reserve.ProductWhmonthWareproduct', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. BaseUtil: Ext.create('erp.util.BaseUtil'),
  6. views:[
  7. 'scm.reserve.ProductWhmonth','common.datalist.GridPanel','common.datalist.Toolbar','common.batchDeal.Form',
  8. 'core.trigger.DbfindTrigger','core.form.ConDateField','core.form.MonthDateField',
  9. 'core.button.TurnPWHMonthAdjust'
  10. ],
  11. init:function(){
  12. var me = this;
  13. this.control({
  14. 'erpDatalistGridPanel': {
  15. itemclick: this.onGridItemClick,
  16. afterrender:function(grid){
  17. Ext.getCmp('datalistexport').setDisabled(true);
  18. if(Ext.isIE){
  19. document.body.attachEvent('onkeydown', function(){
  20. if(window.event.ctrlKey && window.event.keyCode == 67){//Ctrl + C
  21. var e = window.event;
  22. if(e.srcElement) {
  23. window.clipboardData.setData('text', e.srcElement.innerHTML);
  24. }
  25. }
  26. });
  27. } else {
  28. grid.getEl().dom.addEventListener("mouseover", function(e){
  29. if(e.ctrlKey){
  30. var Contextvalue=e.target.textContent==""?e.target.value:e.target.textContent;
  31. textarea_text = parent.document.getElementById("textarea_text");
  32. textarea_text.value=Contextvalue;
  33. textarea_text.focus();
  34. textarea_text.select();
  35. }
  36. });
  37. }
  38. }
  39. },
  40. 'button[id=query]':{
  41. beforerender:function(btn){
  42. btn.handler=function(){
  43. var grid = Ext.getCmp('grid');
  44. var condition = btn.ownerCt.ownerCt.getCondition(grid);
  45. grid.getCount(caller, condition);
  46. };
  47. }
  48. },
  49. 'button[id=export]':{
  50. beforerender:function(btn){
  51. btn.handler = Ext.emptyFn;
  52. me.BaseUtil.addListener('click', function(){
  53. var grid = Ext.getCmp('grid');
  54. var condition = btn.ownerCt.ownerCt.getCondition(grid),
  55. _con = grid.getCondition();
  56. if(!Ext.isEmpty(_con))
  57. condition += ' and (' + _con + ")";
  58. me.BaseUtil.createExcel(caller, 'datalist', condition, null, null, null, grid);
  59. }, btn, 10000);
  60. }
  61. },
  62. 'monthdatefield[name=pwm_yearmonth]':{
  63. beforerender:function(field){
  64. field.autoValue=false;
  65. field.fromnow=false;
  66. me.getCurrentMonth(field);
  67. }
  68. },
  69. 'erpVastDealButton':{
  70. click:function(btn){
  71. var currentMonth= btn.ownerCt.ownerCt.down('monthdatefield').value;
  72. if(!currentMonth) {
  73. showError('期间不能为空!') ;
  74. return
  75. }else{
  76. me.BaseUtil.getActiveTab().setLoading(true);
  77. Ext.Ajax.request({
  78. url:basePath+'scm/product/RefreshProdMonthNew.action',
  79. method:'post',
  80. params:{
  81. currentMonth:currentMonth
  82. },
  83. timeout: 1200000,
  84. callback : function(options,success,response){
  85. me.BaseUtil.getActiveTab().setLoading(false);
  86. var res = new Ext.decode(response.responseText);
  87. if(res.exceptionInfo != null){
  88. showError(res.exceptionInfo);return;
  89. }
  90. Ext.Msg.alert("提示", "刷新成功!", function(){
  91. Ext.getCmp('query').handler();
  92. });
  93. }
  94. });
  95. }
  96. }
  97. },
  98. 'erpTurnPWHMonthAdjustButton':{
  99. click:function(btn){
  100. var currentMonth= btn.ownerCt.ownerCt.down('monthdatefield').value;
  101. if(!currentMonth) {
  102. showError('期间不能为空!') ;
  103. return
  104. }else{
  105. me.BaseUtil.getActiveTab().setLoading(true);
  106. Ext.Ajax.request({
  107. url:basePath+'scm/product/turnProductWHMonthAdjust.action',
  108. method:'post',
  109. params:{
  110. currentMonth:currentMonth
  111. },
  112. timeout: 1200000,
  113. callback : function(options,success,response){
  114. me.BaseUtil.getActiveTab().setLoading(false);
  115. var res = new Ext.decode(response.responseText);
  116. if(res.log){
  117. showError(res.log);
  118. } else {
  119. showError(res.exceptionInfo);
  120. }
  121. }
  122. });
  123. }
  124. }
  125. }
  126. });
  127. },
  128. getCurrentMonth: function(f) {
  129. Ext.Ajax.request({
  130. url: basePath + 'fa/getMonth.action',
  131. params: {
  132. type: 'MONTH-P'
  133. },
  134. callback: function(opt, s, r) {
  135. var rs = Ext.decode(r.responseText);
  136. if(rs.data) {
  137. f.setValue(rs.data.PD_DETNO);
  138. }
  139. }
  140. });
  141. },
  142. onGridItemClick: function(selModel, record){//grid行选择
  143. var me = this;
  144. if(keyField != null && keyField != ''){//有些datalist不需要打开明细表,这些表在datalist表里面不用配dl_keyField
  145. var value = record.data[keyField];
  146. var formCondition = keyField + "IS" + value ;
  147. var gridCondition = pfField + "IS" + value;
  148. var panel = Ext.getCmp(caller + keyField + "=" + value);
  149. var main = parent.Ext.getCmp("content-panel");
  150. if(!main){
  151. main = parent.parent.Ext.getCmp("content-panel");
  152. }
  153. if(!panel){
  154. var title = "";
  155. if (value.toString().length>4) {
  156. title = value.toString().substring(value.toString().length-4);
  157. } else {
  158. title = value;
  159. }
  160. var myurl = '';
  161. if(me.BaseUtil.contains(url, '?', true)){
  162. myurl = url + '&formCondition='+formCondition+'&gridCondition='+gridCondition;
  163. } else {
  164. myurl = url + '?formCondition='+formCondition+'&gridCondition='+gridCondition;
  165. }
  166. myurl += "&datalistId=" + main.getActiveTab().id;
  167. main.getActiveTab().currentStore = me.getCurrentStore(value);//用于单据翻页
  168. panel = {
  169. title : me.BaseUtil.getActiveTab().title+'('+title+')',
  170. tag : 'iframe',
  171. tabConfig:{tooltip:me.BaseUtil.getActiveTab().tabConfig.tooltip+'('+keyField + "=" + value+')'},
  172. frame : true,
  173. border : false,
  174. layout : 'fit',
  175. iconCls : 'x-tree-icon-tab-tab1',
  176. html : '<iframe id="iframe_maindetail_'+caller+"_"+value+'" src="' + myurl + '" height="100%" width="100%" frameborder="0" style="border-width: 0px;padding: 0px;" scrolling="auto"></iframe>',
  177. closable : true,
  178. listeners : {
  179. close : function(){
  180. if(!main){
  181. main = parent.parent.Ext.getCmp("content-panel");
  182. }
  183. main.setActiveTab(main.getActiveTab().id);
  184. }
  185. }
  186. };
  187. this.openTab(panel, caller + keyField + "=" + record.data[keyField]);
  188. }else{
  189. main.setActiveTab(panel);
  190. }
  191. }
  192. },
  193. openTab : function (panel,id){
  194. var o = (typeof panel == "string" ? panel : id || panel.id);
  195. var main = parent.Ext.getCmp("content-panel");
  196. if(!main) {
  197. main =parent.parent.Ext.getCmp("content-panel");
  198. }
  199. var tab = main.getComponent(o);
  200. if (tab) {
  201. main.setActiveTab(tab);
  202. } else if(typeof panel!="string"){
  203. panel.id = o;
  204. var p = main.add(panel);
  205. main.setActiveTab(p);
  206. }
  207. },
  208. getCurrentStore: function(value){
  209. var grid = Ext.getCmp('grid');
  210. var items = grid.store.data.items;
  211. var array = new Array();
  212. var o = null;
  213. Ext.each(items, function(item, index){
  214. o = new Object();
  215. o.selected = false;
  216. if(index == 0){
  217. o.prev = null;
  218. } else {
  219. o.prev = items[index-1].data[keyField];
  220. }
  221. if(index == items.length - 1){
  222. o.next = null;
  223. } else {
  224. o.next = items[index+1].data[keyField];
  225. }
  226. var v = item.data[keyField];
  227. o.value = v;
  228. if(v == value)
  229. o.selected = true;
  230. array.push(o);
  231. });
  232. return array;
  233. },
  234. });