Periods.js 5.1 KB

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