BreakingBatch.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. /**
  2. *条码拆分
  3. */
  4. Ext.define('erp.view.core.button.BreakingBatch', {
  5. extend : 'Ext.Button',
  6. alias : 'widget.erpBreakingBatchButton',
  7. iconCls : 'x-button-icon-check',
  8. cls : 'x-btn-gray',
  9. id : 'BreakingBatch',
  10. text : $I18N.common.button.erpBreakingBatchButton,
  11. style : {
  12. marginLeft : '10px'
  13. },
  14. width:100,
  15. initComponent : function() {
  16. this.callParent(arguments);
  17. },
  18. handler: function(btn){
  19. var me = this;
  20. var bool = false;
  21. var or_barcode;
  22. var or_baremain;
  23. var grid = Ext.getCmp('batchDealGridPanel');
  24. var items = grid.selModel.getSelection();
  25. var id ;
  26. Ext.each(items, function(item, index){
  27. if(this.data['bar_id'] != null && this.data['bar_id'] != ''
  28. && this.data['bar_id'] != '0' && this.data['bar_id'] != 0){
  29. id = this.data['bar_id'];
  30. or_barcode = this.data['bar_code'];
  31. or_baremain = this.data['bar_remain'];
  32. bool = true;
  33. }
  34. });
  35. if(bool){
  36. if(items.length == 1){
  37. var win = new Ext.window.Window({
  38. id: 'win',
  39. height: '40%',
  40. width: '50%',
  41. maximizable: false,
  42. title:'<span>条码拆分</span>',
  43. buttonAlign: 'center',
  44. layout: 'column',
  45. bodyStyle:"background-color:#F5F5F5;",
  46. items: [{
  47. xtype:'displayfield',
  48. name:'barcode',
  49. fieldLabel:'条码',
  50. id : 'barcode',
  51. readOnly:true,
  52. columnWidth:1,
  53. labelWidth:60,
  54. allowBlank : false,
  55. style:'border:none;'
  56. },{
  57. name:'bar_remain',
  58. fieldLabel:'数量',
  59. id : 'bar_remain',
  60. readOnly:true,
  61. labelWidth:60,
  62. allowBlank : false,
  63. columnWidth:.3,
  64. xtype:'displayfield'
  65. },{
  66. fieldLabel:"需拆分数量",
  67. labelStyle:"color:red;",
  68. labelWidth:80,
  69. xtype:"numberfield",
  70. minValue: 0,
  71. allowBlank:false,
  72. columnWidth:.45,
  73. name : 'barNumber',
  74. id:'barNumber',
  75. autoStripChars:true,
  76. hideTrigger:true
  77. },
  78. {
  79. xtype:'displayfield',
  80. name:'barcode1',
  81. fieldLabel:'新条码1',
  82. id : 'barcode1',
  83. readOnly:true,
  84. columnWidth:.75,
  85. labelWidth:60,
  86. allowBlank : false
  87. },
  88. {
  89. xtype:'displayfield',
  90. name:'number1',
  91. fieldLabel:'数量',
  92. id : 'number1',
  93. readOnly:true,
  94. columnWidth:.25,
  95. labelWidth:40,
  96. allowBlank : false
  97. },
  98. {
  99. xtype:'displayfield',
  100. name:'barcode2',
  101. fieldLabel:'新条码2',
  102. id : 'barcode2',
  103. readOnly:true,
  104. columnWidth:.75,
  105. labelWidth:60,
  106. allowBlank : false
  107. },{
  108. xtype:'displayfield',
  109. name:'number2',
  110. fieldLabel:'数量',
  111. id : 'number2',
  112. readOnly:true,
  113. columnWidth:.25,
  114. labelWidth:40,
  115. allowBlank : false
  116. },
  117. {
  118. xtype:'displayfield',
  119. name:'barid',
  120. fieldLabel:'bar_id',
  121. id : 'barid',
  122. readOnly:true,
  123. columnWidth:0,
  124. hidden:true
  125. }],
  126. buttons : [{
  127. text : '确定',
  128. id :'confirm',
  129. handler : function(btn) {
  130. var number = Ext.getCmp('barNumber').value;
  131. var bar_remain = Ext.getCmp("bar_remain").value;
  132. if (!number) {
  133. Ext.Msg.alert('温馨提示',
  134. '请输入拆分数量');
  135. return;
  136. }else if (number <= 0) {
  137. Ext.Msg.alert('温馨提示',
  138. '拆分数量必须大于0');
  139. return;
  140. }else if(number >= bar_remain){
  141. Ext.Msg.alert('温馨提示',
  142. '需拆分数量必须小于条码原数量');
  143. return;
  144. }
  145. if (id) {
  146. me.breakingBatch(id);
  147. }
  148. }
  149. },{
  150. xtype: 'checkboxfield',
  151. name: 'autoPrint',
  152. id:'autoPrint',
  153. boxLabel: '自动打印条码',
  154. style:'margin-left:50px',
  155. checked:true
  156. },{
  157. text : '打印新条码',
  158. id : 'print1',
  159. iconCls: 'x-button-icon-print',
  160. disabled : true,
  161. handler : function(btn) {
  162. var me = this;
  163. caller = 'Barcode!BaPrint';
  164. me.idS = '';
  165. var lps_Barcaller = 'Barcode!Print';
  166. var bool = false;
  167. var grid = Ext.getCmp('batchDealGridPanel');
  168. var item = Ext.getCmp("barid").value;
  169. var idArray = [];
  170. if(item != null && item != '' && item != '0' && item != 0 ){
  171. idArray.push(item);
  172. bool = true;
  173. }
  174. if(bool){
  175. var idS = idArray.toString();
  176. //me.print(idS,lps_Barcaller);
  177. me.idS = idS;
  178. me.zplPrint(lps_Barcaller);
  179. }else{
  180. showError("没有需要打印的行,请先拆分出新条码");
  181. }
  182. },
  183. zplPrint:function(caller){//zpl打印语句
  184. // 获取选择打印文件,用户选择分辨率,和打印机
  185. var me = this;
  186. if(!me.window){
  187. setup_web_print(function(printers,selected_printer){
  188. me.window = Ext.create('Ext.window.Window', {
  189. autoShow: true,
  190. title: '选择打印模板',
  191. width: 400,
  192. height: 300,
  193. layout: 'anchor',
  194. id :'template-win0',
  195. closeAction:'hide',
  196. items: [{
  197. anchor:'100% 100%',
  198. xtype:'form',
  199. buttonAlign : 'center',
  200. items:[{
  201. xtype: 'combo',
  202. id: 'printers',
  203. fieldLabel: '打印机列表',
  204. store: Ext.create('Ext.data.Store', {
  205. autoLoad: true,
  206. fields: ['display', 'value'],
  207. data:printers
  208. }),
  209. queryMode: 'local',
  210. displayField: 'display',
  211. valueField: 'value',
  212. width:361,
  213. allowBlank:false,
  214. value:selected_printer.uid,
  215. selectOnFocus:true,//用户不能自己输入,只能选择列表中有的记录
  216. style:'margin-left:15px;margin-top:15px;'
  217. },{
  218. xtype: 'combo',
  219. id: 'dpi',
  220. fieldLabel: '打印机分辨率',
  221. style:'margin-left:15px;margin-top:15px;',
  222. store: Ext.create('Ext.data.Store', {
  223. fields: ['display', 'value'],
  224. data : [{"display": '203dpi', "value": '203'},
  225. {"display": '300dpi', "value": '300'},
  226. {"display": '600dpi', "value": '600'},
  227. {"display": '1200dpi', "value": '1200'}]
  228. }),
  229. displayField: 'display',
  230. valueField: 'value',
  231. queryMode: 'local',
  232. value:resolutionCookie||'203',
  233. width:361,
  234. allowBlank:false,
  235. selectOnFocus:true//用户不能自己输入,只能选择列表中有的记录
  236. }]
  237. }],
  238. buttonAlign: 'center',
  239. buttons: [{
  240. text: '确定',
  241. handler: function(b) {
  242. var printers = Ext.getCmp('printers');
  243. var dpi = Ext.getCmp('dpi');
  244. if(printers && printers.value!= null){
  245. me.zebraPrint(caller,printers.value,dpi.value);
  246. b.ownerCt.ownerCt.close();
  247. }else{
  248. alert("请选择打印机 ");
  249. }
  250. }
  251. }, {
  252. text: '取消',
  253. handler: function(b) {
  254. b.ownerCt.ownerCt.close();
  255. }
  256. }]
  257. });
  258. });
  259. }else if(me.window.isHidden()){
  260. me.window.show();
  261. }
  262. },
  263. zebraPrint:function(caller,printer,dpi){
  264. var me = this;
  265. var params = new Object();
  266. params['condition'] = 'bar_id in ('+me.idS +")";
  267. sendData(caller,printer,dpi,params);
  268. }
  269. },
  270. {
  271. text : '取消',
  272. id : 'cancle',
  273. handler : function(btn) {
  274. var win = btn.ownerCt.ownerCt;
  275. win.close();
  276. }
  277. }
  278. ],
  279. listeners : {
  280. beforerender:function(){
  281. Ext.getCmp('barcode').setValue(or_barcode);
  282. Ext.getCmp('bar_remain').setValue(or_baremain);
  283. if(Ext.getCmp("barcode1").value == null || Ext.getCmp("barcode1").value ==''){
  284. Ext.getCmp('barcode1').hide();
  285. Ext.getCmp('number1').hide();
  286. }
  287. if(Ext.getCmp("barcode2").value == null || Ext.getCmp("barcode2").value ==''){
  288. Ext.getCmp('barcode2').hide();
  289. Ext.getCmp('number2').hide();
  290. }
  291. }
  292. }
  293. });
  294. win.show();
  295. /*win.on("close",function(){
  296. var grid = Ext.getCmp("batchDealGridPanel");
  297. if(grid){
  298. caller = 'BarcodeStatus!query';
  299. grid.ownerCt.down('form').onQuery();
  300. }
  301. });*/
  302. }else{
  303. showError("只能勾选一条拆分的数据");
  304. }
  305. }else{
  306. showError("没有勾选需要拆分的行,请勾选");
  307. }
  308. },
  309. breakingBatch: function(id){
  310. var me=this;
  311. var or_remain;
  312. var or_barcode = Ext.getCmp("barcode").getValue(); //原条码
  313. var or_baremain = Ext.getCmp("bar_remain").getValue(); //原数量
  314. var bar_remain = Ext.getCmp("barNumber").getValue(); //输入拆分的数量
  315. var grid = Ext.getCmp("batchDealGridPanel");
  316. var barcode1 = Ext.getCmp('barcode1'); //新条码1
  317. var barcode2 = Ext.getCmp('barcode2'); //新条码2
  318. var number1 = Ext.getCmp('number1');
  319. var number2 = Ext.getCmp('number2');
  320. var bar_id = Ext.getCmp("barid"); //返回的bar_id
  321. var idArray = [];
  322. me.setLoading(true);
  323. Ext.Ajax.request({
  324. url : basePath +'scm/reserve/breakingBatch.action',
  325. params: {
  326. or_barcode:or_barcode,
  327. or_remain: or_baremain,
  328. bar_remain: bar_remain
  329. },
  330. method : 'post',
  331. timeout: 360000,
  332. callback : function(options,success,response){
  333. me.setLoading(false);
  334. var res = new Ext.decode(response.responseText);
  335. if(res.success){
  336. var data = res.data;
  337. Ext.MessageBox.alert('提示', '条码拆分成功!',function(){
  338. /*grid.ownerCt.down('form').onQuery();*/
  339. Ext.getCmp('barcode1').show();
  340. Ext.getCmp('number1').show();
  341. Ext.getCmp("bar_remain").setValue(or_baremain - bar_remain);
  342. barcode1.setValue(data[0].BAR_CODE);
  343. number1.setValue(data[0].BAR_REMAIN);
  344. idArray = [];
  345. idArray.push(data[0].BAR_ID);
  346. if(data.length > 1){
  347. barcode2.setValue(data[1].BAR_CODE);
  348. number2.setValue(data[1 ].BAR_REMAIN);
  349. idArray.push(data[1].BAR_ID);
  350. Ext.getCmp('barcode2').show();
  351. Ext.getCmp('number2').show();
  352. }
  353. bar_id.setValue(idArray);
  354. Ext.getCmp('print1').enable();
  355. Ext.getCmp('confirm').setDisabled(true);
  356. var status = Ext.getCmp('autoPrint').value;
  357. if(status){
  358. var lps_Barcaller = 'Barcode!Print';
  359. var item = Ext.getCmp("barid").value;
  360. var idArray = [];
  361. if(item != null && item != '' && item != '0' && item != 0 ){
  362. idArray.push(item);
  363. }
  364. var idS = idArray.toString();
  365. //me.print(idS,lps_Barcaller);
  366. me.idS = idS;
  367. me.zplPrint(lps_Barcaller);
  368. }
  369. });
  370. }else if(res.exceptionInfo){
  371. showError(res.exceptionInfo);return;
  372. }
  373. }
  374. });
  375. },
  376. setLoading : function(b) {
  377. var mask = this.mask;
  378. if (!mask) {
  379. this.mask = mask = new Ext.LoadMask(Ext.getBody(), {
  380. msg : "处理中,请稍后...",
  381. msgCls : 'z-index:10000;'
  382. });
  383. }
  384. if (b)
  385. mask.show();
  386. else
  387. mask.hide();
  388. },
  389. zplPrint:function(caller){//zpl打印语句
  390. // 获取选择打印文件,用户选择分辨率,和打印机
  391. var me = this;
  392. if(!me.window){
  393. setup_web_print(function(printers,selected_printer){
  394. me.window = Ext.create('Ext.window.Window', {
  395. autoShow: true,
  396. title: '选择打印模板',
  397. width: 400,
  398. height: 300,
  399. layout: 'anchor',
  400. id :'template-win',
  401. closeAction:'hide',
  402. items: [{
  403. anchor:'100% 100%',
  404. xtype:'form',
  405. buttonAlign : 'center',
  406. items:[{
  407. xtype: 'combo',
  408. id: 'printers',
  409. fieldLabel: '打印机列表',
  410. store: Ext.create('Ext.data.Store', {
  411. autoLoad: true,
  412. fields: ['display', 'value'],
  413. data:printers
  414. }),
  415. queryMode: 'local',
  416. displayField: 'display',
  417. valueField: 'value',
  418. width:361,
  419. allowBlank:false,
  420. value:selected_printer.uid,
  421. selectOnFocus:true,//用户不能自己输入,只能选择列表中有的记录
  422. style:'margin-left:15px;margin-top:15px;'
  423. },{
  424. xtype: 'combo',
  425. id: 'dpi',
  426. fieldLabel: '打印机分辨率',
  427. style:'margin-left:15px;margin-top:15px;',
  428. store: Ext.create('Ext.data.Store', {
  429. fields: ['display', 'value'],
  430. data : [{"display": '203dpi', "value": '203'},
  431. {"display": '300dpi', "value": '300'},
  432. {"display": '600dpi', "value": '600'},
  433. {"display": '1200dpi', "value": '1200'}]
  434. }),
  435. displayField: 'display',
  436. valueField: 'value',
  437. queryMode: 'local',
  438. value:resolutionCookie||'203',
  439. width:361,
  440. allowBlank:false,
  441. selectOnFocus:true//用户不能自己输入,只能选择列表中有的记录
  442. }]
  443. }],
  444. buttonAlign: 'center',
  445. buttons: [{
  446. text: '确定',
  447. handler: function(b) {
  448. var printers = Ext.getCmp('printers');
  449. var dpi = Ext.getCmp('dpi');
  450. if(printers && printers.value!= null){
  451. me.zebraPrint(caller,printers.value,dpi.value);
  452. b.ownerCt.ownerCt.close();
  453. }else{
  454. alert("请选择打印机 ");
  455. }
  456. }
  457. }, {
  458. text: '取消',
  459. handler: function(b) {
  460. b.ownerCt.ownerCt.close();
  461. }
  462. }]
  463. });
  464. });
  465. }else if(me.window.isHidden()){
  466. me.window.show();
  467. }
  468. },
  469. zebraPrint:function(caller,printer,dpi){
  470. var me = this;
  471. var params = new Object();
  472. params['condition'] = 'bar_id in ('+me.idS +")";
  473. sendData(caller,printer,dpi,params);
  474. }
  475. });