VerifyApplyDetail2.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.scm.qc.VerifyApplyDetail2', {
  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. 'core.form.Panel','scm.qc.VerifyApplyDetail2','core.grid.Panel2','scm.qc.ProjectDetGrid','core.toolbar.Toolbar','core.form.MultiField',
  9. 'core.button.Print','core.button.ResAudit','core.button.Audit','core.button.Close','core.form.FileField',
  10. 'core.button.Delete','core.button.Update','core.button.DeleteDetail','core.button.TurnMrb',
  11. 'core.button.Load','core.button.DeleteAllDetails','core.button.Submit','core.button.ResSubmit',
  12. 'core.button.Check','core.button.ResCheck',
  13. 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField','core.grid.YnColumn'
  14. ],
  15. init:function(){
  16. var me = this;
  17. this.control({
  18. 'erpGridPanel2': {
  19. itemclick : this.onGridItemClick,
  20. afterrender: function(g) {
  21. g.plugins[0].on('beforeedit', function(args){
  22. if(g.readOnly) {
  23. return false;
  24. }
  25. var status = args.record.data.ved_statuscode, isok=args.record.data.ved_isok,
  26. isng = args.record.data.ved_isng;
  27. if(status == 'AUDITED' || status == 'TURNIN') {
  28. return false;
  29. }
  30. if (args.field == "ved_okqty") {
  31. return me.isAllowUpdateOkQty(args.record);
  32. }
  33. if (args.field == "ved_ngqty") {
  34. return me.isAllowUpdateNgQty(args.record);
  35. }
  36. if(args.field == "ved_okqty" && isok == 1) {
  37. return false;
  38. }
  39. if(args.field == "ved_ngqty" && isng == 1) {
  40. return false;
  41. }
  42. });
  43. },
  44. reconfigure: function(grid) {
  45. if (Ext.getCmp('vad_qty')) {
  46. var qty = Ext.getCmp('vad_qty').value,
  47. record = grid.store.getAt(0);
  48. if(record.get('ved_okqty') == 0 && record.get('ved_ngqty') == 0
  49. && record.get('ved_id') == 0) {
  50. record.set('ved_okqty', qty);
  51. }
  52. }
  53. }
  54. },
  55. '#erpUpdateQtyButton': {
  56. afterrender: function(btn){
  57. var status = Ext.getCmp('ve_statuscode');
  58. if(status && status.value == 'UNAUDIT'){
  59. btn.hide();
  60. }
  61. },
  62. click: function(btn){
  63. var record=btn.ownerCt.ownerCt.getSelectionModel().getLastSelected();
  64. me.updateQty(record);
  65. }
  66. },
  67. 'projectdet': {
  68. itemclick: this.onGridItemClick1
  69. },
  70. 'erpDeleteButton' : {
  71. click: function(btn){
  72. me.FormUtil.onDelete(Ext.getCmp('ve_id').value);
  73. }
  74. },
  75. 'erpUpdateButton': {
  76. click: function(btn){
  77. var grid = Ext.getCmp('grid');
  78. var qty = Ext.getCmp('vad_qty').value,
  79. record = grid.store.getAt(0);
  80. if(record.get('ved_okqty') == 0 && record.get('ved_ngqty') == 0) {
  81. record.set('ved_okqty', qty);
  82. }
  83. me.beforeUpdate();
  84. }
  85. },
  86. 'erpCloseButton': {
  87. click: function(btn){
  88. me.FormUtil.beforeClose(me);
  89. }
  90. },
  91. 'erpAuditButton': {
  92. click: function(btn){
  93. var grid = Ext.getCmp('grid');
  94. var qty = Ext.getCmp('vad_qty').value,
  95. record = grid.store.getAt(0);
  96. if(record.get('ved_okqty') == qty && record.get('ved_id') == 0) {
  97. warnMsg('还未保存!是否先保存单据?', function(b){
  98. if(b == 'ok' || b == 'yes') {
  99. me.beforeUpdate();
  100. }
  101. });
  102. } else {
  103. me.FormUtil.onAudit(Ext.getCmp('ve_id').value);
  104. }
  105. }
  106. },
  107. 'erpResAuditButton': {
  108. afterrender: function(btn){
  109. var status = Ext.getCmp('ve_statuscode');
  110. if(status && status.value != 'AUDITED'){
  111. btn.hide();
  112. }
  113. },
  114. click: function(btn){
  115. me.FormUtil.onResAudit(Ext.getCmp('ve_id').value);
  116. }
  117. },
  118. 'erpPrintButton': {
  119. click: function(btn){
  120. var condition = '{QUA_VerifyApplyDetail.ve_id}=' + Ext.getCmp('ve_id').value + '';
  121. var id = Ext.getCmp('ve_id').value;
  122. reportName="verifyMake";
  123. me.FormUtil.onwindowsPrint(id, reportName, condition);
  124. }
  125. },
  126. 'erpTurnMrbButton':{
  127. click: function(btn){
  128. warnMsg("确定要转Mrb单吗?", function(btn){
  129. if(btn == 'yes'){
  130. var ve_id = Ext.getCmp('ve_id').value;
  131. Ext.Ajax.request({//拿到grid的columns
  132. url : basePath + "scm/qc/turnMrb.action",
  133. params: {
  134. id:ve_id,
  135. code:Ext.getCmp('ve_code').value
  136. },
  137. method : 'post',
  138. async: false,
  139. callback : function(options,success,response){
  140. var localJson = new Ext.decode(response.responseText);
  141. if(localJson.exceptionInfo){
  142. showError(localJson.exceptionInfo);
  143. }
  144. if(localJson.success){
  145. alert("转Mrb单成功!");
  146. }
  147. }
  148. });
  149. }
  150. });
  151. }
  152. },
  153. 'erpLoadButton':{
  154. afterrender: function(btn){
  155. var status = Ext.getCmp('ve_statuscode');
  156. if(status && status.value != 'UNAUDIT'){
  157. btn.hide();
  158. }
  159. },
  160. click: function(btn){
  161. var veid = Ext.getCmp('ve_id').value;
  162. var prid = Ext.getCmp('ve_prid').value;
  163. if(prid == 0 || prid == null){
  164. Ext.Msg.alert('请先填写检验方案ID!');
  165. }
  166. warnMsg("确认载入检验项目?", function(btn){
  167. if(btn == 'yes'){
  168. var params = new Object();
  169. var form = Ext.getCmp('form');
  170. var grid = Ext.getCmp('projectdetGrid');
  171. var items = grid.store.data.items;
  172. var array = new Array();
  173. var r = form.getValues();
  174. Ext.each(items,function(item,index){
  175. if(item.data['vd_item']!=null&&item.data['vd_item']!=""){
  176. array.push(item);
  177. }
  178. });
  179. var prid = Ext.getCmp('ve_prid').value;
  180. if(!prid||(prid&&(prid == 0||prid==''||prid==null))){
  181. Ext.Msg.alert('请先填写检验方案ID!');
  182. }else{
  183. if(array.length>0){
  184. Ext.Msg.alert('需要先清除明细行中的数据!');
  185. } else {
  186. params.formStore = unescape(Ext.JSON.encode(r).replace(/\\/g,"%"));
  187. //抓取
  188. Ext.Ajax.request({
  189. url : basePath + "scm/qc/catchProject.action",
  190. params : {
  191. id: veid,
  192. prid: prid
  193. },
  194. method : 'post',
  195. callback : function(options,success,response){
  196. me.FormUtil.getActiveTab().setLoading(false);
  197. var localJson = new Ext.decode(response.responseText);
  198. if(localJson.success){
  199. catchSuccess(function(){
  200. //add成功后刷新页面进入可编辑的页面
  201. var value = r[form.keyField];
  202. var condition = 'vd_veid='+value;
  203. grid.getMyData(condition);
  204. });
  205. } else if(localJson.exceptionInfo){
  206. } else{
  207. catchFailure();//@i18n/i18n.js
  208. }
  209. window.location.reload();
  210. }
  211. });
  212. }
  213. }
  214. }
  215. });
  216. }
  217. },
  218. 'erpSubmitButton': {
  219. afterrender: function(btn){
  220. var status = Ext.getCmp('ve_statuscode');
  221. if(status && status.value != 'AUDITED'){
  222. btn.hide();
  223. }
  224. status = Ext.getCmp('ve_checkstatuscode');
  225. if(status && status.value != 'UNAPPROVED'){
  226. btn.hide();
  227. }
  228. },
  229. click: function(btn){
  230. me.FormUtil.onSubmit(Ext.getCmp('ve_id').value);
  231. }
  232. },
  233. 'erpResSubmitButton': {
  234. afterrender: function(btn){
  235. var status = Ext.getCmp('ve_checkstatuscode');
  236. if(status && status.value != 'COMMITED'){
  237. btn.hide();
  238. }
  239. },
  240. click: function(btn){
  241. me.FormUtil.onResSubmit(Ext.getCmp('ve_id').value);
  242. }
  243. },
  244. 'erpCheckButton': {
  245. afterrender: function(btn){
  246. var status = Ext.getCmp('ve_checkstatuscode');
  247. if(status && status.value != 'COMMITED'){
  248. btn.hide();
  249. }
  250. },
  251. click: function(btn){
  252. me.FormUtil.onCheck(Ext.getCmp('ve_id').value);
  253. }
  254. },
  255. 'erpResCheckButton': {
  256. afterrender: function(btn){
  257. var status = Ext.getCmp('ve_checkstatuscode');
  258. if(status && status.value != 'APPROVE' ){
  259. btn.hide();
  260. }
  261. },
  262. click: function(btn){
  263. me.FormUtil.onResCheck(Ext.getCmp('ve_id').value);
  264. }
  265. },
  266. 'erpDeleteAllDetailsButton':{
  267. afterrender: function(btn){
  268. var status = Ext.getCmp('ve_statuscode');
  269. if(status && status.value != 'UNAUDIT'){
  270. btn.hide();
  271. }
  272. },
  273. click: function(btn){
  274. var grid = Ext.getCmp('projectdetGrid');
  275. warnMsg('确定清除所有明细行么?',function(t){
  276. if(t=='yes'){
  277. var veid = Ext.getCmp('ve_id').value;
  278. var form = Ext.getCmp('form');
  279. var r = form.getValues();
  280. var params = new Object();
  281. params.formStore = unescape(Ext.JSON.encode(r).replace(/\\/g,"%"));
  282. Ext.Ajax.request({
  283. url : basePath + "scm/qc/cleanProject.action",
  284. params : {
  285. id: veid
  286. },
  287. method : 'post',
  288. callback : function(options,success,response){
  289. me.FormUtil.getActiveTab().setLoading(false);
  290. var localJson = new Ext.decode(response.responseText);
  291. if(localJson.success){
  292. catchSuccess(function(){
  293. //add成功后刷新页面进入可编辑的页面
  294. var value = r[form.keyField];
  295. var condition = 'vd_veid='+value;
  296. grid.getMyData(condition);
  297. });
  298. } else if(localJson.exceptionInfo){
  299. } else{
  300. catchFailure();//@i18n/i18n.js
  301. }
  302. }
  303. });
  304. }else{
  305. return;
  306. }
  307. });
  308. }
  309. }
  310. });
  311. },
  312. onGridItemClick: function(selModel, record){//grid行选择
  313. this.GridUtil.onGridItemClick(selModel, record);
  314. var grid = selModel.ownerCt,
  315. btn = grid.down('erpDeleteDetailButton');
  316. if(btn && record.get('ved_statuscode') == 'TURNIN'){
  317. btn.setDisabled(true);
  318. }
  319. btn = Ext.getCmp('erpUpdateQtyButton');
  320. if(btn && record.data.ved_statuscode != 'TURNIN'){
  321. btn && btn.setDisabled(false);
  322. }
  323. },
  324. onGridItemClick1: function(selModel, record){//grid行选择
  325. this.gridLastSelected = record;
  326. var grid = Ext.getCmp('projectdetGrid');
  327. grid.lastSelectedRecord = record;
  328. if(record.data[grid.necessaryField] == null || record.data[grid.necessaryField] == ''){
  329. this.gridLastSelected.findable = true;//空数据可以在输入完code,并移开光标后,自动调出该条数据
  330. } else {
  331. this.gridLastSelected.findable = false;
  332. }
  333. this.GridUtil.onGridItemClick(selModel, record);
  334. },
  335. getForm: function(btn){
  336. return btn.ownerCt.ownerCt;
  337. },
  338. beforeUpdate: function(){
  339. var mm = this;
  340. if(! mm.FormUtil.checkForm()){
  341. return;
  342. }
  343. var s1 = mm.FormUtil.checkFormDirty(form);
  344. var grid2 = Ext.getCmp('projectdetGrid');
  345. var grid = Ext.getCmp('grid'), items = grid.store.data.items, qty = Ext.getCmp('vad_qty').value,
  346. testman = Ext.getCmp('ve_testman').value;
  347. var bool = true;
  348. //合格数量不能大于送检数量
  349. Ext.each(items, function(item){
  350. if(item.dirty){
  351. item.set('ved_samplingngqtylv', item.data['ved_samplingngqty']*100/item.data['ved_samplingqty']);
  352. }
  353. });
  354. Ext.each(items, function(item){
  355. if(item.dirty){
  356. if(item.data['ved_statuscode'] == "AUDITED"){
  357. bool = false;
  358. showError('明细表第' + item.data['ved_detno'] + '行已审核,不能修改!');return;
  359. }
  360. if(item.data['ved_okqty'] + item.data['ved_ngqty'] > qty){
  361. bool = false;
  362. showError('明细表第' + item.data['ved_detno'] + '行的合格数量与不合格数量之和不能大于送检数量!');return;
  363. } else {
  364. item.set('ved_checkqty', item.data['ved_okqty'] + item.data['ved_ngqty']);
  365. }
  366. item.set('ved_samplingqty', item.data['ved_samplingokqty'] + item.data['ved_samplingngqty']);
  367. }
  368. });
  369. var sum = grid.store.getSum(items, 'ved_checkqty');
  370. if(sum > qty) {
  371. showError('送检数量之和不能大于收料数量!');return;
  372. }
  373. var param1 = mm.GridUtil.getGridStore(grid);
  374. var param2 = mm.GridUtil.getGridStore(grid2);
  375. //更新
  376. if(bool){
  377. if(s1 == '' && (param1 == null || param1 == '') && (param2 == null || param2 == '')){
  378. warnMsg('未添加或修改数据,是否继续?', function(btn){
  379. if(btn == 'yes'){
  380. mm.onUpdate(param1, param2);
  381. } else {
  382. return;
  383. }
  384. });
  385. } else {
  386. mm.onUpdate(param1, param2);
  387. }
  388. }
  389. },
  390. onUpdate:function(param1,param2){
  391. var me = this;
  392. var form = Ext.getCmp('form');
  393. param1 = param1 == null ? [] : "[" + param1.toString().replace(/\\/g,"%") + "]";
  394. param2 = param2 == null ? [] : "[" + param2.toString().replace(/\\/g,"%") + "]";
  395. if(form.getForm().isValid()){
  396. //form里面数据
  397. Ext.each(form.items.items, function(item){
  398. if(item.xtype == 'numberfield'){
  399. //number类型赋默认值,不然sql无法执行
  400. if(item.value == null || item.value == ''){
  401. item.setValue(0);
  402. }
  403. }
  404. });
  405. var r = form.getValues();
  406. //去除ignore字段
  407. var keys = Ext.Object.getKeys(r), f;
  408. Ext.each(keys, function(k){
  409. f = form.down('#' + k);
  410. if(f && f.logic == 'ignore') {
  411. delete r[k];
  412. }
  413. });
  414. if(!me.FormUtil.contains(form.updateUrl, '?caller=', true)){
  415. form.updateUrl = form.updateUrl + "?caller=" + caller;
  416. }
  417. me.FormUtil.update(r, param1, param2);
  418. }else{
  419. me.FormUtil.checkForm();
  420. }
  421. },
  422. isAllowUpdateOkQty: function(record) {
  423. var bool = true;
  424. if (caller == 'VerifyApplyDetail!FQC') {
  425. if (record.get('ved_ngqty') != null && record.get('ved_ngqty') > 0) bool = false;
  426. }
  427. return bool;
  428. },
  429. isAllowUpdateNgQty: function(record) {
  430. var bool = true;
  431. if (caller == 'VerifyApplyDetail!FQC') {
  432. if (record.get('ved_okqty') != null && record.get('ved_okqty') > 0) bool = false;
  433. }
  434. return bool;
  435. },
  436. updateQty:function(record){
  437. var win = this.updateQtywindow;
  438. if (!win) {
  439. this.updateQtywindow = win = this.getUpdateQtyWindow(record);
  440. }
  441. win.show();
  442. },
  443. getComboData: function(table, field, callback) {
  444. var me = this;
  445. Ext.Ajax.request({
  446. url : basePath + 'common/getFieldsDatas.action',
  447. params: {
  448. caller: 'DataListCombo',
  449. fields: 'dlc_value,dlc_display',
  450. condition: 'dlc_caller=\'' + table + '\' AND dlc_fieldname=\'' + field + '\''
  451. },
  452. method : 'post',
  453. callback : function(options,success,response){
  454. var localJson = new Ext.decode(response.responseText);
  455. if(localJson.exceptionInfo){
  456. showError(localJson.exceptionInfo);return;
  457. }
  458. if(localJson.success){
  459. var data = Ext.decode(localJson.data), arr = new Array();
  460. for(var i in data) {
  461. arr.push({
  462. display: data[i].DLC_VALUE,
  463. value: data[i].DLC_DISPLAY
  464. });
  465. }
  466. callback.call(me, arr);
  467. }
  468. }
  469. });
  470. },
  471. getUpdateQtyWindow : function(record) {
  472. var me = this;
  473. var win = Ext.create('Ext.window.Window',{
  474. width: 330,
  475. height: 300,
  476. closeAction: 'hide',
  477. cls: 'custom-blue',
  478. title:'<h1>更改数量</h1>',
  479. layout: {
  480. type: 'vbox'
  481. },
  482. items:[{
  483. margin: '5 0 0 5',
  484. xtype:'numberfield',
  485. hideTrigger: true,
  486. fieldLabel:'合格数量',
  487. value: record.data.ved_okqty,
  488. name:'ved_okqty',
  489. id:'ved_okqty'
  490. },{
  491. margin: '5 0 0 5',
  492. xtype:'numberfield',
  493. hideTrigger: true,
  494. fieldLabel:'不合格数量',
  495. value: record.data.ved_ngqty,
  496. name:'ved_ngqty',
  497. id:'ved_ngqty',
  498. },{
  499. margin: '5 0 0 5',
  500. xtype:'combo',
  501. fieldLabel:'不良原因码',
  502. value: record.data.ved_nrcode,
  503. name:'ved_nrcode',
  504. id:'ved_nrcode',
  505. displayField: 'display',
  506. valueField: 'value',
  507. queryMode: 'local',
  508. store : new Ext.data.Store({
  509. fields: ['display', 'value'],
  510. data: []
  511. })
  512. },{
  513. margin: '5 0 0 5',
  514. xtype:'combo',
  515. fieldLabel:'不良处理',
  516. value: record.data.ved_ngdeal,
  517. name:'ved_ngdeal',
  518. id:'ved_ngdeal',
  519. displayField: 'display',
  520. valueField: 'value',
  521. queryMode: 'local',
  522. store : new Ext.data.Store({
  523. fields: ['display', 'value'],
  524. data: []
  525. })
  526. },{
  527. margin: '5 0 0 5',
  528. xtype:'textfield',
  529. fieldLabel:'不合格描述',
  530. value: record.data.ved_remark,
  531. name:'ved_remark',
  532. id:'ved_remark'
  533. }],
  534. buttonAlign:'center',
  535. buttons:[{
  536. xtype:'button',
  537. text:'保存',
  538. width:60,
  539. iconCls: 'x-button-icon-save',
  540. handler:function(btn){
  541. var w = btn.up('window');
  542. me.saveQty(w);
  543. w.hide();
  544. }
  545. },{
  546. xtype:'button',
  547. columnWidth:0.1,
  548. text:'关闭',
  549. width:60,
  550. iconCls: 'x-button-icon-close',
  551. margin:'0 0 0 10',
  552. handler:function(btn){
  553. btn.up('window').hide();
  554. }
  555. }]
  556. });
  557. me.getComboData(caller, 'ved_nrcode', function(data){
  558. win.down('#ved_nrcode').store.loadData(data);
  559. });
  560. me.getComboData(caller, 'ved_ngdeal', function(data){
  561. win.down('#ved_ngdeal').store.loadData(data);
  562. });
  563. return win;
  564. },
  565. saveQty: function(w) {
  566. var ved_okqty = w.down('field[name=ved_okqty]').getValue(),
  567. ved_ngqty = w.down('field[name=ved_ngqty]').getValue(),
  568. ved_nrcode = w.down('#ved_nrcode').getValue(),
  569. ved_ngdeal = w.down('#ved_ngdeal').getValue(),
  570. qty = Ext.getCmp('vad_qty').value,
  571. ved_remark = w.down('#ved_remark').getValue(),
  572. okqty = ved_okqty ? ved_okqty : 0,
  573. ngqty = ved_ngqty ? ved_ngqty : 0,
  574. grid = Ext.getCmp('grid'),
  575. record = grid.getSelectionModel().getLastSelected();
  576. if(okqty+ngqty-qty>0){
  577. showError('合格数量与不合格数量之和不能大于送检数量!');
  578. return;
  579. }
  580. var dd = {
  581. ved_id : record.data.ved_id,
  582. ved_veid : record.data.ved_veid,
  583. ved_okqty : okqty,
  584. ved_ngqty : ngqty,
  585. ved_nrcode : ved_nrcode,
  586. ved_ngdeal : ved_ngdeal,
  587. ved_remark : ved_remark,
  588. caller: caller
  589. };
  590. Ext.Ajax.request({
  591. url : basePath +'scm/qc/updateQty.action',
  592. params : {
  593. _noc: 1,
  594. data: unescape(Ext.JSON.encode(dd))
  595. },
  596. method : 'post',
  597. callback : function(opt, s, res){
  598. var r = new Ext.decode(res.responseText);
  599. if(r.success){
  600. grid.GridUtil.loadNewStore(grid, {
  601. caller: caller,
  602. condition: 'ved_veid=' + record.data.ved_veid
  603. });
  604. showMessage('提示', '更新成功!', 1000);
  605. } else if(r.exceptionInfo){
  606. showError(r.exceptionInfo);
  607. } else{
  608. saveFailure();
  609. }
  610. }
  611. });
  612. }
  613. });