CostAccount.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.co.cost.CostAccount', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. BaseUtil: Ext.create('erp.util.BaseUtil'),
  6. views:[
  7. 'co.cost.CostAccountForm','co.cost.CostAccount','core.button.BOMVastCost',
  8. 'core.button.Confirm','core.button.Close','core.form.MonthDateField'
  9. ] ,
  10. init:function(){
  11. var me = this;
  12. this.control({
  13. 'erpCloseButton': {
  14. click: function(btn){
  15. me.FormUtil.onClose();
  16. }
  17. },
  18. 'erpConfirmButton': {
  19. click: function(btn){
  20. confirm('确定开始成本计算?') && me.confirm();
  21. }
  22. },
  23. 'erpBOMVastCostButton': {
  24. click: function(btn){
  25. confirm('确认要计算当前月份成本表里产品的BOM成本?') && me.productCost();
  26. }
  27. },
  28. 'monthdatefield': {
  29. afterrender: function(f) {
  30. this.getCurrentMonth(f, "MONTH-T");
  31. }
  32. }
  33. });
  34. },
  35. getForm: function(btn){
  36. return btn.ownerCt.ownerCt;
  37. },
  38. confirm: function(){
  39. var begin = new Date().getTime();
  40. var mb = new Ext.window.MessageBox();
  41. mb.wait('正在核算中','请稍后...',{
  42. interval: 60000, //bar will move fast!
  43. duration: 1800000,
  44. increment: 20,
  45. scope: this,
  46. });
  47. Ext.Ajax.request({
  48. url : basePath + "co/cost/countCost.action",
  49. params:{
  50. param:{date:Ext.getCmp('date').value},
  51. },
  52. method:'post',
  53. timeout: 2400000,
  54. callback:function(options,success,response){
  55. var end = new Date().getTime();
  56. mb.close();
  57. var localJson = new Ext.decode(response.responseText);
  58. if(localJson.success){
  59. Ext.Msg.alert("提示","操作成功!耗时" + Ext.Number.toFixed((end-begin)/60000,2) +"分钟");
  60. } else {
  61. if(localJson.exceptionInfo){
  62. var str = localJson.exceptionInfo;
  63. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  64. str = str.replace('AFTERSUCCESS', '');
  65. showError(str);
  66. postSuccess(function(){
  67. window.location.reload();
  68. });
  69. } else {
  70. showError(str);return;
  71. }
  72. }
  73. }
  74. }
  75. });
  76. },
  77. productCost: function(){
  78. var begin = new Date().getTime();
  79. var mb = new Ext.window.MessageBox();
  80. mb.wait('正在计算中','请稍后...',{
  81. interval: 60000, //bar will move fast!
  82. duration: 1800000,
  83. increment: 20,
  84. scope: this,
  85. });
  86. Ext.Ajax.request({
  87. url : basePath + "co/cost/countStepCost.action",
  88. params:{
  89. param:{date:Ext.getCmp('date').value},
  90. },
  91. method:'post',
  92. timeout: 2400000,
  93. callback:function(options,success,response){
  94. var end = new Date().getTime();
  95. mb.close();
  96. var localJson = new Ext.decode(response.responseText);
  97. if(localJson.success){
  98. Ext.Msg.alert("提示","操作成功!耗时" + Ext.Number.toFixed((end-begin)/60000,2) +"分钟");
  99. } else {
  100. if(localJson.exceptionInfo){
  101. var str = localJson.exceptionInfo;
  102. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  103. str = str.replace('AFTERSUCCESS', '');
  104. showError(str);
  105. postSuccess(function(){
  106. window.location.reload();
  107. });
  108. } else {
  109. showError(str);return;
  110. }
  111. }
  112. }
  113. }
  114. });
  115. },
  116. getCurrentMonth: function(f, type) {
  117. Ext.Ajax.request({
  118. url: basePath + 'fa/getMonth.action',
  119. params: {
  120. type: type
  121. },
  122. callback: function(opt, s, r) {
  123. var rs = Ext.decode(r.responseText);
  124. if(rs.data) {
  125. f.setValue(rs.data.PD_DETNO);
  126. }
  127. }
  128. });
  129. }
  130. });