VastPost.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /**
  2. * 批量抛转按钮
  3. */
  4. Ext.define('erp.view.core.button.VastPost',{
  5. extend: 'Ext.Button',
  6. alias: 'widget.erpVastPostButton',
  7. text: $I18N.common.button.erpVastPostButton,
  8. tooltip: '可以抛转多条记录',
  9. iconCls: 'x-button-icon-check',
  10. cls: 'x-btn-gray-1',
  11. id: 'erpVastPostButton',
  12. initComponent : function(){
  13. this.callParent(arguments);
  14. },
  15. width: 90,
  16. handler: function(){
  17. var grid = Ext.getCmp('grid');
  18. var records = grid.getMultiSelected();
  19. if(records.length > 0){
  20. var me = this;
  21. var win = new Ext.window.Window({
  22. title: '数据抛转',
  23. id : 'win-post',
  24. height: "100%",
  25. width: "80%",
  26. maximizable : true,
  27. modal: true,
  28. buttonAlign : 'center',
  29. layout : 'anchor',
  30. items: [me.createForm(), me.createGrid(grid)],
  31. });
  32. win.show();
  33. this.getCurrentMaster();
  34. this.getMasters();
  35. }
  36. },
  37. /**
  38. *
  39. */
  40. createForm: function(){
  41. var me = this;
  42. return Ext.create('Ext.form.Panel', {
  43. anchor: '100% 23%',
  44. bodyStyle: 'background:#f1f1f1;',
  45. layout: 'column',
  46. items: [{
  47. xtype: 'fieldcontainer',
  48. columnWidth: 0.3,
  49. layout: 'column',
  50. style: {
  51. marginTop: '10px',
  52. marginLeft: '10px'
  53. },
  54. items: [{
  55. xtype: 'displayfield',
  56. id: 'ma_name',
  57. name: 'ma_name',
  58. columnWidth: 1,
  59. fieldLabel: '当前账套编号'
  60. },{
  61. xtype: 'displayfield',
  62. id: 'ma_function',
  63. name: 'ma_function',
  64. columnWidth: 1,
  65. fieldLabel: '当前账套描述'
  66. }]
  67. },{
  68. xtype: 'displayfield',
  69. columnWidth: 0.15,
  70. labelSeparator: '',
  71. fieldLabel: '<img src="' + basePath + 'resource/images/screens/network.png">'
  72. },{
  73. xtype: 'displayfield',
  74. columnWidth: 0.1,
  75. labelSeparator: '',
  76. style: {
  77. marginTop: '20px',
  78. },
  79. fieldLabel: '<img src="' + basePath + 'resource/images/screens/arrow.png">'
  80. },{
  81. xtype: 'displayfield',
  82. columnWidth: 0.15,
  83. labelSeparator: '',
  84. fieldLabel: '<img src="' + basePath + 'resource/images/screens/network.png">'
  85. },{
  86. xtype: 'fieldcontainer',
  87. columnWidth: 0.3,
  88. layout: 'column',
  89. style: {
  90. marginTop: '10px',
  91. marginRight: '10px'
  92. },
  93. items: [{
  94. xtype: 'combobox',
  95. id: 'ma_name_t',
  96. name: 'ma_name_t',
  97. columnWidth: 1,
  98. fieldLabel: '选择抛转账套',
  99. displayField: 'display',
  100. valueField: 'value',
  101. queryMode: 'local',
  102. editable: false,
  103. store: Ext.create('Ext.data.Store', {
  104. fields: ['display', 'value'],
  105. data : []
  106. })
  107. },{
  108. xtype: 'displayfield',
  109. id: 'ma_function_t',
  110. name: 'ma_function_t',
  111. fieldLabel: '抛转账套描述',
  112. columnWidth: 1
  113. },{
  114. xtype: 'hidden',
  115. id: 'ma_id_t',
  116. name: 'ma_id_t'
  117. }]
  118. }],
  119. buttonAlign: 'center',
  120. buttons: [{
  121. text: '开始抛转',
  122. iconCls: 'x-button-icon-download',
  123. cls: 'x-btn-gray',
  124. handler: function(btn){
  125. var maid = Ext.getCmp('ma_id_t').value;
  126. if(Ext.isEmpty(maid)){
  127. alert("请先选择账套!");
  128. } else {
  129. me.post(btn.up('window').down('grid'), maid);
  130. }
  131. }
  132. },{
  133. text: '取消',
  134. iconCls: 'x-button-icon-close',
  135. cls: 'x-btn-gray',
  136. handler: function(){
  137. Ext.getCmp('win-post').close();
  138. }
  139. }]
  140. });
  141. },
  142. /**
  143. *
  144. */
  145. createGrid: function(grid){
  146. var records = grid.getMultiSelected();
  147. var fields = new Array();
  148. Ext.each(Ext.Object.getKeys(records[0].data), function(f){
  149. fields.push('_' + f);
  150. });
  151. fields.push('_status');
  152. fields.push('_error');
  153. var cols = new Array();
  154. cols.push({
  155. dataIndex: '_status',
  156. text: '<font color=blue>抛转状态</font>',
  157. width: 100,
  158. cls: 'x-grid-header-1',
  159. renderer: function(val){
  160. if(val == '未抛转'){
  161. return '<font color=blue>未抛转</font>';
  162. } else if(val == '抛转中'){
  163. return '<img src="' + basePath + 'resource/images/download.png">' + '<font color=blue>...</font>';
  164. } else if(val == '抛转成功'){
  165. return '<img src="' + basePath + 'resource/images/face/1.gif">' + '<font color=blue>抛转成功</font>';
  166. } else if(val == '抛转失败'){
  167. return '<img src="' + basePath + 'resource/images/face/6.gif">' + '<font color=red>抛转失败</font>';
  168. } else {
  169. return val;
  170. }
  171. }
  172. });
  173. cols.push({
  174. dataIndex: '_error',
  175. text: '<font color=blue>失败原因</font>',
  176. width: 150,
  177. cls: 'x-grid-header-1',
  178. hidden: true
  179. });
  180. Ext.each(grid.columns, function(c){
  181. if(c.text != '&#160;'){
  182. cols.push({
  183. dataIndex: '_' + c.dataIndex,
  184. text: c.text,
  185. width: c.width,
  186. hidden: c.hidden,
  187. xtype: c.xtype,
  188. cls: 'x-grid-header-1'
  189. });
  190. }
  191. });
  192. var datas = new Array();
  193. Ext.each(records, function(r){
  194. var d = r.data;
  195. Ext.each(fields, function(f){
  196. if(f == '_status'){
  197. d._status = '未抛转';
  198. } else {
  199. d[f] = d[f.substr(1)];
  200. }
  201. });
  202. datas.push(d);
  203. });
  204. return Ext.create('Ext.grid.Panel', {
  205. anchor: '100% 77%',
  206. bodyStyle: 'background:#f1f1f1;',
  207. columns: cols,
  208. columnLines: true,
  209. store: Ext.create('Ext.data.Store', {
  210. fields: fields,
  211. data: datas
  212. })
  213. });
  214. },
  215. /**
  216. * 加载当前用户所在账套
  217. */
  218. getCurrentMaster: function(){
  219. Ext.Ajax.request({
  220. url: basePath + 'common/getMasterByEm.action',
  221. method: 'get',
  222. callback: function(options,success,response){
  223. var res = Ext.decode(response.responseText);
  224. if(res.master){
  225. Ext.getCmp('ma_name').setValue(res.master.ma_name);
  226. Ext.getCmp('ma_function').setValue(res.master.ma_function);
  227. }
  228. }
  229. });
  230. },
  231. /**
  232. * 加载系统所有账套
  233. */
  234. getMasters: function(){
  235. Ext.Ajax.request({
  236. url: basePath + 'common/getMasters.action',
  237. method: 'get',
  238. callback: function(options,success,response){
  239. var res = Ext.decode(response.responseText);
  240. if(res.masters){
  241. var data = new Array();
  242. Ext.each(res.masters, function(m){
  243. data.push({
  244. display: m.ma_name,
  245. value: m.ma_name,
  246. desc: m.ma_function,
  247. id: m.ma_id
  248. });
  249. });
  250. Ext.getCmp('ma_name_t').store.loadData(data);
  251. Ext.getCmp('ma_name_t').on('change', function(f, n, o, obj){
  252. Ext.each(data, function(d){
  253. if(d.value == n){
  254. Ext.getCmp('ma_function_t').setValue(d.desc);
  255. Ext.getCmp('ma_id_t').setValue(d.id);
  256. }
  257. });
  258. });
  259. }
  260. }
  261. });
  262. },
  263. /**
  264. * 抛转数据
  265. */
  266. post: function(grid, maid){
  267. var me = this;
  268. var ids = new Array();
  269. Ext.each(grid.store.data.items, function(){
  270. ids.push(this.data['_' + keyField]);
  271. this.set('_status', '抛转中');
  272. this.commit();
  273. });
  274. parent.Ext.getCmp('content-panel').getActiveTab().setLoading(true);//loading...
  275. Ext.Ajax.request({
  276. url : basePath + (me.url || 'common/vastPost.action'),
  277. params: {
  278. id: ids,
  279. ma_id: maid
  280. },
  281. method : 'post',
  282. callback : function(options,success,response){
  283. parent.Ext.getCmp('content-panel').getActiveTab().setLoading(false);
  284. var localJson = new Ext.decode(response.responseText);
  285. if(localJson.exceptionInfo){
  286. showError(localJson.exceptionInfo);
  287. return "";
  288. }
  289. if(localJson.log){
  290. var bool = false;
  291. Ext.each(localJson.log, function(log){
  292. log = Ext.decode(log);
  293. Ext.each(grid.store.data.items, function(){
  294. if(this.data['_' + keyField] == log.id){
  295. if(log.success){
  296. this.set('_status', '抛转成功');
  297. } else {
  298. bool = true;
  299. this.set('_status', '抛转失败');
  300. this.set('_error', log.error);
  301. }
  302. this.commit();
  303. }
  304. });
  305. if(bool){
  306. Ext.each(grid.columns, function(cn){
  307. if(cn.dataIndex == '_error'){
  308. cn.show();
  309. }
  310. });
  311. }
  312. });
  313. }
  314. }
  315. });
  316. }
  317. });