Ext.QuickTips.init(); Ext.define('erp.controller.fa.fp.FundPlanning', { extend: 'Ext.app.Controller', FormUtil: Ext.create('erp.util.FormUtil'), GridUtil: Ext.create('erp.util.GridUtil'), BaseUtil: Ext.create('erp.util.BaseUtil'), views: ['fa.fp.FundPlanning', 'core.button.Query', 'core.button.Export', 'core.button.Print', 'core.button.Close', 'core.form.MonthDateField','core.form.ConDateFPField'], init:function(){ var me = this; this.control({ 'combo[name=fs_name]': { afterrender: function(f) { me.getRepCodes(f); }, change: function(f) { if(!Ext.isEmpty(f.value)) { var d = f.lastSelection[0].data.data, form = f.ownerCt; form.down('textfield[name=fs_code]').setValue(d.FS_CODE); var grid = form.ownerCt.down('grid'); me.resetGrid(grid, d); } } }, 'button[name=export]': { click: function(btn) { var grid = btn.ownerCt.ownerCt.ownerCt.down('gridpanel'); this.BaseUtil.exportGrid(grid); } }, 'erpQueryButton': { click: function(b) { var grid = b.ownerCt.ownerCt.ownerCt.down('gridpanel'); this.getGridData(grid); } } }); }, getRepCodes: function(f) { Ext.Ajax.request({ url : basePath + 'common/getFieldsDatas.action', params: { caller: 'FARepSet', fields: 'fs_code,fs_name,fs_title1,fs_title2,fs_righttitle1,fs_righttitle2,fs_head,fs_righthead', condition: '1=1' }, method : 'post', callback : function(options,success,response){ var rs = new Ext.decode(response.responseText); if(rs.exceptionInfo){ showError(rs.exceptionInfo);return; } if(rs.success){ var data = Ext.decode(rs.data), s = []; Ext.each(data, function(d){ s.push({ display: d.FS_NAME, value: d.FS_NAME, data: d }); }); f.store.loadData(s); if(s.length > 0) { f.setValue(s[0].value); } } } }); }, resetGrid: function(grid, d) { var columns = [{ text: d.FS_HEAD, dataIndex: 'frd_name', cls: 'x-grid-header-1', flex: 1 }, { text: '行次', dataIndex: 'frd_step', cls: 'x-grid-header-1', flex: 0.3 }, { text: d.FS_TITLE1, dataIndex: 'frd_amount1', cls: 'x-grid-header-1', xtype: 'numbercolumn', format: '0,000.00', align: 'right', flex: 1, renderer: function(v, m, r) { if (v == 0) { m.style = 'text-align: center;color:red;'; return '-'; } return Ext.util.Format.number(v, '0,000.00'); } }, { text: d.FS_TITLE2, dataIndex: 'frd_completerate', cls: 'x-grid-header-1', xtype: 'numbercolumn', format: '0,000.00', align: 'right', flex: 1, renderer: function(v, m, r) { if (v == 0) { m.style = 'text-align: center;color:red;'; return '-'; } return Ext.util.Format.number(v, '0,000.00'); } },{ text: d.FS_RIGHTHEAD, dataIndex: 'frd_rightname', cls: 'x-grid-header-1', flex: 1 }, { text: '行次', dataIndex: 'frd_rightstep', cls: 'x-grid-header-1', flex: 0.3 }, { text: d.FS_RIGHTTITLE1, dataIndex: 'frd_rightamount1', cls: 'x-grid-header-1', xtype: 'numbercolumn', format: '0,000.00', align: 'right', flex: 1, renderer: function(v, m, r) { if (v == 0) { m.style = 'text-align: center;color:red;'; return '-'; } return Ext.util.Format.number(v, '0,000.00'); } }, { text: d.FS_RIGHTTITLE2, dataIndex: 'frd_rightcompleterate', cls: 'x-grid-header-1', xtype: 'numbercolumn', format: '0,000.00', align: 'right', flex: 1, renderer: function(v, m, r) { if (v == 0) { m.style = 'text-align: center;color:red;'; return '-'; } return Ext.util.Format.number(v, '0,000.00'); } }]; var store = new Ext.data.Store({ fields: ['frd_name', 'frd_step', 'frd_amount1', 'frd_completerate', 'frd_rightname', 'frd_rightstep', 'frd_rightamount1', 'frd_rightcompleterate'], data: [{frd_step: 1},{frd_step: 2},{frd_step: 3},{frd_step: 4},{frd_step: 5}] }); grid.reconfigure(store, columns); this.getGridData(grid); }, getGridData: function(grid) { var code = Ext.getCmp('fs_code').value, fc = Ext.getCmp('frd_fpcircle').value, cond = ''; if(!Ext.isEmpty(code)) { cond = "frd_fscode='" + code + "'"; } if(!Ext.isEmpty(fc)) { if(cond.length > 0) cond += ' AND frd_fpcircle ' + fc; else cond = 'frd_fpcircle ' + fc; } if(cond.length == 0) { cond = '1=1'; } cond += ' order by to_number(frd_step)'; Ext.Ajax.request({ url : basePath + 'common/getFieldsDatas.action', params: { caller: 'FARepSetDet left join FARepSet on fs_id=fsd_fsid left join FAReportDetail on frd_fscode=fs_code and fsd_step=frd_step', fields: 'distinct frd_name, frd_step, fsd_rate*frd_amount1 frd_amount1, frd_completerate, frd_rightname, frd_rightstep, fsd_rightrate*frd_rightamount1 frd_rightamount1, frd_rightcompleterate', condition: cond }, method : 'post', callback : function(options,success,response){ var rs = new Ext.decode(response.responseText); if(rs.exceptionInfo){ showError(rs.exceptionInfo);return; } if(rs.success){ var data = Ext.decode(rs.data), s = []; Ext.each(data, function(d){ s.push({ frd_name: d.FRD_NAME, frd_step: d.FRD_STEP, frd_amount1: d.FRD_AMOUNT1, frd_completerate: d.FRD_COMPLETERATE, frd_rightname: d.FRD_RIGHTNAME, frd_rightstep: d.FRD_RIGHTSTEP, frd_rightamount1: d.FRD_RIGHTAMOUNT1, frd_rightcompleterate: d.FRD_RIGHTCOMPLETERATE }); }); grid.store.loadData(s); } } }); } });