CheckBom.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.pm.bom.CheckBom', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.BaseUtil'],
  5. views: ['pm.bom.CheckBom','core.form.Panel','core.button.CheckBom','core.button.Close','core.button.ExportBomCheckMsg',
  6. 'core.trigger.TextAreaTrigger','core.trigger.DbfindTrigger'
  7. ],
  8. init:function(){
  9. var me = this;
  10. this.BaseUtil = Ext.create('erp.util.BaseUtil');
  11. this.control({
  12. 'button[id=checkbombtn]': {
  13. click: function(btn) {
  14. var grid = Ext.getCmp('bom-check');
  15. grid.store.each(function(r){
  16. r.set('check', 'loading');
  17. var win = Ext.getCmp('win-' + r.get('TYPE'));
  18. if(win) {
  19. win.destroy();
  20. }
  21. });
  22. btn.setDisabled(true);
  23. me.check(grid, 0, btn);
  24. }
  25. },
  26. 'button[id=close]': {
  27. click: function() {
  28. me.BaseUtil.getActiveTab().close();
  29. }
  30. },
  31. 'grid[id=bom-check]': {
  32. itemclick: function(selModel, record) {
  33. var val = record.get('check');
  34. if(val == 'error') {
  35. me.showDetail(record);
  36. }
  37. }
  38. }
  39. });
  40. },
  41. check: function(grid, idx, btn) {
  42. var me =this;
  43. var form =Ext.getCmp('formPanel');
  44. var jsonGridData = new Array();
  45. var s = grid.getStore().data.items;
  46. for(var i=0;i<s.length;i++){//将grid里面各行的数据获取并拼成jsonGridData
  47. var data = s[i].data;
  48. jsonGridData.push(Ext.JSON.encode(data));
  49. }
  50. Ext.Ajax.request({
  51. url: basePath + 'pm/bomCheck/checkBom.action',
  52. params: {
  53. bomId: Ext.getCmp(form.keyField).value,
  54. bomMotherCode:Ext.getCmp('pr_code').value,
  55. gridStore:unescape(jsonGridData.toString())
  56. },
  57. callback: function(opt, s, r) {
  58. var rs = Ext.decode(r.responseText);
  59. var data=rs.ok;
  60. data = eval('('+data+')');
  61. if(data != null && data.length > 0){
  62. Ext.each(data, function(item, index){
  63. if(item.result=='true'){
  64. grid.getStore().getAt(index).set('check','checked');
  65. } else{
  66. grid.getStore().getAt(index).set('check','error');
  67. }
  68. });
  69. }
  70. }
  71. });
  72. btn.setDisabled(false);
  73. },
  74. showDetail: function(record) {
  75. var me = this, wid = 'win-' + record.get('TYPE'),
  76. win = Ext.getCmp(wid);
  77. if(!win) {
  78. win = Ext.create('Ext.Window', {
  79. title: record.get('VALUE'),
  80. id: wid,
  81. width: 800,
  82. height: 500,
  83. layout: 'anchor',
  84. items: [{
  85. xtype: 'gridpanel',
  86. anchor: '100% 100%',
  87. columnLines: true,
  88. cls: 'custom',
  89. columns: [{
  90. text: '编号',
  91. flex: 0.5,
  92. dataIndex: 'BM_ID'
  93. },{
  94. text: 'BOMID',
  95. flex: 1,
  96. dataIndex: 'BM_BOMID'
  97. },{
  98. text: '检测条目',
  99. flex: 1,
  100. dataIndex: 'BM_ITEM'
  101. },{
  102. text: '异常描述',
  103. flex: 1.5,
  104. dataIndex: 'BM_DESCRIPTION'
  105. },{
  106. text: '检测时间',
  107. flex: 1,
  108. dataIndex: 'BM_DATE',
  109. renderer: function(val) {return Ext.Date.format(new Date(val), 'Y-m-d');}
  110. }],
  111. store: new Ext.data.Store({
  112. fields: ['BM_ID', 'BM_BOMID', 'BM_ITEM', 'BM_DESCRIPTION', 'BM_DATE']
  113. })
  114. }],
  115. buttonAlign: 'center',
  116. buttons: [{
  117. text: $I18N.common.button.erpExportButton,
  118. iconCls: 'x-button-icon-excel',
  119. cls: 'x-btn-blue',
  120. handler: function(btn) {
  121. me.BaseUtil.exportGrid(btn.up('window').down('gridpanel'));
  122. }
  123. },{
  124. text: $I18N.common.button.erpCloseButton,
  125. cls: 'x-btn-blue',
  126. handler: function(btn) {
  127. btn.ownerCt.ownerCt.close();
  128. }
  129. }]
  130. });
  131. this.getBomError(record.get('VALUE'), win.down('gridpanel'));
  132. }
  133. win.show();
  134. },
  135. getBomError: function(type, grid) {
  136. var form =Ext.getCmp('formPanel');
  137. Ext.Ajax.request({
  138. url: basePath + 'pm/bomCheck/getBomMessage.action',
  139. params: {
  140. bomId: Ext.getCmp(form.keyField).value,
  141. type: type
  142. },
  143. callback: function(opt, s, r) {
  144. var rs = Ext.decode(r.responseText);
  145. if(rs.data) {
  146. grid.store.loadData(rs.data);
  147. } else if(rs.exceptionInfo) {
  148. showError(rs.exceptionInfo);
  149. }
  150. }
  151. });
  152. }
  153. });