InitImportGrid.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. console.log(res.data);
  82. grid.store=Ext.create('Ext.data.Store',{
  83. fields:[ {name: 'in_pid', type: 'int'},
  84. {name:'in_desc',type:'string'},
  85. {name:'in_caller',type:'string'},
  86. {name:'parentName',type:'string'}],
  87. groupField: 'in_pid',
  88. data:res.data,
  89. sorters: {property: 'in_detno', direction: 'ASC'},
  90. });
  91. console.log(grid.store);
  92. }
  93. });
  94. },
  95. setStore: function(grid, fields, data, groupField, necessaryField){
  96. Ext.each(fields, function(f){
  97. if(f.name.indexOf(' ') > -1) {// column有取别名
  98. f.name = f.name.split(' ')[1];
  99. }
  100. if(!Ext.isChrome){
  101. if(f.type == 'date'){
  102. f.dateFormat = 'Y-m-d H:m:s';
  103. }
  104. }
  105. });
  106. var modelName = 'ext-model-' + grid.id;
  107. Ext.define(modelName, {
  108. extend: 'Ext.data.Model',
  109. fields: fields
  110. });
  111. var config = {
  112. model: modelName,
  113. groupField: groupField,
  114. getSum: function(records, field) {
  115. if (arguments.length < 2) {
  116. return 0;
  117. }
  118. var total = 0,
  119. i = 0,
  120. len = records.length;
  121. if(necessaryField) {
  122. for (; i < len; ++i) {//重写getSum,grid在合计时,只合计填写了必要信息的行
  123. var necessary = records[i].get(necessaryField);
  124. if(necessary != null && necessary != ''){
  125. total += records[i].get(field);
  126. }
  127. }
  128. } else {
  129. for (; i < len; ++i) {
  130. total += records[i].get(field);
  131. }
  132. }
  133. return total;
  134. },
  135. getCount: function() {
  136. if(necessaryField) {
  137. var count = 0;
  138. Ext.each(this.data.items, function(item){//重写getCount,grid在合计时,只合计填写了必要信息的行
  139. if(item.data[necessaryField] != null && item.data[necessaryField] != ''){
  140. count++;
  141. }
  142. });
  143. return count;
  144. }
  145. return this.data.items.length;
  146. }
  147. };
  148. if(grid.buffered) {//grid数据缓存
  149. config.buffered = true;
  150. config.pageSize = 200;
  151. config.purgePageCount = 0;
  152. config.proxy = {
  153. type: 'memory'
  154. };
  155. } else {
  156. config.data = data;
  157. }
  158. var store = Ext.create('Ext.data.Store', config);
  159. store.each(function(item, x){
  160. item.index = x;
  161. });
  162. if(grid.buffered) {
  163. var ln = data.length, records = [], i = 0;
  164. for (; i < ln; i++) {
  165. records.push(Ext.create(modelName, data[i]));
  166. }
  167. store.cacheRecords(records);
  168. }
  169. return store;
  170. },
  171. loadNewStore: function(grid, param){
  172. var me = this;
  173. param=param||grid.params;
  174. grid.setLoading(true);//loading...
  175. Ext.Ajax.request({//拿到grid的columns
  176. url : basePath + "common/loadNewGridStore.action",
  177. params: param,
  178. method : 'post',
  179. callback : function(options,success,response){
  180. grid.setLoading(false);
  181. var res = new Ext.decode(response.responseText);
  182. if(res.exceptionInfo){
  183. showError(res.exceptionInfo);return;
  184. }
  185. var data = res.data;
  186. if(!data || data.length == 0){
  187. grid.store.removeAll();
  188. me.add10EmptyItems(grid);
  189. } else {
  190. grid.store.loadData(data);
  191. }
  192. //自定义event
  193. grid.addEvents({
  194. storeloaded: true
  195. });
  196. grid.fireEvent('storeloaded', grid, data);
  197. }
  198. });
  199. },
  200. removeDetail:function(grid,id){
  201. grid.setLoading(true);
  202. Ext.Ajax.request({
  203. url : basePath + grid.deleteUrl,
  204. params: {
  205. id: id
  206. },
  207. method : 'post',
  208. callback : function(options,success,response){
  209. grid.setLoading(false);
  210. var localJson = new Ext.decode(response.responseText);
  211. if(localJson.exceptionInfo){
  212. showError(localJson.exceptionInfo);return;
  213. }
  214. if(localJson.success){
  215. showResult('提示','删除成功!');
  216. grid.loadNewStore(grid,grid.params);
  217. } else {
  218. delFailure();
  219. }
  220. }
  221. });
  222. },
  223. setColumns:function(columns){
  224. Ext.Array.each(columns,function(column){
  225. if(column.xtype=='yncolumn'){
  226. column.xtype='checkcolumn';
  227. column.editor= {
  228. xtype: 'checkbox',
  229. cls: 'x-grid-checkheader-editor'
  230. };
  231. }
  232. });
  233. return columns;
  234. },
  235. DetailUpdateSuccess:function(btn,type){
  236. var tabP=Ext.getCmp('saletabpanel'),_activeTab=tabP.activeTab;
  237. _activeTab.loadNewStore(_activeTab,_activeTab.params);
  238. var win=btn.up('window');
  239. if(win) win.close();
  240. }
  241. })