DataUpdate.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.ma.update.DataUpdate', {
  3. extend : 'Ext.app.Controller',
  4. requires : ['erp.util.GridUtil', 'erp.util.BaseUtil'],
  5. views : [ 'ma.update.DataUpdate', 'core.toolbar.Toolbar' ],
  6. init : function() {
  7. var me = this;
  8. me.GridUtil = Ext.create('erp.util.GridUtil');
  9. me.BaseUtil = Ext.create('erp.util.BaseUtil');
  10. this.control({
  11. '#updategrid':{
  12. afterrender : function(f) {
  13. f.addGrid= function(){
  14. me.createGrid(this, Ext.getCmp('scheme_id_').value,Ext.getCmp('scheme_id_').rawValue, true);
  15. };
  16. }
  17. },
  18. 'button[name=import]' : {
  19. click : function(btn) {
  20. me.onQueryClick();
  21. },
  22. afterrender : function() {
  23. Ext.defer(function(){
  24. me.onQueryClick();
  25. }, 500);
  26. }
  27. },
  28. 'button[id=checkupdate]':{
  29. click:function(btn){
  30. if(btn.activeItem.itemIndex==1)me.checkData();
  31. else me.updateData();
  32. }
  33. },
  34. 'button[name=history]' : {
  35. click : function(btn) {
  36. me.history();
  37. }
  38. },
  39. 'button[name=close]' : {
  40. click : function() {
  41. if (parent.Ext && parent.Ext.getCmp('content-panel')) {
  42. parent.Ext.getCmp('content-panel').getActiveTab().close();
  43. } else {
  44. window.close();
  45. }
  46. }
  47. },
  48. });
  49. },
  50. onQueryClick : function() {
  51. var me = this, win = me.querywin;
  52. if (!win) {
  53. var form = me.createQueryForm(), temp = me.createTempForm();
  54. win = me.querywin = Ext.create('Ext.window.Window', {
  55. closeAction : 'hide',
  56. closable:false,
  57. title : '选择更新方案',
  58. height: 500,
  59. width: 800,
  60. id:'scheme-win',
  61. layout: 'anchor',
  62. modal: true,
  63. items : [form, temp],
  64. buttonAlign : 'center',
  65. buttons : [{
  66. text : '查看历史',
  67. iconCls: 'history',
  68. cls : 'x-btn-gray',
  69. height : 26,
  70. width : 100,
  71. handler : function(b) {
  72. me.history();
  73. }
  74. },{
  75. text : '下载模板',
  76. iconCls: 'x-button-icon-excel',
  77. cls : 'x-btn-gray',
  78. height : 26,
  79. width : 100,
  80. handler : function(b) {
  81. me.exportExcel();
  82. }
  83. },{
  84. xtype: 'form',
  85. height : 26,
  86. width : 100,
  87. bodyStyle : 'background: transparent no-repeat 0 0;border: none;',
  88. items : [ { xtype : 'filefield',
  89. name : 'file',
  90. buttonOnly : true,
  91. hideLabel : true,
  92. buttonConfig : {
  93. iconCls : 'x-button-icon-excel',
  94. cls : 'x-btn-gray',
  95. width : 100,
  96. height : 26,
  97. text : $I18N.common.button.erpUpExcelButton
  98. },
  99. listeners : {
  100. change : function(field) {
  101. me.importData(field);
  102. }
  103. }} ],
  104. }, {
  105. text : $I18N.common.button.erpCloseButton,
  106. height : 26,
  107. width : 100,
  108. cls : 'x-btn-gray',
  109. handler : function(b) {
  110. if(!Ext.getCmp('updategrid-data')){
  111. Ext.getCmp('history').setDisabled(true);
  112. Ext.getCmp('checkupdate').setDisabled(true);
  113. }
  114. b.ownerCt.ownerCt.hide();
  115. }
  116. }]
  117. });
  118. }
  119. win.show();
  120. },
  121. createQueryForm:function(){
  122. var me = this;
  123. var form = Ext.create('Ext.form.Panel', {
  124. region: 'center',
  125. anchor: '100% 10%',
  126. layout: 'column',
  127. autoScroll: true,
  128. defaults: {
  129. columnWidth: 1,
  130. margin: '4 8 4 8'
  131. },
  132. bodyStyle: 'background:#f1f2f5;',
  133. items:[{
  134. xtype:'combo',
  135. flex:1,
  136. fieldLabel:'更新方案',
  137. allowBlank:false,
  138. name:'scheme_id_',
  139. id:'scheme_id_',
  140. listConfig:{
  141. maxHeight:180
  142. },
  143. store: schemeStore,
  144. displayField: 'title_',
  145. valueField: 'id_',
  146. queryMode: 'local',
  147. editable:false,
  148. triggerAction : 'all',
  149. listeners: {
  150. afterRender : function(combo) {
  151. if( schemeStore.getAt(0)!=null){
  152. var firstValue = schemeStore.getAt(0).get('id_');
  153. combo.setValue(firstValue);
  154. me.getUpdateDetail(firstValue);}
  155. },
  156. select: function (combo, record, index) {
  157. me.getUpdateDetail(record[0].data.id_);
  158. }
  159. }
  160. }]
  161. });
  162. return form;
  163. },
  164. createTempForm : function() {
  165. var me = this;
  166. return Ext.create('Ext.form.Panel', {
  167. id: 'temp',
  168. title: '可修改信息',
  169. anchor: '100% 90%',
  170. bodyStyle: 'background:#f1f1f1;',
  171. autoScroll : true,
  172. items:[
  173. { id: 'tempContainer',
  174. xtype: 'fieldcontainer',
  175. defaultType: 'checkboxfield',
  176. items: [],
  177. layout:'column',
  178. fieldDefaults: {
  179. margin: '3 10 3 10'
  180. }
  181. }]
  182. });
  183. },
  184. getUpdateDetail:function(id){
  185. var me = this;
  186. Ext.Ajax.request({
  187. url : basePath + 'ma/update/getUpdateDetail.action',
  188. params: {
  189. id: id,
  190. },
  191. method : 'post',
  192. callback : function(options,success,response){
  193. var res = new Ext.decode(response.responseText);
  194. if(res.exception || res.exceptionInfo){
  195. showError(res.exceptionInfo);
  196. return;
  197. }
  198. if(!res.success){
  199. return;
  200. } else {
  201. me.indexfields = res.indexfields;
  202. me.updatedetails = res.updatedetails;
  203. schemeDetails=me.indexfields.concat(me.updatedetails);
  204. var b=me.indexfields,d = me.updatedetails, mainitems = new Array();
  205. if(b && b.length > 0) {
  206. Ext.each(b, function(i){
  207. mainitems.push({
  208. xtype: 'checkbox',
  209. name: i.field_,
  210. boxLabel:i.caption_!='null'?'<font color=red>'+i.caption_+'</font>':'<font color=red>'+i.field_+'</font>',
  211. checked:true,
  212. columnWidth: 0.25,
  213. readOnly:true
  214. });
  215. });
  216. }
  217. if(d && d.length > 0) {
  218. Ext.each(d, function(i){
  219. mainitems.push({
  220. xtype: 'checkbox',
  221. name: i.field_,
  222. boxLabel: i.caption_,
  223. columnWidth: 0.25,
  224. checked:i.checked_
  225. });
  226. });
  227. }
  228. Ext.getCmp('tempContainer').removeAll();
  229. Ext.getCmp('tempContainer').add(mainitems);
  230. Ext.getCmp('temp').doLayout(true);
  231. }
  232. }
  233. });
  234. },
  235. exportExcel:function(){
  236. var me=this;
  237. var items = Ext.getCmp('tempContainer').items.items;
  238. var checked = new Array();
  239. Ext.each(items,function(item){
  240. if(!item.readOnly && item.checked)checked.push(item.name);
  241. });
  242. if (checked.length!=0){
  243. window.location = basePath + 'ma/update/exportExcel.xls?id=' + Ext.getCmp('scheme_id_').value +
  244. '&title=' + (Ext.getCmp('scheme_id_').rawValue)+'&checked='+unescape(checked);
  245. }else showError("请选择待更新的字段");
  246. },
  247. importData:function(field){
  248. var me=this;
  249. var bool = field.ownerCt.fireEvent('beforeimport', this);
  250. if (bool != false) {
  251. field.ownerCt.getForm().submit({
  252. url: basePath + 'ma/update/importData.action?id=' + Ext.getCmp('scheme_id_').value,
  253. waitMsg: "正在解析Excel",
  254. success: function(fp, o){
  255. field.reset();
  256. me.createGrid(Ext.getCmp('updategrid'), Ext.getCmp('scheme_id_').value,Ext.getCmp('scheme_id_').rawValue, true);
  257. Ext.getCmp('updategrid-data').ulid = o.result.ulid;
  258. Ext.getCmp('updategrid-data').down('pagingtoolbar').dataCount = o.result.count;
  259. Ext.getCmp('updategrid-data').down('pagingtoolbar').onLoad();
  260. Ext.getCmp('updategrid-data').getGridData(1);
  261. Ext.getCmp('checkupdate').setDisabled(false);
  262. Ext.getCmp('history').setDisabled(false);
  263. field.ownerCt.ownerCt.ownerCt.hide();
  264. },
  265. failure: function(fp, o){
  266. if(o.result.size){
  267. showError(o.result.error + "&nbsp;" + Ext.util.Format.fileSize(o.result.size));
  268. field.reset();
  269. } else {
  270. showError(o.result.error);
  271. field.reset();
  272. }
  273. }
  274. });
  275. }
  276. },
  277. emptyData: function(arr){
  278. var fields = new Array();
  279. Ext.each(arr, function(a){
  280. fields.push(a.field_);
  281. });
  282. return new Ext.data.Store({
  283. fields: fields,
  284. data: [{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}]
  285. });
  286. },
  287. parseUpdateDetails: function(arr){
  288. var me = this, d = new Array(),o;
  289. d.push({xtype: 'rownumberer', width: 35});
  290. Ext.each(arr, function(a){
  291. o = new Object();
  292. o.text = a.caption_;
  293. o.dataIndex = a.field_;
  294. o.width = a.width_;
  295. o.dataType = a.type_;
  296. o.editor = {
  297. xtype: 'textfield'
  298. };
  299. o.renderer = function(val, meta, record, x, y, store, view){
  300. return val;
  301. };
  302. d.push(o);
  303. });
  304. return d;
  305. },
  306. loadUpdateData: function(grid, page){
  307. var f = (page-1) * 100 + 1,
  308. t = page*100;
  309. grid.setLoading(true);
  310. Ext.Ajax.request({
  311. url: basePath + 'ma/update/getUpdateData.action',
  312. params: {
  313. condition: "ud_ulid=" + grid.ulid +
  314. " AND ud_detno between " + f + " AND " + t
  315. },
  316. method: 'post',
  317. callback: function(options, success, response){
  318. var res = new Ext.decode(response.responseText);
  319. grid.setLoading(false);
  320. if(res.exceptionInfo != null){
  321. showError(res.exceptionInfo);return;
  322. } else {
  323. var datas = new Array(), o;
  324. Ext.each(res.data, function(d){
  325. o = Ext.decode(d.ud_data);
  326. o.ud_id = d.ud_id;
  327. datas.push(o);
  328. });
  329. grid.store.loadData(datas);
  330. }
  331. }
  332. });
  333. },
  334. createGrid: function(p, id,title, isReload) {
  335. var me=this;
  336. var store = me.emptyData(schemeDetails);
  337. var updategrid= Ext.create('Ext.grid.Panel', {
  338. anchor: '100% 100%',
  339. id : 'updategrid-data',
  340. cls : 'default-grid',
  341. cfg: schemeDetails,//当前导入项的配置信息
  342. ulid:-1,
  343. checked:0,
  344. columnLines: true,
  345. columns: me.parseUpdateDetails(schemeDetails),
  346. store: store,
  347. dockedItems: [me.getDockedItems(store)],
  348. getGridData: function(page){
  349. me.loadUpdateData(this, page);
  350. },
  351. loadData: function(ulid, count, page){
  352. this.ulid = ulid;
  353. this.down('pagingtoolbar').dataCount = count;
  354. this.down('pagingtoolbar').onLoad();
  355. this.getGridData(page);
  356. }
  357. });
  358. p.add(updategrid);
  359. },
  360. checkData:function(){
  361. var me=this,grid=Ext.getCmp('updategrid-data');
  362. grid.setLoading(true);
  363. Ext.Ajax.request({
  364. url: basePath + 'ma/update/checkData.action',
  365. params: {
  366. ulid:grid.ulid
  367. },
  368. method: 'post',
  369. callback: function(options, success, response){
  370. var res = new Ext.decode(response.responseText);
  371. grid.setLoading(false);
  372. if(res.exceptionInfo != null){
  373. showError(res.exceptionInfo);return;
  374. } else {
  375. grid.checked=1;
  376. alert('校验成功!');
  377. }
  378. }
  379. });
  380. },
  381. updateData: function(){
  382. var me=this,grid=Ext.getCmp('updategrid-data');
  383. if(grid.checked==1){
  384. grid.setLoading(true);
  385. Ext.Ajax.request({
  386. url: basePath + 'ma/update/updateData.action',
  387. params: {
  388. ulid:grid.ulid
  389. },
  390. method: 'post',
  391. callback: function(options, success, response){
  392. var res = new Ext.decode(response.responseText);
  393. grid.setLoading(false);
  394. if(res.exceptionInfo != null){
  395. showError(res.exceptionInfo);return;
  396. } else {
  397. alert('更新成功!');
  398. }
  399. }
  400. });}
  401. else showError('请先校验数据!');
  402. },
  403. history:function(){
  404. var w = Ext.create('Ext.Window', {
  405. width: '60%',
  406. height: '80%',
  407. id: 'history-win',
  408. title: '更新数据历史记录',
  409. autoShow: true,
  410. layout: 'anchor',
  411. items: [{
  412. xtype: 'gridpanel',
  413. anchor: '100% 100%',
  414. columnLines: true,
  415. columns: [{dataIndex: 'ul_id', hidden: true},{dataIndex: 'ul_usid', hidden: true},{dataIndex: 'ul_man', text: '更新人编号', flex: 1},
  416. {dataIndex: 'ul_date', text: '日期', flex: 2},
  417. {dataIndex: 'ul_count', text: '数据量(条)', flex: 1},
  418. {dataIndex: 'ul_checked', text: '是否校验通过', flex: 1, renderer: function(val, m){
  419. if(val == '否') {
  420. m.style = 'float:right';
  421. }
  422. return val;
  423. }}, {dataIndex: 'ul_success', text: '是否更新成功', flex: 1, renderer: function(val, m){
  424. if(val == '否') {
  425. m.style = 'float:right';
  426. }
  427. return val;
  428. }}, {text: '', flex: 1, renderer: function(val, m, r){
  429. return '<a href="javascript:Ext.getCmp(\'updategrid\').addGrid();Ext.getCmp(\'updategrid-data\').loadData(' + r.get('ul_id') + ','
  430. + r.get('ul_count') + ',1);Ext.getCmp(\'history-win\').close();Ext.getCmp(\'scheme-win\').close();Ext.getCmp(\'checkupdate\').setDisabled(true);Ext.getCmp(\'history\').setDisabled(false);">载入</a>';
  431. }}],
  432. store: Ext.create('Ext.data.Store', {
  433. fields: ['ul_id', 'ul_usid', 'ul_man', 'ul_date', 'ul_count', 'ul_checked', 'ul_success'],
  434. data: [{},{},{},{},{},{},{},{}]
  435. })
  436. }]
  437. });
  438. this.getUpdateLog(w.down('gridpanel'));
  439. },
  440. getUpdateLog: function(g){
  441. Ext.Ajax.request({
  442. url: basePath + 'ma/update/updateHistory.action',
  443. params: {
  444. id: Ext.getCmp('scheme_id_').value
  445. },
  446. method: 'post',
  447. callback: function(opt, s, r){
  448. var res = new Ext.decode(r.responseText);
  449. var dd = res.data;
  450. Ext.each(dd, function(d){
  451. d.ul_date = Ext.Date.format(new Date(d.ul_date), 'Y-m-d H:i:s');
  452. d.ul_checked = d.ul_checked == 1 ? '是' : '否';
  453. d.ul_success = d.ul_success == 1 ? '是' : '否';
  454. });
  455. g.store.loadData(dd);
  456. }
  457. });
  458. },
  459. getDockedItems: function(store){
  460. return {
  461. xtype: 'pagingtoolbar',
  462. store: store,
  463. pageSize: 100,
  464. dataCount: store.data.items.length,
  465. page: 1,
  466. dock: 'bottom',
  467. displayInfo: true,
  468. updateInfo : function(){
  469. var page = this.child('#inputItem').getValue() || 1;
  470. var me = this,
  471. pageSize = me.pageSize || 100,
  472. dataCount = me.dataCount || 20;
  473. var displayItem = me.child('#displayItem'),
  474. pageData = me.getPageData();
  475. pageData.fromRecord = (page-1)*pageSize+1;
  476. pageData.toRecord = page*pageSize > dataCount ? dataCount : page*pageSize;
  477. pageData.total = dataCount;
  478. var msg;
  479. if (displayItem) {
  480. if (me.dataCount === 0) {
  481. msg = me.emptyMsg;
  482. } else {
  483. msg = Ext.String.format(
  484. me.displayMsg,
  485. pageData.fromRecord,
  486. pageData.toRecord,
  487. pageData.total
  488. );
  489. }
  490. displayItem.setText(msg);
  491. me.doComponentLayout();
  492. }
  493. },
  494. getPageData : function(){
  495. var me = this,
  496. totalCount = me.dataCount;
  497. return {
  498. total : totalCount,
  499. currentPage : me.page,
  500. pageCount: Math.ceil(me.dataCount / me.pageSize),
  501. fromRecord: ((me.page - 1) * me.pageSize) + 1,
  502. toRecord: Math.min(me.page * me.pageSize, totalCount)
  503. };
  504. },
  505. doRefresh:function(){
  506. this.moveFirst();
  507. },
  508. onPagingKeyDown : function(field, e){
  509. var me = this,
  510. k = e.getKey(),
  511. pageData = me.getPageData(),
  512. increment = e.shiftKey ? 10 : 1,
  513. pageNum = 0;
  514. if (k == e.RETURN) {
  515. e.stopEvent();
  516. pageNum = me.readPageFromInput(pageData);
  517. if (pageNum !== false) {
  518. pageNum = Math.min(Math.max(1, pageNum), pageData.pageCount);
  519. me.child('#inputItem').setValue(pageNum);
  520. if(me.fireEvent('beforechange', me, pageNum) !== false){
  521. me.page = pageNum;
  522. me.ownerCt.getGridData(me.page);
  523. }
  524. }
  525. } else if (k == e.HOME || k == e.END) {
  526. e.stopEvent();
  527. pageNum = k == e.HOME ? 1 : pageData.pageCount;
  528. field.setValue(pageNum);
  529. } else if (k == e.UP || k == e.PAGEUP || k == e.DOWN || k == e.PAGEDOWN) {
  530. e.stopEvent();
  531. pageNum = me.readPageFromInput(pageData);
  532. if (pageNum) {
  533. if (k == e.DOWN || k == e.PAGEDOWN) {
  534. increment *= -1;
  535. }
  536. pageNum += increment;
  537. if (pageNum >= 1 && pageNum <= pageData.pages) {
  538. field.setValue(pageNum);
  539. }
  540. }
  541. }
  542. me.updateInfo();
  543. me.resetTool(value);
  544. },
  545. moveFirst : function(){
  546. var me = this;
  547. me.child('#inputItem').setValue(1);
  548. value = 1;
  549. me.page = value;
  550. me.ownerCt.getGridData(value);
  551. me.updateInfo();
  552. me.resetTool(value);
  553. },
  554. movePrevious : function(){
  555. var me = this;
  556. me.child('#inputItem').setValue(me.child('#inputItem').getValue() - 1);
  557. value = me.child('#inputItem').getValue();
  558. me.page = value;
  559. me.ownerCt.getGridData(value);
  560. me.updateInfo();
  561. me.resetTool(value);
  562. },
  563. moveNext : function(){
  564. var me = this,
  565. last = me.getPageData().pageCount;
  566. total = last;
  567. me.child('#inputItem').setValue(me.child('#inputItem').getValue() + 1);
  568. value = me.child('#inputItem').getValue();
  569. me.page = value;
  570. me.ownerCt.getGridData(value);
  571. me.updateInfo();
  572. me.resetTool(value);
  573. },
  574. moveLast : function(){
  575. var me = this,
  576. last = me.getPageData().pageCount;
  577. total = last;
  578. me.child('#inputItem').setValue(last);
  579. value = me.child('#inputItem').getValue();
  580. me.page = value;
  581. me.ownerCt.getGridData(value);
  582. me.updateInfo();
  583. me.resetTool(value);
  584. },
  585. onLoad : function() {
  586. var e = this, d, b, c, a;
  587. if (!e.rendered) {
  588. return ;
  589. }
  590. d = e.getPageData();
  591. b = d.currentPage;
  592. c = Math.ceil(e.dataCount / e.pageSize);
  593. a = Ext.String.format(e.afterPageText, isNaN(c) ? 1 : c);
  594. e.child("#afterTextItem").setText(a);
  595. e.child("#inputItem").setValue(b);
  596. e.child("#first").setDisabled(b === 1);
  597. e.child("#prev").setDisabled(b === 1);
  598. e.child("#next").setDisabled(b === c || c===1);//
  599. e.child("#last").setDisabled(b === c || c===1);
  600. e.child("#refresh").enable();
  601. e.updateInfo();
  602. e.fireEvent("change", e, d);
  603. },
  604. resetTool: function(value){
  605. var pageCount = this.getPageData().pageCount;
  606. this.child('#last').setDisabled(value == pageCount || pageCount == 1);
  607. this.child('#next').setDisabled(value == pageCount || pageCount == 1);
  608. this.child('#first').setDisabled(value <= 1);
  609. this.child('#prev').setDisabled(value <= 1);
  610. }
  611. };
  612. }
  613. });