PackageTransfer.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.pm.mes.PackageTransfer', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. GridUtil: Ext.create('erp.util.GridUtil'),
  6. BaseUtil: Ext.create('erp.util.BaseUtil'),
  7. views: [
  8. 'pm.mes.PackageTransfer', 'core.trigger.DbfindTrigger',
  9. 'core.form.YnField', 'core.grid.YnColumn', 'core.grid.TfColumn',
  10. 'core.button.Query', 'core.button.Close', 'core.button.Print',
  11. 'core.trigger.TextAreaTrigger','core.trigger.BoxCodeTrigger2'
  12. ],
  13. init: function() {
  14. var me = this;
  15. this.control({
  16. '#pa_outboxcode':{//需要转移的号带出数量
  17. specialkey: function(f, e) { //按ENTER执行确认
  18. if (e.getKey() == e.ENTER) {
  19. if (f.value != null && f.value != '') {
  20. me.getOriginalQty(f.value);
  21. }
  22. }
  23. }
  24. },
  25. '#pa_outboxnew':{
  26. afterrender:function(){
  27. Ext.create('Ext.tip.ToolTip', {
  28. target: 'pa_outboxnew-triggerWrap',
  29. html: '生成箱号'
  30. });
  31. },
  32. specialkey: function(f, e) { //按ENTER执行确认
  33. if (e.getKey() == e.ENTER) {
  34. if (f.value != null && f.value != '') {
  35. var old = Ext.getCmp('pa_outboxcode').value;
  36. if(Ext.isEmpty(old)){
  37. showError('需要转移的包装箱号不允许为空');
  38. return;
  39. }
  40. me.getFormStore( Ext.getCmp("form").getForm().getValues());
  41. }
  42. }
  43. }
  44. },
  45. '#entercode': {
  46. specialkey: function(f, e) { //按ENTER执行确认
  47. if (e.getKey() == e.ENTER) {
  48. if (f.value != null && f.value != '') {
  49. me.onConfirm();
  50. }
  51. }
  52. }
  53. },
  54. 'button[id=generatePackageBtn]': { //生成包装箱号
  55. click: function(btn) {
  56. var pa_totalqtynew = Ext.getCmp("pa_totalqtynew").value,
  57. pa_outboxcode = Ext.getCmp("pa_outbox").value;
  58. var result = Ext.getCmp('t_result');
  59. if (Ext.isEmpty(pa_outboxcode)) {
  60. showError('请先指定箱号!');
  61. return;
  62. } else if (Ext.isEmpty(pa_totalqtynew) || pa_totalqtynew == 0 || pa_totalqtynew == '0') {
  63. showError("箱内数量不允许为空或者零!");
  64. return;
  65. }
  66. Ext.Ajax.request({ //拿到grid的columns
  67. url: basePath + "pm/mes/generateNewPackage.action",
  68. params: {
  69. pa_totalqtynew: pa_totalqtynew, //目标箱号箱内容量
  70. pa_oldcode: pa_outboxcode // 原箱号
  71. },
  72. method: 'post',
  73. callback: function(options, success, response) {
  74. var res = new Ext.decode(response.responseText);
  75. if (res.exceptionInfo) {
  76. result.append(res.exceptionInfo, 'error');
  77. showError(res.exceptionInfo);
  78. return;
  79. }
  80. var data = res.data;
  81. if (data ) { //设置包装箱号
  82. result.append('生成箱号:' + data['pa_code'] + '成功!');
  83. Ext.getCmp("pa_outboxnew").setValue(data['pa_code']);
  84. Ext.getCmp("pa_totalqtynew").setValue(data['pa_totalqtynew']);
  85. }
  86. }
  87. });
  88. }
  89. }
  90. });
  91. },
  92. getOriginalQty:function(data){
  93. Ext.Ajax.request({//拿到grid的columns
  94. url : basePath + "pm/bom/getDescription.action",
  95. params: {
  96. tablename: 'package',
  97. field: 'pa_totalqty',
  98. condition: "pa_status=0 and pa_outboxcode='"+data+"'"
  99. },
  100. method : 'post',
  101. callback : function(options,success,response){
  102. var res = new Ext.decode(response.responseText);
  103. if(res.exceptionInfo){
  104. showError(res.exceptionInfo);
  105. Ext.getCmp('pa_outboxcode').setValue('');
  106. Ext.getCmp('pa_totalqty').setValue('');
  107. return;
  108. }
  109. if(res.description == null){
  110. showError('箱号:'+data+'错误,不存在或者状态无效!');
  111. Ext.getCmp('pa_outboxcode').setValue('');
  112. Ext.getCmp('pa_totalqty').setValue('');
  113. return;
  114. }else if(res.description == '0' || res.description == 0){
  115. showError('箱号:'+data+'错误,库存数量为0!');
  116. Ext.getCmp('pa_outboxcode').setValue('');
  117. Ext.getCmp('pa_totalqty').setValue('');
  118. return;
  119. }else{//包装箱号正确设置编号数量
  120. Ext.getCmp('pa_totalqty').setValue(res.description);
  121. Ext.getCmp('pa_outboxnew').focus(true);
  122. }
  123. }
  124. });
  125. },
  126. onConfirm: function() { //确认采集序列号 或者子箱号
  127. var me = this;
  128. var serial = Ext.getCmp('serial').value,
  129. pa_outboxcode = Ext.getCmp('pa_outboxcode').value,
  130. pa_outboxnew = Ext.getCmp('pa_outboxnew').value,
  131. entercode = Ext.getCmp('entercode').value,
  132. result = Ext.getCmp('t_result');
  133. //判断剩余装箱数量
  134. if (Ext.isEmpty(pa_outboxcode)) {
  135. showError('请先指定箱号!');
  136. return;
  137. } else if (Ext.isEmpty(pa_outboxnew)) {
  138. showError('请先指定目标箱号!');
  139. return;
  140. }
  141. if (serial) { //输入序列号
  142. if (Ext.isEmpty(entercode)) {
  143. result.append('请输入序列号!');
  144. return;
  145. }
  146. var condition = {
  147. pa_oldcode: pa_outboxcode,
  148. pa_newcode: pa_outboxnew,
  149. serialcode: entercode
  150. };
  151. Ext.Ajax.request({ //采集序列号
  152. url: basePath + "pm/mes/getPackageDetailSerial.action",
  153. params: {
  154. condition: unescape(escape(Ext.JSON.encode(condition)))
  155. },
  156. method: 'post',
  157. callback: function(options, success, response) {
  158. var res = new Ext.decode(response.responseText);
  159. if (res.exceptionInfo) {
  160. result.append(res.exceptionInfo, 'error');
  161. Ext.getCmp("entercode").setValue('');
  162. showError(res.exceptionInfo);
  163. return;
  164. } else {
  165. result.append('采集序列号:' + entercode + '成功!');
  166. //数据添加到grid中
  167. me.loadNewStore({
  168. pd_outboxcode: pa_outboxnew,
  169. pd_barcode: entercode,
  170. pd_innerqty: '1'
  171. });
  172. Ext.getCmp("entercode").setValue('');
  173. }
  174. }
  175. });
  176. } else { //输入子箱号
  177. if (Ext.isEmpty(entercode)) {
  178. result.append('请输入子箱号!');
  179. return;
  180. }
  181. }
  182. },
  183. getFormStore: function(data) {
  184. if (data['pa_outboxcode'] == data['pa_outboxnew']) {
  185. showError('目标箱号不允许和原箱号相同!');
  186. Ext.getCmp('pa_outboxnew').setValue('');
  187. Ext.getCmp('pa_totalqtynew').setValue('');
  188. return;
  189. }
  190. Ext.Ajax.request({
  191. url: basePath + 'pm/mes/getFormTStore.action',
  192. params: {
  193. condition: unescape(escape(Ext.JSON.encode(data)))
  194. },
  195. method: 'post',
  196. callback: function(options, success, response) {
  197. var r = new Ext.decode(response.responseText);
  198. if (r.exceptionInfo) {
  199. showError(r.exceptionInfo); return;
  200. } else if (r.data) {
  201. Ext.getCmp("form").getForm().setValues(r.data);
  202. }
  203. }
  204. });
  205. },
  206. loadNewStore: function(data) {
  207. var me = this;
  208. var grid = Ext.getCmp("querygrid");
  209. var datas = [];
  210. var items = grid.store.data.items;
  211. Ext.each(items, function(item, index) {
  212. var o = new Object();
  213. Ext.each(grid.columns, function(c) {
  214. if (!Ext.isEmpty(item.data[c.dataIndex])) {
  215. o[c.dataIndex] = item.data[c.dataIndex];
  216. }
  217. });
  218. if (!o) {
  219. datas.push(o);
  220. }
  221. });
  222. datas.push(data);
  223. grid.store.loadData(datas);
  224. }
  225. });