MakeSerial.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.pm.mes.MakeSerial', {
  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.mes.MakeSerial','core.form.Panel','core.grid.Panel2','core.button.PrintRepair',
  9. 'core.button.Add','core.button.Save','core.button.Close','core.button.Update','core.button.Delete',
  10. 'core.form.YnField','core.grid.YnColumn', 'core.grid.TfColumn', 'core.button.VastOccur',
  11. 'core.trigger.TextAreaTrigger','core.trigger.DbfindTrigger','core.button.PrintAll','core.button.PrintCombine'
  12. ],
  13. init:function(){
  14. var me = this;
  15. this.control({
  16. 'erpGridPanel2': {
  17. itemclick: this.onGridItemClick
  18. },
  19. 'dbfindtrigger[name=mc_code]' : {
  20. afterrender: function(v) {
  21. var mcid = Ext.getCmp('mc_id').value;
  22. if (mcid != null & mcid != '') {
  23. var params = {
  24. caller: 'MakeSerial',
  25. condition : ('ms_mcid=' + mcid || '1=1')
  26. };
  27. me.GridUtil.loadNewStore(Ext.getCmp('grid'), params);
  28. }
  29. },
  30. aftertrigger : function(v) {
  31. var mcid = Ext.getCmp('mc_id').value;
  32. var dbtn = Ext.getCmp('deletebutton'), ubtn = Ext.getCmp('updatebutton'),
  33. vbtn = Ext.getCmp('erpVastOccurButton'),pabtn1 = Ext.getCmp('printCombine'),
  34. pabtn2 = Ext.getCmp('printAll'),prbtn = Ext.getCmp('printRepair');
  35. dbtn.setDisabled(false);
  36. ubtn.setDisabled(false);
  37. vbtn.setDisabled(false);
  38. pabtn1.setDisabled(false);
  39. pabtn2.setDisabled(false);
  40. prbtn.setDisabled(false);
  41. if (mcid != null & mcid != '') {
  42. var params = {
  43. caller: 'MakeSerial',
  44. condition : ('ms_mcid=' + mcid || '1=1')
  45. };
  46. me.GridUtil.loadNewStore(Ext.getCmp('grid'), params);
  47. }
  48. }
  49. },
  50. 'erpSaveButton': {
  51. click: function(btn){
  52. me.update();
  53. }
  54. },
  55. 'erpDeleteButton': {
  56. click: function(btn){
  57. warnMsg("确认清空?", function(btn){
  58. var mcid = Ext.getCmp('mc_id').value;
  59. if(btn == 'yes'){
  60. me.FormUtil.getActiveTab().setLoading(true);//loading...
  61. Ext.Ajax.request({
  62. url : basePath + 'pm/mes/deleteMakeSerial.action',
  63. params: {
  64. id: mcid
  65. },
  66. method : 'post',
  67. callback : function(opt, s, res) {
  68. me.FormUtil.getActiveTab().setLoading(false);//loading...
  69. var r = Ext.decode(res.responseText);
  70. if(r.exceptionInfo) {
  71. showError(r.exceptionInfo);
  72. }else if (r.success) {
  73. if (mcid != null & mcid != '') {
  74. var params = {
  75. caller: 'MakeSerial',
  76. condition : ('ms_mcid=' + mcid || '1=1')
  77. };
  78. me.GridUtil.loadNewStore(Ext.getCmp('grid'), params);
  79. }
  80. }
  81. }
  82. });
  83. }
  84. });
  85. },
  86. afterrender:function(btn){
  87. btn.setWidth(100);
  88. btn.setText('清空序列号');
  89. if(Ext.isEmpty(Ext.getCmp('mc_id').value)){
  90. btn.setDisabled(true);
  91. }
  92. }
  93. },
  94. 'erpCloseButton': {
  95. click: function(btn){
  96. this.FormUtil.beforeClose(this);
  97. }
  98. },
  99. 'erpUpdateButton': {
  100. click: function(btn){
  101. me.update();
  102. },
  103. afterrender:function(btn){
  104. if(Ext.isEmpty(Ext.getCmp('mc_id').value)){
  105. btn.setDisabled(true);
  106. }
  107. }
  108. },
  109. 'erpVastOccurButton': {
  110. click: function(btn){
  111. var me = this, win = Ext.getCmp('Complaint-win');
  112. var pscode = Ext.getCmp('mc_pscode').value,ps_combineqty ;
  113. /*if(Ext.isEmpty(pscode)){
  114. showError('请先维护作业单排位表编号!');return;
  115. }*/
  116. win = Ext.create('Ext.Window', {
  117. id: 'Complaint-win',
  118. title: '批量生成序列号',
  119. height: 200,
  120. width: 590,
  121. items: [{
  122. xtype: 'form',
  123. height: '100%',
  124. width: '100%',
  125. bodyStyle: 'background:#f1f2f5;',
  126. items: [{
  127. xtype: 'fieldcontainer',
  128. defaults: {
  129. width:190
  130. },
  131. layout: {
  132. type: 'table',
  133. columns: 3
  134. },
  135. items: [{
  136. margin: '10 0 0 0',
  137. xtype: 'textfield',
  138. fieldLabel: '序列前缀',
  139. id:'prefixcode',
  140. allowBlank: false,
  141. colspan: 1,
  142. labelWidth:70
  143. },{
  144. margin: '10 0 0 0',
  145. xtype: 'textfield',
  146. fieldLabel: '起始编码',
  147. id:'startno',
  148. allowBlank: false,
  149. colspan: 1,
  150. labelWidth:70
  151. },{
  152. margin: '10 0 0 0',
  153. xtype: 'textfield',
  154. fieldLabel: '序列后缀',
  155. id:'suffixcode',
  156. allowBlank: true,
  157. colspan: 1,
  158. labelWidth:70
  159. },{
  160. margin: '3 0 0 0',
  161. xtype: 'numberfield',
  162. fieldLabel: '产生序列号数量',
  163. id:'number',
  164. allowBlank: false,
  165. emptyText: 'n' ,
  166. style:{'padding-top': '15px'}
  167. },{
  168. margin: '3 0 0 0',
  169. xtype: 'textfield',
  170. fieldLabel: '拼板数',
  171. id:'combineqty',
  172. name:'combineqty',
  173. allowBlank: true ,
  174. labelWidth:70,
  175. value:Ext.getCmp('ps_combineqty').value || 0
  176. }]
  177. }],
  178. closeAction: 'hide',
  179. buttonAlign: 'center',
  180. layout: {
  181. type: 'vbox',
  182. align: 'center'
  183. },
  184. buttons: [{
  185. text: $I18N.common.button.erpConfirmButton,
  186. formBind:true,
  187. handler: function(btn) {
  188. var form = btn.ownerCt.ownerCt,
  189. a = form.down('#prefixcode'),
  190. b = form.down('#suffixcode'),
  191. c = form.down('#startno'),
  192. d = form.down('#number');
  193. e = form.down('#combineqty');
  194. if(form.getForm().isDirty()) {
  195. if(!Ext.isNumeric(c.value) || c.value <'0' ){
  196. showError("起始编码必须为数值或者大于等于0!");
  197. return ;
  198. }
  199. if(e.value != '' && e.value != null){
  200. if(e.value != 0 && (!Ext.isNumeric(e.value) || e.value <'2') ){
  201. showError("拼板数必须为数值或者大于1!");
  202. return ;
  203. }
  204. }else{
  205. form.down('#combineqty').setValue(0);
  206. }
  207. me.OccurCode(Ext.getCmp('mc_id').value, a.value, b.value, c.value, d.value,e.value);
  208. }
  209. }
  210. }, {
  211. text: $I18N.common.button.erpCloseButton,
  212. cls: 'x-btn-gray',
  213. handler: function(btn) {
  214. btn.up('window').close();
  215. }
  216. }]
  217. }]
  218. });
  219. win.show();
  220. },
  221. afterrender:function(btn){
  222. if(Ext.isEmpty(Ext.getCmp('mc_id').value)){
  223. btn.setDisabled(true);
  224. }
  225. }
  226. } ,
  227. 'erpPrintCombineButton':{
  228. click:function(btn){//打印拼板号
  229. var lp_barcaller = 'MakeSerialCombinePrintAll';
  230. var items = Ext.getCmp('grid').store.data.items;
  231. var bool = true;
  232. Ext.each(items, function(item, index){
  233. if(item.data.ms_id != '' && item.data.ms_id != 0 && item.data.ms_id != null){
  234. }else{
  235. bool = false;
  236. }
  237. });
  238. if(bool){
  239. var win = new Ext.window.Window({
  240. id : 'win',
  241. maximizable : true,
  242. buttonAlign : 'center',
  243. layout : 'anchor',
  244. title: '打印模板选择',
  245. modal : true,
  246. items: [{
  247. tag : 'iframe',
  248. frame : true,
  249. anchor : '100% 100%',
  250. layout : 'fit',
  251. html : '<iframe id="iframe_' + caller + '" src="' + basePath + 'jsps/scm/reserve/selPrintTemplate.jsp?whoami='+lp_barcaller+'" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>'
  252. }]
  253. });
  254. win.show();
  255. }else{
  256. showError('没有需要打印的明细!');
  257. }
  258. },
  259. afterrender:function(btn){
  260. if(Ext.isEmpty(Ext.getCmp('mc_id').value)){
  261. btn.setDisabled(true);
  262. }
  263. }
  264. },
  265. 'erpPrintAllButton':{
  266. afterrender:function(btn){
  267. btn.setText('打印序列号');
  268. if(Ext.isEmpty(Ext.getCmp('mc_id').value)){
  269. btn.setDisabled(true);
  270. }
  271. },
  272. click :function(btn){//打印序列号
  273. var lp_barcaller = 'MakeSerialCodePrintAll';
  274. var items = Ext.getCmp('grid').store.data.items;
  275. var bool = true;
  276. Ext.each(items, function(item, index){
  277. if(item.data.ms_id != '' && item.data.ms_id != 0 && item.data.ms_id != null){
  278. }else{
  279. bool = false;
  280. }
  281. });
  282. if(bool){
  283. var win = new Ext.window.Window({
  284. id : 'win',
  285. maximizable : true,
  286. buttonAlign : 'center',
  287. layout : 'anchor',
  288. title: '打印模板选择',
  289. modal : true,
  290. items: [{
  291. tag : 'iframe',
  292. frame : true,
  293. anchor : '100% 100%',
  294. layout : 'fit',
  295. html : '<iframe id="iframe_' + caller + '" src="' + basePath + 'jsps/scm/reserve/selPrintTemplate.jsp?whoami='+lp_barcaller +'" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>'
  296. }]
  297. });
  298. win.show();
  299. }else{
  300. showError('没有需要打印的明细!');
  301. }
  302. }
  303. },
  304. erpPrintRepairButton:{//补打条码
  305. afterrender:function(btn){
  306. if(Ext.isEmpty(Ext.getCmp('mc_id').value)){
  307. btn.setDisabled(true);
  308. }
  309. },
  310. click :function(btn){//打印序列号
  311. var me = this;
  312. me.createWin();
  313. }
  314. }
  315. });
  316. },
  317. getForm: function(btn){
  318. return btn.ownerCt.ownerCt;
  319. },
  320. onGridItemClick: function(selModel, record){//grid行选择
  321. this.GridUtil.onGridItemClick(selModel, record);
  322. },
  323. OccurCode: function(id, a, b, c, d,e) {
  324. var me = this;
  325. Ext.getCmp('Complaint-win').setLoading(true);
  326. Ext.Ajax.request({
  327. url: basePath + 'pm/mes/makeSerial/occurCode.action',
  328. params: {
  329. id: id,
  330. prefixcode: a,
  331. suffixcode: b,
  332. startno : c,
  333. number : d,
  334. combineqty: e
  335. },
  336. callback: function(opt, s, r) {
  337. Ext.getCmp('Complaint-win').setLoading(false);
  338. var rs = Ext.decode(r.responseText);
  339. if(rs.exceptionInfo) {
  340. showError(rs.exceptionInfo);
  341. } else {
  342. Ext.Msg.alert("提示","生成成功!");
  343. var params = {
  344. caller: 'MakeSerial',
  345. condition : ('ms_mcid=' + id || '1=1')
  346. };
  347. Ext.getCmp('Complaint-win').close();
  348. me.GridUtil.loadNewStore(Ext.getCmp('grid'), params);
  349. }
  350. }
  351. });
  352. },
  353. createWin: function(){
  354. var me = this;
  355. var win = new Ext.window.Window({
  356. modal : true,
  357. id : 'win',
  358. height : '35%',
  359. width : '30%',
  360. layout : 'anchor',
  361. bodyStyle: 'background: #f1f1f1;',
  362. bodyPadding:5,
  363. items : [{
  364. anchor: '100% 100%',
  365. xtype: 'form',
  366. bodyStyle: 'background: #f1f1f1;',
  367. items:[{
  368. xtype:'textfield',
  369. name:'serialCode',
  370. fieldLabel:'序列号',
  371. id:'serialCode',
  372. allowBlank:false,
  373. fieldStyle : "background:rgb(224, 224, 255);",
  374. labelStyle:"color:red;"
  375. },{
  376. xtype: 'checkbox',
  377. boxLabel : '产生新序列号',
  378. name : 'newSerial',
  379. checked : false,
  380. id : 'newSerial',
  381. fieldStyle:''
  382. }],
  383. buttonAlign : 'center',
  384. buttons: [{
  385. text: '确定' ,
  386. cls: 'x-btn-gray',
  387. iconCls: 'x-button-icon-save',
  388. id:'confirmBtn',
  389. formBind: true, //only enabled once the form is valid
  390. handler: function(btn) {
  391. me.checkOrNewBarcode();
  392. }
  393. },{
  394. text: '取消' ,
  395. cls: 'x-btn-gray',
  396. iconCls: 'x-button-icon-delete',
  397. handler: function(btn) {
  398. win.close();
  399. }
  400. }]
  401. }]
  402. });
  403. win.show();
  404. },
  405. checkOrNewBarcode:function(){//判断是新增条码还是补打原有的条码
  406. var me= this , newSerial = Ext.getCmp('newSerial').value,
  407. mc_id = Ext.getCmp('mc_id').value,serialCode = Ext.getCmp('serialCode').value;
  408. Ext.Ajax.request({
  409. url: basePath + 'pm/mes/makeSerial/checkOrNewSerialCode.action',
  410. params: {
  411. newSerial: newSerial,//是否新生成条码
  412. serialCode:serialCode, //需要打印的条码
  413. mc_id:mc_id //作业单Id,
  414. },
  415. callback: function(opt, s, r) {
  416. var rs = Ext.decode(r.responseText);
  417. if(rs.exceptionInfo) {
  418. showError(rs.exceptionInfo);return;
  419. } else {
  420. Ext.getCmp('win').close();
  421. var params = {
  422. caller: 'MakeSerial',
  423. condition : ('ms_mcid=' + mc_id || '1=1')
  424. };
  425. me.GridUtil.loadNewStore(Ext.getCmp('grid'), params);
  426. var ms_id = rs.message;
  427. var lp_barcaller = 'MakeSerialCodePrint';
  428. var win = new Ext.window.Window({
  429. id : 'win2',
  430. maximizable : true,
  431. buttonAlign : 'center',
  432. layout : 'anchor',
  433. title: '打印模板选择',
  434. modal : true,
  435. items: [{
  436. tag : 'iframe',
  437. frame : true,
  438. anchor : '100% 100%',
  439. layout : 'fit',
  440. html : '<iframe id="iframe_' + caller + '" src="' + basePath + 'jsps/scm/reserve/selPrintTemplate.jsp?whoami='+lp_barcaller +'&formCondition='+ms_id+'height="100%" width="100%" frameborder="0" scrolling="no"></iframe>'
  441. }]
  442. });
  443. win.show();
  444. }
  445. }
  446. });
  447. },
  448. update : function(){
  449. var me = this;
  450. var grid = Ext.getCmp('grid'), items = grid.store.data.items;
  451. var mc_id = Ext.getCmp('mc_id').value,
  452. mc_code = Ext.getCmp('mc_code').value,
  453. mc_prodcode = Ext.getCmp('mc_prodcode').value;
  454. Ext.Array.each(items, function(item) {
  455. if(!Ext.isEmpty(item.data['ms_sncode']) && Ext.isEmpty(item.data['ms_mcid'])){
  456. item.set('ms_mcid', mc_id);
  457. }
  458. });
  459. var form = Ext.getCmp('form');
  460. var jsondata = me.GridUtil.getGridStore();
  461. if(jsondata.length == 0){//未修改数据
  462. showError('还未修改或新增数据');
  463. return ;
  464. }
  465. me.FormUtil.getActiveTab().setLoading(true);
  466. Ext.Ajax.request({//拿到grid的columns
  467. url : basePath + 'pm/mes/updateMakeSerial.action',
  468. params: {
  469. formStore:unescape(escape(Ext.JSON.encode(form.getValues()))),
  470. caller:caller,
  471. param:unescape(jsondata)
  472. },
  473. async: false,
  474. method : 'post',
  475. callback:function(options,success,response){
  476. me.FormUtil.getActiveTab().setLoading(false);
  477. var res = Ext.decode(response.responseText);
  478. if(res.exceptionInfo){
  479. showError(res.exceptionInfo);
  480. return;
  481. }else{
  482. var params = {
  483. caller: 'MakeSerial',
  484. condition : ('ms_mcid=' + mc_id || '1=1')
  485. };
  486. me.GridUtil.loadNewStore(Ext.getCmp('grid'), params);
  487. }
  488. }
  489. });
  490. }
  491. });