SNRange.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.pm.make.SNRange', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. BaseUtil: Ext.create('erp.util.BaseUtil'),
  6. GridUtil: Ext.create('erp.util.GridUtil'),
  7. views:[
  8. 'pm.make.SNRange','core.form.Panel','pm.make.SNRangeGrid','common.datalist.Toolbar',
  9. 'core.button.DownloadTemp','core.button.SNimport','core.button.ClearSN','core.button.UpExcel',
  10. 'core.button.Close'
  11. ],
  12. init:function(){
  13. var me = this;
  14. me.BaseUtil = Ext.create('erp.util.BaseUtil');
  15. me.GridUtil = Ext.create('erp.util.GridUtil');
  16. this.control({
  17. 'erpDownloadTempButton': {
  18. afterrender: function(btn){
  19. var status = Ext.getCmp('re_statuscode');
  20. if(status && status.value != 'ENTERING'){
  21. btn.hide();
  22. }
  23. },
  24. click: function(btn){
  25. var grid = Ext.getCmp('grid1');
  26. if(grid){
  27. me.BaseUtil.exportGrid(grid);
  28. }
  29. }
  30. },
  31. 'erpSNimportButton':{
  32. afterrender: function(btn){
  33. var status = Ext.getCmp('re_statuscode');
  34. if(status && status.value != 'ENTERING'){
  35. btn.hide();
  36. }
  37. var grid = Ext.getCmp('grid1');
  38. btn.upexcel = function(field){
  39. if(grid){
  40. btn.getForm().submit({
  41. url: basePath + 'pm/make/upexcel.action?caller='+caller,
  42. waitMsg: "正在解析Excel",
  43. success: function(fp, o){
  44. field.reset();
  45. grid.ilid = o.result.ilid;
  46. me.checkdata(grid);
  47. },
  48. failure: function(fp, o){
  49. if(o.result.size){
  50. showError(o.result.error + " " + Ext.util.Format.fileSize(o.result.size));
  51. field.reset();
  52. } else {
  53. showError(o.result.error);
  54. field.reset();
  55. }
  56. }
  57. });
  58. }
  59. };
  60. }
  61. },
  62. 'erpClearSNButton': {
  63. afterrender: function(btn){
  64. var status = Ext.getCmp('re_statuscode');
  65. if(status && status.value != 'ENTERING'){
  66. btn.hide();
  67. }
  68. },
  69. click: function(btn){
  70. var reid = Ext.getCmp('re_id').value;
  71. var grid = Ext.getCmp('grid1');
  72. if(grid&&grid.getStore().getCount()==0){
  73. showError('明细行为空,不需要清除');
  74. }else{
  75. me.clearSN(reid);
  76. }
  77. }
  78. }
  79. })
  80. },
  81. /**
  82. * 数据校验
  83. */
  84. checkdata: function(grid){
  85. var me = this;
  86. var p = Ext.create('Ext.ProgressBar', {
  87. width: '60%',
  88. text: '准备校验中...',
  89. floating: true,
  90. renderTo: Ext.getBody()
  91. }).show();
  92. grid.setLoading(true);
  93. // 校验+清除校验环境
  94. me.onCheck(grid, p, function(){
  95. //刷新grid.renderer
  96. me.getCheckResult(grid, p);
  97. });
  98. },
  99. onCheck: function(grid, process, callback) {
  100. process.updateProgress(0.4, '准备完毕,正在校验...', true);
  101. Ext.Ajax.request({
  102. url: basePath + 'pm/make/checkInitData.action',
  103. timeout: 300000,
  104. params: {
  105. id: grid.ilid,
  106. caller : caller
  107. },
  108. method: 'post',
  109. callback: function(opt, s, r){
  110. var res = Ext.decode(r.responseText);
  111. if(!res) {
  112. grid.setLoading(false);
  113. p.destroy();
  114. Ext.Msg.alert('发现错误', '连接超时');
  115. } else if(res.success) {
  116. process.updateProgress(0.8, '校验完成,正在获取校验结果...', true);
  117. callback.call();
  118. }
  119. }
  120. });
  121. },
  122. /**
  123. * 从数据库取校验结果
  124. */
  125. getCheckResult: function(grid, p){
  126. var reid = Ext.getCmp('re_id').value;
  127. grid.setLoading(true);
  128. Ext.Ajax.request({
  129. url: basePath + 'pm/make/checkOrInsert.action',
  130. timeout: 60000,
  131. params: {
  132. id: grid.ilid,
  133. reid:reid
  134. },
  135. method: 'post',
  136. callback: function(opt, s, r){
  137. p.destroy();
  138. grid.setLoading(false);
  139. var res = r.responseText;
  140. if(res.exceptionInfo != null){
  141. showError(res.exceptionInfo);return;
  142. } else {
  143. Ext.Msg.alert("提示","导入成功!",function(){
  144. window.location.reload();
  145. });
  146. }
  147. }
  148. });
  149. },
  150. clearSN: function(id){
  151. var mm = this;
  152. Ext.Ajax.request({
  153. url : basePath + "pm/make/cleardetail.action",
  154. params: {
  155. id : id,
  156. caller : caller
  157. },
  158. method : 'post',
  159. callback : function(options,success,response){
  160. var res = new Ext.decode(response.responseText);
  161. if(res.exceptionInfo != null){
  162. showError(res.exceptionInfo);return;
  163. }else{
  164. Ext.Msg.alert("提示","清除成功!",function(){
  165. window.location.reload();
  166. });
  167. }
  168. }
  169. });
  170. }
  171. });