CraftMaterial.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.pm.mes.CraftMaterial', {
  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.CraftMaterial','core.form.Panel',
  9. 'core.form.YnField','core.grid.YnColumn', 'core.grid.TfColumn',
  10. 'core.button.Query','core.button.Close', 'core.trigger.TextAreaTrigger','core.trigger.DbfindTrigger'
  11. ],
  12. init:function(){
  13. var me = this;
  14. this.control({
  15. 'erpQueryButton' : {//筛选
  16. click: function(btn) {
  17. var mccode = Ext.getCmp('mc_code').value ,sccode = Ext.getCmp('sc_code').value;
  18. if(Ext.isEmpty(mccode)){
  19. showError('请先指定作业单号!');
  20. return;
  21. }
  22. if(Ext.isEmpty(sccode)){
  23. showError('请先指定资源号!');
  24. return;
  25. }
  26. me.query(btn);
  27. Ext.getCmp('input').focus();
  28. }
  29. },
  30. 'grid[id=qgrid]':{
  31. edit:function(editor, e) {
  32. // 编辑完成后,提交更改
  33. e.record.commit();
  34. }
  35. },
  36. '#input': {
  37. specialkey: function(f, e){//按ENTER执行确认
  38. if ([e.ENTER, e.RETURN, e.SPACE].indexOf(e.getKey()) > -1) {
  39. Ext.defer(function(){
  40. var val = e.target.value;
  41. if(val){
  42. me.onConfirm(val);
  43. }
  44. }, 50);
  45. }
  46. }
  47. },
  48. '#confirm' : {
  49. click: function(btn) {
  50. me.onConfirm();
  51. },
  52. afterrender:function(btn){
  53. btn.disable(true);
  54. }
  55. },
  56. 'numberfield[id=mcd_inqty]':{
  57. change:function(f,n,o){
  58. var qty = Ext.getCmp("mc_qty").value;
  59. Ext.getCmp("mc_restqty").setValue(qty-n);//设置剩余数的值
  60. }
  61. }
  62. });
  63. },
  64. onConfirm : function(value){
  65. var me = this, get = Ext.getCmp('get').value,back = Ext.getCmp('back').value;
  66. var result = Ext.getCmp('t_result'), grid = Ext.getCmp('qgrid'),
  67. mscode = Ext.getCmp('ms_code').value,stepcode = Ext.getCmp("sc_stepcode").value,
  68. mccode = Ext.getCmp('mc_code').value ,sccode = Ext.getCmp('sc_code').value,
  69. linecode = Ext.getCmp('sc_linecode').value,input = value;
  70. if(Ext.isEmpty(mccode)){
  71. showError('请先指定作业单号!');
  72. return;
  73. }
  74. if(Ext.isEmpty(sccode)){
  75. showError('请先指定资源号!');
  76. return;
  77. }
  78. if(Ext.isEmpty(mscode) && Ext.isElement(input)){
  79. result.append('请录入序列号!');
  80. return;
  81. }else if(Ext.isEmpty(mscode) && !Ext.isElement(input)){//enter如果“序列号”字段为空,录入框不为空,上料检测序列号
  82. var ifGet = false;
  83. if(get){
  84. ifGet = true;
  85. }
  86. Ext.Ajax.request({
  87. url : basePath + 'pm/mes/checkCraftMaterialGet.action',
  88. params: {
  89. mscode : input, //序列号
  90. mccode : mccode, //作业单号
  91. licode : linecode, //线别
  92. sccode : sccode , //资源号
  93. stepcode: stepcode, //工序编号,
  94. ifGet : ifGet //上料或者下料
  95. },
  96. method : 'post',
  97. callback : function(options,success,response){
  98. var r = new Ext.decode(response.responseText);
  99. if(r.exceptionInfo){
  100. result.append(r.exceptionInfo, 'error');
  101. }else{
  102. Ext.getCmp('ms_code').setValue(input);//检测通过则“序列号”字段显示该录入内容
  103. if(r.data && r.data.length > 0){
  104. //grid.store.loadData(r.data);
  105. var items = grid.store.data.items;
  106. //提示采集的物料的条码号
  107. Ext.each(items,function(item,idx){//获取物料ID,sp_type 条码类型,
  108. item.set('if_pick',r.data[idx].if_pick);
  109. });
  110. }
  111. if(ifGet){
  112. index = -1;
  113. me.getSelectProdcode();
  114. }
  115. }
  116. Ext.getCmp('input').setValue('');
  117. }
  118. });
  119. }else if(!Ext.isEmpty(mscode) && !Ext.isEmpty(input)){
  120. if(get){
  121. me.getCraftMaterial(result,mscode,mccode,linecode,sccode,stepcode,input);
  122. } else if(back){
  123. /*warnMsg("确定取消下料?", function(btn){
  124. if(btn == 'yes'){*/
  125. me.FormUtil.getActiveTab().setLoading(true);//loading...
  126. Ext.Ajax.request({
  127. url : basePath + 'pm/mes/backCraftMaterial.action',
  128. params: {
  129. mscode: mscode, //序列号
  130. mccode : mccode, //作业单号
  131. sccode : sccode , //资源号
  132. barcode:input //条码编号
  133. },
  134. method : 'post',
  135. callback : function(options,success,response){
  136. me.FormUtil.getActiveTab().setLoading(false);//loading...
  137. var r = new Ext.decode(response.responseText);
  138. if(r.exceptionInfo){
  139. result.append(r.exceptionInfo, 'error');
  140. }
  141. if(r.success){
  142. //下的是哪个料提示采集哪个料的条码
  143. var items = grid.store.data.items;
  144. Ext.each(items,function(item,idx){
  145. if(item.data['sp_id'] == r.result.replace('success', '')){
  146. index = idx;
  147. sp_id = item.data['sp_id'];
  148. pr_code = item.data['sp_soncode'];
  149. this.set('if_pick','未采集');
  150. this.commit();
  151. }
  152. });
  153. result.append('序列号:'+mscode+',条码:'+input + '物料:'+pr_code+',取消上料成功!');
  154. if(r.result.trim().substr(0,7) == 'success'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  155. r.result = r.result.replace('success', '');
  156. result.append('下料完成!');
  157. Ext.getCmp('ms_code').setValue('');
  158. var mcd_inqty = Ext.getCmp("mcd_inqty").value;
  159. Ext.getCmp('mcd_inqty').setValue(mcd_inqty-1);
  160. }else{
  161. result.append("请采集物料:"+pr_code+"的条码号");
  162. }
  163. }
  164. Ext.getCmp("input").setValue('');//置空录入框
  165. }
  166. });
  167. /*}
  168. });*/
  169. }
  170. }
  171. },
  172. query : function(btn){//筛选
  173. var me = this, grid = Ext.getCmp('qgrid'), form = btn.ownerCt.ownerCt;
  174. var stepcode = Ext.getCmp("sc_stepcode").value,mcprodcode = Ext.getCmp('mc_prodcode').value
  175. mccode = Ext.getCmp('mc_code').value ,sccode = Ext.getCmp('sc_code').value;
  176. var btn1 = Ext.getCmp("confirm");
  177. grid.setLoading(true);//loading...
  178. Ext.Ajax.request({//筛选之前判断
  179. url : basePath + 'pm/mes/checkCraftMaterialQuery.action',
  180. params: {
  181. mccode : mccode, //作业单号
  182. sccode : sccode , //资源号
  183. stepcode:stepcode, //工序编号
  184. mcprodcode:mcprodcode //产品编号
  185. },
  186. method : 'post',
  187. callback : function(options,success,r){
  188. grid.setLoading(false);
  189. var res = Ext.decode(r.responseText);
  190. if(res.exceptionInfo) {
  191. showError(res.exceptionInfo);
  192. btn1.setDisabled(true);
  193. return;
  194. }else{
  195. var data = res.data;
  196. Ext.getCmp("mcd_inqty").setValue(data.mcd_inqty);
  197. if(data.datas && data.datas.length > 0 ){
  198. grid.store.loadData(data.datas);
  199. btn1.setDisabled(false);
  200. } else {
  201. grid.store.removeAll();
  202. btn1.setDisabled(true);
  203. me.GridUtil.add10EmptyItems(grid);
  204. }
  205. }
  206. }
  207. });
  208. },
  209. getCraftMaterial : function(result,mscode,mccode,linecode,sccode ,stepcode,input){//上料采集
  210. var me = this;
  211. var grid = Ext.getCmp("qgrid");
  212. var result = Ext.getCmp('t_result');
  213. var prefix = grid.getStore().getAt(index).get('pr_prefix'),
  214. length = grid.getStore().getAt(index).get('pr_length');
  215. if(prefix != null && prefix!=''){//增加前缀判断
  216. var temp = input.substr(0,prefix.length);
  217. if(temp != prefix){
  218. showError('物料条码前缀是:'+prefix);
  219. Ext.getCmp('input').setValue('');
  220. return ;
  221. }
  222. }
  223. if(length != null && length!=''){
  224. if(input.length != length){
  225. showError('物料条码位数必须等于限制位数:'+length);
  226. Ext.getCmp('input').setValue('');
  227. return ;
  228. }
  229. }
  230. me.FormUtil.getActiveTab().setLoading(true);//loading...
  231. Ext.Ajax.request({
  232. url : basePath + 'pm/mes/getCraftMaterial.action',
  233. params: {
  234. mscode : mscode, //序列号
  235. mccode : mccode, //作业单号
  236. licode : linecode, //线别
  237. sccode : sccode , //资源号
  238. stepcode:stepcode , //工序编号
  239. barcode:input , //条码编号
  240. sp_id :sp_id
  241. },
  242. method : 'post',
  243. callback : function(options,success,response){
  244. me.FormUtil.getActiveTab().setLoading(false);//loading...
  245. var r = new Ext.decode(response.responseText);
  246. if(r.exceptionInfo){
  247. result.append(r.exceptionInfo, 'error');
  248. Ext.getCmp('input').setValue('');
  249. }
  250. if(r.success){
  251. //修改grid行
  252. grid.getStore().getAt(index).set('if_pick','已采集');
  253. grid.getStore().getAt(index).commit();
  254. result.append('上料成功:'+mscode+','+input+'!');
  255. Ext.getCmp('input').setValue('');
  256. if(r.result == 'success'){
  257. result.append('采集完成!');
  258. Ext.getCmp('ms_code').setValue('');
  259. //更新主表 剩余数,和计数字段
  260. var mcd_inqty = Ext.getCmp("mcd_inqty").value;
  261. Ext.getCmp('mcd_inqty').setValue(Number(mcd_inqty)+1);
  262. }else{//提示下一行采集的物料编号
  263. me.getSelectProdcode();
  264. }
  265. }
  266. }
  267. });
  268. },
  269. getSelectProdcode:function(){//获取当前需要采集物料的条码
  270. index = -1;
  271. var pr_code ;
  272. var result = Ext.getCmp('t_result');
  273. var items = Ext.getCmp('qgrid').store.data.items;
  274. //提示采集的物料的条码号
  275. Ext.each(items,function(item,idx){//获取物料ID,sp_type 条码类型,
  276. if(index == -1 && item.data['if_pick'] != '已采集'){
  277. index = idx;
  278. sp_id = item.data['sp_id'];
  279. pr_code = item.data['sp_soncode'];
  280. }
  281. });
  282. result.append("请采集物料:"+pr_code+"的条码号");
  283. }
  284. });