ProductWhmonthSubject.js 8.0 KB

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