InitImportGrid.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. Ext.define('erp.view.sys.init.InitImportGrid',{
  2. extend: 'Ext.grid.Panel',
  3. alias: 'widget.initimportgrid',
  4. columnLines: true,
  5. forceFit: true,
  6. viewConfig: {
  7. stripeRows: true,
  8. enableTextSelection: true
  9. },
  10. autoScroll:true,
  11. columns:[{
  12. text:'导入项目',
  13. dataIndex:'in_desc',
  14. style:'text-align:center',
  15. width:150,
  16. renderer:function(val,meta){
  17. if(val && val.indexOf('*')>0) return '<span style="color:red;">' + val + '</span>';
  18. return val;
  19. }
  20. },{
  21. text:'数据导入',
  22. style:'text-align:center',
  23. columns:[{
  24. dataIndex:'in_caller',
  25. text:'导入地址',
  26. style:'text-align:center',
  27. width:150,
  28. renderer:function(val, meta, record){
  29. return '<a href="'+basePath+'/ma/sysinit/initImportData.action?whoami='+val+'&title='+record.get('parentName')+'-'+record.get('in_desc')+'" target="_blank">数据导入</a>';
  30. }
  31. },{
  32. text:'记录数',
  33. style:'text-align:center'
  34. },{
  35. text:'导入日志',
  36. style:'text-align:center'
  37. },{
  38. text:'状态',
  39. width:40
  40. }]
  41. },{
  42. text:'最近更新日期',
  43. align:'center'
  44. },{
  45. text:'最近更新人',
  46. align:'center'
  47. }],
  48. features: [{
  49. id: 'group',
  50. ftype: 'grouping',
  51. groupHeaderTpl: Ext.create('Ext.XTemplate',
  52. '{rows:this.formatName}',
  53. {
  54. formatName: function(f) {
  55. return f[0].data.parentName;
  56. }
  57. }
  58. ),
  59. //hideGroupedHeader: true,
  60. enableGroupingMenu: false
  61. }],
  62. initComponent : function(){
  63. this.getGridColumnsAndStore(this, 'ma/sysinit/getImportDataItem.action');
  64. this.callParent(arguments);
  65. },
  66. getGridColumnsAndStore: function(grid, url, param, no){
  67. var me = this;
  68. grid.setLoading(true);
  69. Ext.Ajax.request({
  70. url : basePath + url,
  71. params: param,
  72. async: false,
  73. method : 'get',
  74. callback : function(options,success,response){
  75. grid.setLoading(false);
  76. if (!response) return;
  77. var res = new Ext.decode(response.responseText);
  78. if(res.exceptionInfo){
  79. showError(res.exceptionInfo);return;
  80. }
  81. grid.store=Ext.create('Ext.data.Store',{
  82. fields:[ {name: 'in_pid', type: 'int'},
  83. {name:'in_desc',type:'string'},
  84. {name:'in_caller',type:'string'},
  85. {name:'parentName',type:'string'}],
  86. groupField: 'in_pid',
  87. data:res.data,
  88. sorters: {property: 'in_detno', direction: 'ASC'},
  89. });
  90. }
  91. });
  92. },
  93. setStore: function(grid, fields, data, groupField, necessaryField){
  94. Ext.each(fields, function(f){
  95. if(f.name.indexOf(' ') > -1) {// column有取别名
  96. f.name = f.name.split(' ')[1];
  97. }
  98. if(!Ext.isChrome){
  99. if(f.type == 'date'){
  100. f.dateFormat = 'Y-m-d H:m:s';
  101. }
  102. }
  103. });
  104. var modelName = 'ext-model-' + grid.id;
  105. Ext.define(modelName, {
  106. extend: 'Ext.data.Model',
  107. fields: fields
  108. });
  109. var config = {
  110. model: modelName,
  111. groupField: groupField,
  112. getSum: function(records, field) {
  113. if (arguments.length < 2) {
  114. return 0;
  115. }
  116. var total = 0,
  117. i = 0,
  118. len = records.length;
  119. if(necessaryField) {
  120. for (; i < len; ++i) {//重写getSum,grid在合计时,只合计填写了必要信息的行
  121. var necessary = records[i].get(necessaryField);
  122. if(necessary != null && necessary != ''){
  123. total += records[i].get(field);
  124. }
  125. }
  126. } else {
  127. for (; i < len; ++i) {
  128. total += records[i].get(field);
  129. }
  130. }
  131. return total;
  132. },
  133. getCount: function() {
  134. if(necessaryField) {
  135. var count = 0;
  136. Ext.each(this.data.items, function(item){//重写getCount,grid在合计时,只合计填写了必要信息的行
  137. if(item.data[necessaryField] != null && item.data[necessaryField] != ''){
  138. count++;
  139. }
  140. });
  141. return count;
  142. }
  143. return this.data.items.length;
  144. }
  145. };
  146. if(grid.buffered) {//grid数据缓存
  147. config.buffered = true;
  148. config.pageSize = 200;
  149. config.purgePageCount = 0;
  150. config.proxy = {
  151. type: 'memory'
  152. };
  153. } else {
  154. config.data = data;
  155. }
  156. var store = Ext.create('Ext.data.Store', config);
  157. store.each(function(item, x){
  158. item.index = x;
  159. });
  160. if(grid.buffered) {
  161. var ln = data.length, records = [], i = 0;
  162. for (; i < ln; i++) {
  163. records.push(Ext.create(modelName, data[i]));
  164. }
  165. store.cacheRecords(records);
  166. }
  167. return store;
  168. },
  169. loadNewStore: function(grid, param){
  170. var me = this;
  171. param=param||grid.params;
  172. grid.setLoading(true);//loading...
  173. Ext.Ajax.request({//拿到grid的columns
  174. url : basePath + "common/loadNewGridStore.action",
  175. params: param,
  176. method : 'post',
  177. callback : function(options,success,response){
  178. grid.setLoading(false);
  179. var res = new Ext.decode(response.responseText);
  180. if(res.exceptionInfo){
  181. showError(res.exceptionInfo);return;
  182. }
  183. var data = res.data;
  184. if(!data || data.length == 0){
  185. grid.store.removeAll();
  186. me.add10EmptyItems(grid);
  187. } else {
  188. grid.store.loadData(data);
  189. }
  190. //自定义event
  191. grid.addEvents({
  192. storeloaded: true
  193. });
  194. grid.fireEvent('storeloaded', grid, data);
  195. }
  196. });
  197. },
  198. removeDetail:function(grid,id){
  199. grid.setLoading(true);
  200. Ext.Ajax.request({
  201. url : basePath + grid.deleteUrl,
  202. params: {
  203. id: id
  204. },
  205. method : 'post',
  206. callback : function(options,success,response){
  207. grid.setLoading(false);
  208. var localJson = new Ext.decode(response.responseText);
  209. if(localJson.exceptionInfo){
  210. showError(localJson.exceptionInfo);return;
  211. }
  212. if(localJson.success){
  213. showResult('提示','删除成功!');
  214. grid.loadNewStore(grid,grid.params);
  215. } else {
  216. delFailure();
  217. }
  218. }
  219. });
  220. },
  221. setColumns:function(columns){
  222. Ext.Array.each(columns,function(column){
  223. if(column.xtype=='yncolumn'){
  224. column.xtype='checkcolumn';
  225. column.editor= {
  226. xtype: 'checkbox',
  227. cls: 'x-grid-checkheader-editor'
  228. };
  229. }
  230. });
  231. return columns;
  232. },
  233. DetailUpdateSuccess:function(btn,type){
  234. var tabP=Ext.getCmp('saletabpanel'),_activeTab=tabP.activeTab;
  235. _activeTab.loadNewStore(_activeTab,_activeTab.params);
  236. var win=btn.up('window');
  237. if(win) win.close();
  238. }
  239. })