PackageCollection.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.pm.mes.PackageCollection', {
  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.PackageCollection','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.BoxCodeTrigger','core.grid.ButtonColumn'
  12. ],
  13. init:function(){
  14. var me = this;
  15. this.control({
  16. 'erpQueryButton' : {
  17. click: function(btn) {
  18. me.query();
  19. }
  20. },
  21. '#ms_sncode': {
  22. specialkey: function(f, e){//按ENTER执行确认
  23. if ([e.ENTER, e.RETURN, e.SPACE].indexOf(e.getKey()) > -1) {
  24. Ext.defer(function(){
  25. var val = e.target.value;
  26. if(val && val!=null && val!=''){
  27. me.onConfirm(val);
  28. }
  29. }, 50);
  30. }
  31. }
  32. },
  33. '#pa_code':{
  34. afterrender:function(){
  35. Ext.create('Ext.tip.ToolTip', {
  36. target: 'pa_code-triggerWrap',
  37. html: '生成箱号'
  38. });
  39. },
  40. specialkey: function(f, e) { //按ENTER执行确认,带出箱内数量
  41. if (e.getKey() == e.ENTER) {
  42. if (f.value != null && f.value != '') {
  43. me.getQty(f.value);
  44. }
  45. }
  46. },
  47. blur:function(f){
  48. if (f.value != null && f.value != '') {
  49. me.getQty(f.value);
  50. }
  51. }
  52. },
  53. 'textfield[id=pa_inqty]':{
  54. change:function(f,n,o){
  55. var qty = Ext.getCmp("pa_totalqty").value;
  56. if(n == qty){
  57. Ext.getCmp("pa_restqty").setValue(0);
  58. }else{
  59. Ext.getCmp("pa_restqty").setValue(qty-n);//设置剩余数的值
  60. }
  61. }
  62. },
  63. 'button[id=updateQty]':{
  64. click:function(btn){
  65. var pa_code = Ext.getCmp("pa_code").value;
  66. if(!pa_code || Ext.isElement(pa_code)){//
  67. showError("请先输入箱号!");
  68. return ;
  69. }
  70. me.updateQty(pa_code);
  71. }
  72. },
  73. 'erpPrintButton':{
  74. click:function(btn){//打印
  75. //判断是否选择标签模板
  76. var lps_id = Ext.getCmp('template').value, totalqty = Ext.getCmp("pa_totalqty").value,
  77. restqty = Ext.getCmp('pa_restqty').value,pa_outboxcode = Ext.getCmp('pa_code').value;
  78. if(pa_outboxcode == '' || pa_outboxcode == null){
  79. showError('箱号不允许为空!');
  80. return ;
  81. }
  82. // if(lps_id && !Ext.isEmpty(lps_id)){
  83. //判断箱是否装满,未装满提示“是否继续打印”
  84. if(restqty > 0){
  85. warnMsg("该箱未装满,确定要打印吗?", function(btn){
  86. if(btn == 'yes'){
  87. me.print(pa_outboxcode,lps_id);
  88. }
  89. });
  90. }else{
  91. me.print(pa_outboxcode,lps_id);
  92. }
  93. // }else{
  94. // showError("请先选择标签模板!");
  95. // }
  96. }
  97. }
  98. });
  99. },
  100. onConfirm : function(val){//确认采集序列号
  101. var me = this;
  102. var sc_code = Ext.getCmp("sc_code").value, mc_makecode = Ext.getCmp("mc_makecode").value,
  103. pa_code = Ext.getCmp("pa_code").value, pa_restqty = Ext.getCmp("pa_restqty").value,
  104. st_code = Ext.getCmp("st_code").value,ms_sncode = val,
  105. mc_code =Ext.getCmp('mc_code').value; result = Ext.getCmp('t_result');
  106. var grid = Ext.getCmp('querygrid');
  107. //判断剩余装箱数量
  108. if(Ext.isEmpty(sc_code)){
  109. showError('请先指定资源编号!');
  110. return ;
  111. }else if(Ext.isEmpty(mc_code)){
  112. showError('请先指定作业单号!');
  113. return ;
  114. }else if(Ext.isEmpty(pa_code)){
  115. showError('请先指定箱号!');
  116. return ;
  117. }else if(pa_restqty == 0 ||pa_restqty == '0'){
  118. showError('箱内总数已达到总容量!');
  119. return ;
  120. } if(Ext.isEmpty(ms_sncode)){
  121. result.append('请输入序列号!');
  122. return ;
  123. }
  124. grid.setLoading(true);
  125. var condition = {sc_code:sc_code,pa_code:pa_code,st_code:st_code,mc_makecode:mc_makecode,ms_sncode:ms_sncode,mc_code:mc_code};
  126. Ext.Ajax.request({//采集序列号
  127. url : basePath + "pm/mes/getPackageDetail.action",
  128. params: {condition: unescape(escape(Ext.JSON.encode(condition)))},
  129. method : 'post',
  130. callback : function(options,success,response){
  131. grid.setLoading(false);
  132. var res = new Ext.decode(response.responseText);
  133. if(res.exceptionInfo){
  134. result.append(res.exceptionInfo, 'error');
  135. Ext.getCmp("ms_sncode").setValue('');
  136. showError(res.exceptionInfo);return;
  137. }else{
  138. me.query();
  139. //更新已装数量,剩余可装数量
  140. var pa_inqty = Ext.getCmp("pa_inqty").value;
  141. Ext.getCmp("pa_inqty").setValue(pa_inqty+1);
  142. var qty = Ext.getCmp("pa_totalqty").value;
  143. Ext.getCmp("pa_restqty").setValue(qty-pa_inqty-1);
  144. Ext.getCmp("ms_sncode").setValue('');
  145. result.append('采集序列号:'+ms_sncode+'成功!');
  146. }
  147. }
  148. });
  149. },
  150. query : function(){
  151. var me = this, querygrid = Ext.getCmp('querygrid');
  152. //判断资源编号不为空,制造单号,箱号
  153. var sc_code = Ext.getCmp("sc_code").value, mc_makecode = Ext.getCmp("mc_makecode").value,
  154. pa_code = Ext.getCmp("pa_code").value, mc_code = Ext.getCmp("mc_code").value;
  155. if(Ext.isEmpty(sc_code)){
  156. showError('请先指定资源编号!');
  157. return ;
  158. }else if(Ext.isEmpty(mc_code)){
  159. showError('请先指定作业单号');
  160. return ;
  161. }else if(Ext.isEmpty(pa_code) ){
  162. showError('请先指定箱号');
  163. return ;
  164. }
  165. var condition = {sc_code:sc_code,mc_makecode:mc_makecode,pa_code:pa_code,mc_code:mc_code};
  166. var gridParam = {caller: caller, condition: unescape(escape(Ext.JSON.encode(condition)))};
  167. me.loadNewStore(querygrid, gridParam);
  168. },
  169. loadNewStore : function(grid,param){//筛选
  170. var me = this;
  171. grid.setLoading(true);//loading...
  172. Ext.Ajax.request({//拿到grid的columns
  173. url : basePath + "pm/mes/loadQueryGridStore.action",
  174. params: param,
  175. method : 'post',
  176. callback : function(options,success,response){
  177. grid.setLoading(false);
  178. var res = new Ext.decode(response.responseText);
  179. if(res.exceptionInfo){
  180. showError(res.exceptionInfo);return;
  181. }
  182. var data = res.data;
  183. if(data == null || data.length == 0){
  184. Ext.getCmp('pa_inqty').setValue(0);
  185. var qty = Ext.getCmp("pa_totalqty").value;
  186. Ext.getCmp("pa_restqty").setValue(qty);
  187. grid.store.removeAll();
  188. } else {
  189. if(grid.buffered) {
  190. var ln = data.length, records = [], i = 0;
  191. for (; i < ln; i++) {
  192. records.push(Ext.create(grid.store.model.getName(), data[i]));
  193. }
  194. grid.store.purgeRecords();
  195. grid.store.cacheRecords(records);
  196. grid.store.totalCount = ln;
  197. grid.store.guaranteedStart = -1;
  198. grid.store.guaranteedEnd = -1;
  199. var a = grid.store.pageSize - 1;
  200. a = a > ln - 1 ? ln - 1 : a;
  201. grid.store.guaranteeRange(0, a);
  202. } else {
  203. grid.store.loadData(data);
  204. }
  205. Ext.getCmp('pa_inqty').setValue(data.length);
  206. var qty = Ext.getCmp("pa_totalqty").value;
  207. Ext.getCmp("pa_restqty").setValue(qty-data.length);
  208. }
  209. //自定义event
  210. grid.addEvents({
  211. storeloaded: true
  212. });
  213. grid.fireEvent('storeloaded', grid, data);
  214. }
  215. });
  216. },
  217. getQty:function(data){
  218. Ext.Ajax.request({//拿到grid的columns
  219. url : basePath + "pm/bom/getDescription.action",
  220. params: {
  221. tablename: 'package',
  222. field: 'pa_totalqty',
  223. condition: "pa_status=0 and pa_outboxcode='"+data+"'"
  224. },
  225. method : 'post',
  226. callback : function(options,success,response){
  227. var res = new Ext.decode(response.responseText);
  228. if(res.exceptionInfo){
  229. showError(res.exceptionInfo);
  230. Ext.getCmp('pa_code').setValue('');
  231. Ext.getCmp('pa_totalqty').setValue(0);
  232. return;
  233. }
  234. if(res.description == null){
  235. showError('箱号:'+data+'错误,不存在或者状态无效!');
  236. Ext.getCmp('pa_code').setValue('');
  237. Ext.getCmp('pa_totalqty').setValue(0);
  238. return;
  239. }else if(res.description == '0' || res.description == 0){
  240. showError('箱号:'+data+'错误,库存数量为0!');
  241. Ext.getCmp('pa_code').setValue('');
  242. Ext.getCmp('pa_totalqty').setValue(0);
  243. return;
  244. }else{//包装箱号正确设置编号数量
  245. Ext.getCmp('pa_totalqty').setValue(res.description);
  246. }
  247. }
  248. });
  249. },
  250. updateQty : function(pa_code){
  251. var me = this;
  252. var win=Ext.create('Ext.window.Window', {
  253. width: 430,
  254. height: 250,
  255. closeAction: 'destroy',
  256. title: '<h1>修改箱内容量</h1>',
  257. layout: {
  258. type: 'vbox'
  259. },
  260. items: [{
  261. margin: '5 0 0 5',
  262. xtype: 'textfield',
  263. fieldLabel: '箱号',
  264. name: 'boxcode',
  265. value: pa_code,
  266. id:'boxcode',
  267. readOnly:true
  268. },
  269. {
  270. margin: '5 0 0 5',
  271. xtype: 'numberfield',
  272. fieldLabel: '箱内容量',
  273. name: 'qty',
  274. value: Ext.getCmp("pa_totalqty").value ||0,
  275. id:'qty',
  276. allowBlank:false,
  277. fieldStyle : "background:rgb(224, 224, 255);",
  278. labelStyle:"color:red;"
  279. }],
  280. buttonAlign: 'center',
  281. buttons: [{
  282. xtype: 'button',
  283. text: '保存',
  284. width: 60,
  285. iconCls: 'x-button-icon-save',
  286. handler: function(btn) {
  287. var w = btn.up('window');
  288. me.updateQ(w);
  289. }
  290. },
  291. {
  292. xtype: 'button',
  293. columnWidth: 0.1,
  294. text: '关闭',
  295. width: 60,
  296. iconCls: 'x-button-icon-close',
  297. margin: '0 0 0 10',
  298. handler: function(btn) {
  299. var win = btn.up('window');
  300. win.close();
  301. win.destroy();
  302. }
  303. }]
  304. });
  305. win.show();
  306. },
  307. updateQ:function(w){
  308. var boxcode = w.down('field[name=boxcode]').getValue();
  309. var qty = w.down('field[name=qty]').getValue();
  310. var oqty = Ext.getCmp("pa_totalqty").getValue();
  311. if(oqty == qty){
  312. showError('修改的箱内容量等于原箱内容量!');
  313. return;
  314. }
  315. if (!qty || qty <0 || qty == 0 ) {
  316. showError('请填写有效的箱内容量!');
  317. return;
  318. } else {
  319. Ext.Ajax.request({
  320. url: basePath + 'pm/mes/updatePackageQty.action',
  321. params: {
  322. pa_outboxcode: boxcode,
  323. pa_totalqty : qty ,
  324. caller : caller
  325. },
  326. method: 'post',
  327. callback: function(opt, s, res) {
  328. var r = new Ext.decode(res.responseText);
  329. if (r.success) {
  330. showMessage('提示', '更新成功!', 1000);
  331. Ext.getCmp("pa_code").setValue(boxcode);
  332. Ext.getCmp("pa_totalqty").setValue(qty);
  333. Ext.getCmp("pa_restqty").setValue(qty - Ext.getCmp("pa_inqty").getValue());
  334. w.close();
  335. w.destroy();
  336. } else if (r.exceptionInfo) {
  337. showError(r.exceptionInfo);
  338. }
  339. }
  340. });
  341. }
  342. },
  343. print:function(pa_outboxcode,lps_id){
  344. var me = this;
  345. //me.FormUtil.getActiveTab().setLoading(true);//loading...
  346. if (!Ext.fly('ext-attach-download')) {
  347. var frm = document.createElement('form');
  348. frm.id = 'ext-attach-download';
  349. frm.name = id;
  350. frm.className = 'x-hidden';
  351. document.body.appendChild(frm);
  352. }
  353. Ext.Ajax.request({
  354. url : basePath + 'pm/mes/printPackageSN.action',
  355. params: {
  356. pa_outboxcode: pa_outboxcode,
  357. lps_id : lps_id,
  358. caller : caller
  359. },
  360. method : 'POST',
  361. form: Ext.fly('ext-attach-download'),
  362. isUpload: true,
  363. callback : function(o, s, res){
  364. //me.FormUtil.getActiveTab().setLoading(false);
  365. /*var r = new Ext.decode(res.responseText);
  366. if(r.exceptionInfo){
  367. showError(r.exceptionInfo);
  368. }
  369. if(r.success){
  370. var fso, tf;
  371. fso = new ActiveXObject("Scripting.FileSystemObject");
  372. tf = fso.CreateTextFile("D:\\资料\\测试\\ftp.txt", true);
  373. tf.WriteLine("Testing 1, 2, 3.") ;
  374. }*/
  375. }
  376. });
  377. }
  378. });