123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- Ext.define('erp.view.sys.init.InitImportGrid',{
- extend: 'Ext.grid.Panel',
- alias: 'widget.initimportgrid',
- columnLines: true,
- forceFit: true,
- viewConfig: {
- stripeRows: true,
- enableTextSelection: true
- },
- autoScroll:true,
- columns:[{
- text:'导入项目',
- dataIndex:'in_desc',
- style:'text-align:center',
- width:150,
- renderer:function(val,meta){
- if(val && val.indexOf('*')>0) return '<span style="color:red;">' + val + '</span>';
- return val;
-
- }
- },{
- text:'数据导入',
- style:'text-align:center',
- columns:[{
- dataIndex:'in_caller',
- text:'导入地址',
- style:'text-align:center',
- width:150,
- renderer:function(val, meta, record){
- return '<a href="'+basePath+'/ma/sysinit/initImportData.action?whoami='+val+'&title='+record.get('parentName')+'-'+record.get('in_desc')+'" target="_blank">数据导入</a>';
- }
- },{
- text:'记录数',
- style:'text-align:center'
- },{
- text:'导入日志',
- style:'text-align:center'
- },{
- text:'状态',
- width:40
- }]
-
- },{
- text:'最近更新日期',
- align:'center'
- },{
- text:'最近更新人',
- align:'center'
- }],
- features: [{
- id: 'group',
- ftype: 'grouping',
- groupHeaderTpl: Ext.create('Ext.XTemplate',
- '{rows:this.formatName}',
- {
- formatName: function(f) {
- return f[0].data.parentName;
- }
- }
- ),
- //hideGroupedHeader: true,
- enableGroupingMenu: false
- }],
- initComponent : function(){
- this.getGridColumnsAndStore(this, 'ma/sysinit/getImportDataItem.action');
- this.callParent(arguments);
-
- },
- getGridColumnsAndStore: function(grid, url, param, no){
- var me = this;
- grid.setLoading(true);
- Ext.Ajax.request({
- url : basePath + url,
- params: param,
- async: false,
- method : 'get',
- callback : function(options,success,response){
- grid.setLoading(false);
- if (!response) return;
- var res = new Ext.decode(response.responseText);
- if(res.exceptionInfo){
- showError(res.exceptionInfo);return;
- }
- grid.store=Ext.create('Ext.data.Store',{
- fields:[ {name: 'in_pid', type: 'int'},
- {name:'in_desc',type:'string'},
- {name:'in_caller',type:'string'},
- {name:'parentName',type:'string'}],
- groupField: 'in_pid',
- data:res.data,
- sorters: {property: 'in_detno', direction: 'ASC'},
- });
- }
- });
- },
- setStore: function(grid, fields, data, groupField, necessaryField){
- Ext.each(fields, function(f){
- if(f.name.indexOf(' ') > -1) {// column有取别名
- f.name = f.name.split(' ')[1];
- }
- if(!Ext.isChrome){
- if(f.type == 'date'){
- f.dateFormat = 'Y-m-d H:m:s';
- }
- }
- });
- var modelName = 'ext-model-' + grid.id;
- Ext.define(modelName, {
- extend: 'Ext.data.Model',
- fields: fields
- });
- var config = {
- model: modelName,
- groupField: groupField,
- getSum: function(records, field) {
- if (arguments.length < 2) {
- return 0;
- }
- var total = 0,
- i = 0,
- len = records.length;
- if(necessaryField) {
- for (; i < len; ++i) {//重写getSum,grid在合计时,只合计填写了必要信息的行
- var necessary = records[i].get(necessaryField);
- if(necessary != null && necessary != ''){
- total += records[i].get(field);
- }
- }
- } else {
- for (; i < len; ++i) {
- total += records[i].get(field);
- }
- }
- return total;
- },
- getCount: function() {
- if(necessaryField) {
- var count = 0;
- Ext.each(this.data.items, function(item){//重写getCount,grid在合计时,只合计填写了必要信息的行
- if(item.data[necessaryField] != null && item.data[necessaryField] != ''){
- count++;
- }
- });
- return count;
- }
- return this.data.items.length;
- }
- };
- if(grid.buffered) {//grid数据缓存
- config.buffered = true;
- config.pageSize = 200;
- config.purgePageCount = 0;
- config.proxy = {
- type: 'memory'
- };
- } else {
- config.data = data;
- }
- var store = Ext.create('Ext.data.Store', config);
- store.each(function(item, x){
- item.index = x;
- });
- if(grid.buffered) {
- var ln = data.length, records = [], i = 0;
- for (; i < ln; i++) {
- records.push(Ext.create(modelName, data[i]));
- }
- store.cacheRecords(records);
- }
- return store;
- },
- loadNewStore: function(grid, param){
- var me = this;
- param=param||grid.params;
- grid.setLoading(true);//loading...
- Ext.Ajax.request({//拿到grid的columns
- url : basePath + "common/loadNewGridStore.action",
- params: param,
- method : 'post',
- callback : function(options,success,response){
- grid.setLoading(false);
- var res = new Ext.decode(response.responseText);
- if(res.exceptionInfo){
- showError(res.exceptionInfo);return;
- }
- var data = res.data;
- if(!data || data.length == 0){
- grid.store.removeAll();
- me.add10EmptyItems(grid);
- } else {
- grid.store.loadData(data);
- }
- //自定义event
- grid.addEvents({
- storeloaded: true
- });
- grid.fireEvent('storeloaded', grid, data);
- }
- });
- },
- removeDetail:function(grid,id){
- grid.setLoading(true);
- Ext.Ajax.request({
- url : basePath + grid.deleteUrl,
- params: {
- id: id
- },
- method : 'post',
- callback : function(options,success,response){
- grid.setLoading(false);
- var localJson = new Ext.decode(response.responseText);
- if(localJson.exceptionInfo){
- showError(localJson.exceptionInfo);return;
- }
- if(localJson.success){
- showResult('提示','删除成功!');
- grid.loadNewStore(grid,grid.params);
- } else {
- delFailure();
- }
- }
- });
- },
- setColumns:function(columns){
- Ext.Array.each(columns,function(column){
- if(column.xtype=='yncolumn'){
- column.xtype='checkcolumn';
- column.editor= {
- xtype: 'checkbox',
- cls: 'x-grid-checkheader-editor'
- };
- }
- });
- return columns;
- },
- DetailUpdateSuccess:function(btn,type){
- var tabP=Ext.getCmp('saletabpanel'),_activeTab=tabP.activeTab;
- _activeTab.loadNewStore(_activeTab,_activeTab.params);
- var win=btn.up('window');
- if(win) win.close();
- }
- })
|