BeforeAccount.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.co.cost.BeforeAccount', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.BaseUtil'],
  5. views: ['co.cost.BeforeAccount'],
  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=account-check]': {
  26. itemclick: function(selModel, record) {
  27. var val = record.get('check');
  28. if(val == 'error') {
  29. me.showDetail(selModel.ownerCt, record);
  30. }
  31. }
  32. },
  33. 'tbtext[id=yearmonth]': {
  34. afterrender: function(f) {
  35. this.getCurrentMonth(f);
  36. }
  37. }
  38. });
  39. },
  40. check: function(grid, idx, btn) {
  41. var me =this,f = grid.store.getAt(idx);
  42. if(!f) {
  43. btn.setDisabled(false);
  44. return;
  45. }
  46. f.set('check', 'loading');
  47. var win = Ext.getCmp('win-' + f.get('type'));
  48. if(win) {
  49. win.destroy();
  50. }
  51. Ext.Ajax.request({
  52. url: basePath + f.get('action'),
  53. params: {
  54. type: f.get('type'),
  55. month: me.currentMonth,
  56. pmonth: me.preYearmonth,
  57. start: me.datestart,
  58. end: me.dateend
  59. },
  60. callback: function(opt, s, r) {
  61. me.check(grid, ++idx, btn);
  62. var rs = Ext.decode(r.responseText);
  63. if(rs.ok) {
  64. f.set('check', 'checked');
  65. } else {
  66. f.set('check', 'error');
  67. }
  68. }
  69. });
  70. },
  71. checkAll: function(grid, record) {
  72. var me =this;
  73. record.set('check', 'loading');
  74. Ext.Ajax.request({
  75. url: basePath + record.get('action'),
  76. params: {
  77. type: record.get('type'),
  78. month: me.currentMonth,
  79. pmonth: me.preYearmonth,
  80. start: me.datestart,
  81. end: me.dateend,
  82. all: true
  83. },
  84. async: false,
  85. callback: function(opt, s, r) {
  86. var rs = Ext.decode(r.responseText);
  87. if(rs.ok) {
  88. record.set('check', 'checked');
  89. } else {
  90. record.set('check', 'error');
  91. }
  92. }
  93. });
  94. },
  95. exportExcel: function(type) {
  96. var title = Ext.Date.format(new Date(), 'Y-m-d H:m:s');
  97. if (!Ext.fly('ext-grid-excel')) {
  98. var frm = document.createElement('form');
  99. frm.id = 'ext-grid-excel';
  100. frm.name = id;
  101. frm.className = 'x-hidden';
  102. document.body.appendChild(frm);
  103. }
  104. Ext.Ajax.request({
  105. url: basePath + ('fa/exportBillError.xls'),
  106. method: 'post',
  107. form: Ext.fly('ext-grid-excel'),
  108. isUpload: true,
  109. params: {
  110. type: type,
  111. title: title
  112. }
  113. });
  114. },
  115. getAll: function(grid, record) {
  116. var p = Ext.create('Ext.ProgressBar', {
  117. renderTo: Ext.getBody(),
  118. floating: true,
  119. width: 300,
  120. value: 0.4,
  121. text: '获取全部数据...'
  122. }).show();
  123. this.checkAll(grid, record);
  124. p.updateProgress(0.8, '正在下载...', true);
  125. this.exportExcel(record.get('type'));
  126. Ext.defer(function(){
  127. p.setVisible(false);
  128. }, 3000);
  129. },
  130. showDetail: function(grid, record) {
  131. var me = this, wid = 'win-' + record.get('type'),
  132. win = Ext.getCmp(wid);
  133. if(!win) {
  134. win = Ext.create('Ext.Window', {
  135. title: record.get('value'),
  136. id: wid,
  137. width: 800,
  138. height: 500,
  139. layout: 'anchor',
  140. items: [{
  141. xtype: 'gridpanel',
  142. anchor: '100% 100%',
  143. columnLines: true,
  144. cls: 'custom',
  145. columns: [{
  146. text: '单据',
  147. flex: 1,
  148. dataIndex: 'be_class'
  149. },{
  150. text: '编号',
  151. flex: 1.6,
  152. dataIndex: 'be_code'
  153. },{
  154. text: '检测时间',
  155. flex: 1,
  156. dataIndex: 'be_date',
  157. renderer: function(val) {return Ext.Date.format(new Date(val), 'Y-m-d');}
  158. },{
  159. text: '检测人',
  160. flex: .8,
  161. dataIndex: 'be_checker'
  162. },{
  163. text: '备注',
  164. flex: 3,
  165. dataIndex: 'be_remark'
  166. }],
  167. store: new Ext.data.Store({
  168. fields: ['be_class', 'be_code', 'be_date', 'be_checker', 'be_remark']
  169. })
  170. }],
  171. buttonAlign: 'center',
  172. buttons: [{
  173. text: $I18N.common.button.erpExportButton,
  174. iconCls: 'x-button-icon-excel',
  175. cls: 'x-btn-blue',
  176. handler: function(btn) {
  177. me.BaseUtil.exportGrid(btn.up('window').down('gridpanel'));
  178. }
  179. },{
  180. text: '导出全部',
  181. iconCls: 'x-button-icon-excel',
  182. cls: 'x-btn-blue',
  183. handler: function(btn) {
  184. me.getAll(grid, record);
  185. }
  186. },{
  187. text: $I18N.common.button.erpCloseButton,
  188. cls: 'x-btn-blue',
  189. handler: function(btn) {
  190. btn.ownerCt.ownerCt.close();
  191. }
  192. }]
  193. });
  194. this.getBillError(record.get('type'), win.down('gridpanel'));
  195. }
  196. win.show();
  197. },
  198. getCurrentMonth: function(f) {
  199. var me = this;
  200. Ext.Ajax.request({
  201. url: basePath + 'fa/getMonth.action',
  202. params: {
  203. type: 'MONTH-T'
  204. },
  205. callback: function(opt, s, r) {
  206. var rs = Ext.decode(r.responseText);
  207. if(rs.data) {
  208. me.currentMonth = rs.data.PD_DETNO;
  209. me.datestart = Ext.Date.format(new Date(rs.data.PD_STARTDATE), 'Ymd');
  210. me.dateend = Ext.Date.format(new Date(rs.data.PD_ENDDATE), 'Ymd');
  211. me.preYearmonth = rs.data.PreYearmonth;
  212. f.setText(rs.data.PD_DETNO + ' (从' + Ext.Date.format(new Date(rs.data.PD_STARTDATE), 'Y-m-d')
  213. + ' 到 ' + Ext.Date.format(new Date(rs.data.PD_ENDDATE), 'Y-m-d') +
  214. ') 上个期间: ' + rs.data.PreYearmonth);
  215. }
  216. }
  217. });
  218. },
  219. getBillError: function(type, grid) {
  220. Ext.Ajax.request({
  221. url: basePath + 'fa/getBillError.action',
  222. params: {
  223. type: type
  224. },
  225. callback: function(opt, s, r) {
  226. var rs = Ext.decode(r.responseText);
  227. if(rs.data) {
  228. grid.store.loadData(rs.data);
  229. } else if(rs.exceptionInfo) {
  230. showError(rs.exceptionInfo);
  231. }
  232. }
  233. });
  234. }
  235. });