Periods.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.ma.logic.Periods', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.BaseUtil'],
  5. views: ['ma.logic.Periods','core.form.MonthDateField','core.button.Confirm'],
  6. init:function(){
  7. var me = this;
  8. this.BaseUtil = Ext.create('erp.util.BaseUtil');
  9. this.control({
  10. 'button[id=check]': {
  11. click: function(btn) {
  12. var grid = btn.ownerCt.ownerCt;
  13. grid.store.each(function(r){
  14. r.set('check', '');
  15. });
  16. btn.setDisabled(true);
  17. me.check(grid, 0, btn);
  18. }
  19. },
  20. 'button[id=close]': {
  21. click: function() {
  22. me.BaseUtil.getActiveTab().close();
  23. }
  24. },
  25. 'grid[id=check-Periods]': {
  26. itemclick: function(selModel, record) {
  27. var val = record.get('check');
  28. if(val == 'error') {
  29. me.showDetail(record);
  30. }
  31. }
  32. },
  33. 'erpConfirmButton':{
  34. click: function(btn){
  35. this.confirm();
  36. }
  37. }
  38. });
  39. },
  40. confirm: function(){
  41. Ext.Ajax.request({
  42. url : basePath + "ma/logic/addperiods.action",
  43. params:{
  44. date: Ext.getCmp('date').value
  45. },
  46. method:'post',
  47. callback:function(options,success,response){
  48. var localJson = new Ext.decode(response.responseText);
  49. if(localJson.success){
  50. Ext.Msg.alert("提示","操作成功!");
  51. } else {
  52. if(localJson.exceptionInfo){
  53. var str = localJson.exceptionInfo;
  54. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  55. str = str.replace('AFTERSUCCESS', '');
  56. showMessage('提示', str);
  57. window.location.reload();
  58. } else {
  59. showError(str);return;
  60. }
  61. }
  62. }
  63. }
  64. });
  65. },
  66. check: function(grid, idx, btn) {
  67. var me =this,f = grid.store.getAt(idx);
  68. if(!f) {
  69. btn.setDisabled(false);
  70. return;
  71. }
  72. f.set('check', 'loading');
  73. var win = Ext.getCmp('win-' + f.get('type'));
  74. if(win) {
  75. win.destroy();
  76. }
  77. Ext.Ajax.request({
  78. url: basePath + f.get('action'),
  79. params: {
  80. type: f.get('type'),
  81. month: me.currentMonth,
  82. start: me.datestart,
  83. end: me.dateend
  84. },
  85. callback: function(opt, s, r) {
  86. me.check(grid, ++idx, btn);
  87. var rs = Ext.decode(r.responseText);
  88. if(rs.ok) {
  89. f.set('check', 'checked');
  90. } else {
  91. f.set('check', 'error');
  92. }
  93. if(idx == grid.store.data.length) {
  94. var ch = 0;
  95. grid.store.each(function(){
  96. if(this.get('check') == 'checked') {
  97. ch ++;
  98. }
  99. });
  100. if(idx == ch) {
  101. Ext.getCmp('confirm').setDisabled(false);
  102. }
  103. }
  104. }
  105. });
  106. },
  107. showDetail: function(record) {
  108. var wid = 'win-' + record.get('type'),
  109. win = Ext.getCmp(wid);
  110. if(!win) {
  111. win = Ext.create('Ext.Window', {
  112. title: record.get('value'),
  113. id: wid,
  114. width: 800,
  115. height: 500,
  116. layout: 'anchor',
  117. items: [{
  118. xtype: 'gridpanel',
  119. anchor: '100% 100%',
  120. columnLines: true,
  121. cls: 'custom',
  122. columns: [{
  123. text: '单据',
  124. flex: 1,
  125. dataIndex: 'be_class'
  126. },{
  127. text: '编号',
  128. flex: 1.6,
  129. dataIndex: 'be_code'
  130. },{
  131. text: '检测时间',
  132. flex: 1,
  133. dataIndex: 'be_date',
  134. renderer: function(val) {return Ext.Date.format(new Date(val), 'Y-m-d');}
  135. },{
  136. text: '检测人',
  137. flex: .8,
  138. dataIndex: 'be_checker'
  139. },{
  140. text: '备注',
  141. flex: 3,
  142. dataIndex: 'be_remark'
  143. }],
  144. store: new Ext.data.Store({
  145. fields: ['be_class', 'be_code', 'be_date', 'be_checker', 'be_remark']
  146. })
  147. }],
  148. buttonAlign: 'center',
  149. buttons: [{
  150. text: $I18N.common.button.erpCloseButton,
  151. cls: 'x-btn-blue',
  152. handler: function(btn) {
  153. btn.ownerCt.ownerCt.close();
  154. }
  155. }]
  156. });
  157. this.getBillError(record.get('type'), win.down('gridpanel'));
  158. }
  159. win.show();
  160. },
  161. getBillError: function(type, grid) {
  162. Ext.Ajax.request({
  163. url: basePath + 'fa/getBillError.action',
  164. params: {
  165. type: type
  166. },
  167. callback: function(opt, s, r) {
  168. var rs = Ext.decode(r.responseText);
  169. if(rs.data) {
  170. grid.store.loadData(rs.data);
  171. } else if(rs.exceptionInfo) {
  172. showError(rs.exceptionInfo);
  173. }
  174. }
  175. });
  176. }
  177. });