123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- Ext.define('erp.view.common.dbfind.GridPanel',{
- extend: 'Ext.grid.Panel',
- alias: 'widget.erpDbfindGridPanel',
- layout : 'fit',
- id: 'dbfindGridPanel',
- emptyText : $I18N.common.grid.emptyText,
- columnLines : true,
- autoScroll : true,
- store: [],
- columns: [],
- selModel: Ext.create('Ext.selection.CheckboxModel',{
- headerWidth: 0
- }),
- BaseUtil: Ext.create('erp.util.BaseUtil'),
- bodyStyle:'background-color:#f1f1f1;',
- dockedItems: [{
- id : 'pagingtoolbar',
- xtype: 'erpDbfindToolbar',
- dock: 'bottom',
- displayInfo: true
- }],
- plugins: [Ext.create('Ext.ux.grid.GridHeaderFilters')],
- initComponent : function(){
- this.callParent(arguments);
- this.getCount();
- },
- getColumnsAndStore: function(){
- var me = this;
- var c = condition;
- if(typeof trigger.getExtraCondition=='function'){
- var con = trigger.getExtraCondition();
- if(con!=''){
- c += ' AND ' + con;
- }
- }
- if(me.filterCondition){
- c += ' AND ' + me.filterCondition;
- }
- me.setLoading(true);
- Ext.Ajax.request({//拿到grid的columns
- url : basePath + 'common/dbfind.action',
- method : 'post',
- params : {
- which : which,
- caller : caller,
- field: key,
- condition: c,
- ob: dbOrderby,// dynamic order by
- page: page,
- pageSize: pageSize
- },
- callback : function(options,success,response){
- me.setLoading(false);
- var res = new Ext.decode(response.responseText);
- if(res.exceptionInfo){
- showError(res.exceptionInfo);return;
- }
- if(res.autoHeight) {
- me.addCls('custom-grid-autoheight');//自适应样式
- }
- var data = Ext.decode(res.data.replace(/,}/g, '}').replace(/,]/g, ']'));
- if(me.columns && me.columns.length > 2){
- me.store.loadData(data);
- if(me.store.data.items.length != data.length){
- me.store.add(data);
- }
- //修改pagingtoolbar信息
- Ext.getCmp('pagingtoolbar').afterOnLoad();
- } else {
- me.reconfigure(Ext.create('Ext.data.Store', {
- storeId: 'dbfindGridPanelStore',
- fields: res.fields,
- data: data
- }), res.columns);
- //修改pagingtoolbar信息
- Ext.getCmp('pagingtoolbar').afterOnLoad();
- dbfinds = res.dbfinds;
- //通用变更单dbfind 采用变更原有单据的放大镜
- if(trigger.isCommonChange){
-
- Ext.Array.each(dbfinds,function(d){
- d.field=d.field+'-new';
- });
- }
- me.resetable = res.reset;//允许重置条件
- trigger.dbfinds = dbfinds;
- if(me.resetable){
- var win = parent.Ext.getCmp('dbwin');
- win && win.down('#reset').show();
- }
- }
- }
- });
- },
- getCount: function(){
- var me = this;
- if(condition)condition=condition.replace(/\%'%/g,"%''%");
- var c = condition;
- if(typeof trigger.getExtraCondition=='function'){
- var con = trigger.getExtraCondition();
- if(con!=''){
- c += ' AND ' + con;
- }
- }
- if(me.filterCondition){
- me.filterCondition=me.filterCondition.replace(/\%'%/g,"%''%");
- c += ' AND ' + me.filterCondition;
- }
- Ext.Ajax.request({//拿到grid的数据总数count
- url : basePath + 'common/dbfindCount.action',
- params : {
- which : which,
- caller : caller,
- field: key,
- condition: c
- },
- method : 'post',
- callback : function(options,success,response){
- var res = new Ext.decode(response.responseText);
- dataCount = res.count;
- me.getColumnsAndStore();
- }
- });
- },
- listeners: {
- 'headerfiltersapply': function(grid, filters) {
- if(this.allowFilter){
- var condition = null;
- for(var fn in filters){
- var value = filters[fn], f = grid.getHeaderFilterField(fn);
- if(f.xtype == 'datefield')
- value = f.getRawValue();
- if(!Ext.isEmpty(value)) {
- if("null"!=value){
- if(f.filtertype) {
- if (f.filtertype == 'numberfield') {
- value = fn + "=" + value + " ";
- }
- } else {
- if(Ext.isDate(value)){
- value = Ext.Date.toString(value);
- value = "to_char(" + fn + ",'yyyy-MM-dd')='" + value + "' ";
- } else {
- var exp_t = /^(\d{4})\-(\d{2})\-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/,
- exp_d = /^(\d{4})\-(\d{2})\-(\d{2})$/;
- if(exp_d.test(value)){
- value = "to_char(" + fn + ",'yyyy-MM-dd')='" + value + "' ";
- } else if(exp_t.test(value)){
- value = "to_char(" + fn + ",'yyyy-MM-dd')='" + value.substr(0, 10) + "' ";
- } else{
- if (f.xtype == 'combo' || f.xtype == 'combofield') {
- if (value == '-所有-') {
- continue;
- } else if (value == '-无-') {
- value = 'nvl(' + fn + ',\' \')=\' \'';
- } else {
- value = fn + " LIKE '" + value + "%' ";
- }
- } else if(f.xtype == 'datefield') {
- value = "to_char(" + fn + ",'yyyy-MM-dd') like '%" + value + "%' ";
- } else if(f.column && f.column.xtype == 'numbercolumn'){
- if(f.column.format) {
- var precision = f.column.format.substr(f.column.format.indexOf('.') + 1).length;
- value = "to_char(round(" + fn + "," + precision + ")) like '%" + value + "%' ";
- } else
- value = "to_char(" + fn + ") like '%" + value + "%' ";
- } else {
- /**字符串转换下简体*/
- var SimplizedValue=this.BaseUtil.Simplized(value);
- //可能就是按繁体筛选
- if(f.ignoreCase) {// 忽略大小写
- fn = 'upper(' + fn + ')';
- value = value.toUpperCase();
- }
- if(!f.autoDim) {
- if(SimplizedValue!=value){
- value = "("+fn + " LIKE '" + value + "%' or "+fn+" LIKE '"+SimplizedValue+"%')";
- }else value = fn + " LIKE '" + value + "%' ";
-
- } else if(f.exactSearch){
- value=fn+"='"+value+"'";
- } else {
- if(SimplizedValue!=value){
- value = "("+fn + " LIKE '%" + value + "%' or "+fn+" LIKE '%"+SimplizedValue+"%')";
- }else value = fn + " LIKE '%" + value + "%' ";
- }
- }
- }
- }
- }
- }else value ="nvl("+fn+",' ')=' '";
- if(condition == null){
- condition = value;
- } else {
- condition = condition + " AND " + value;
- }
- }
- }
- this.filterCondition = condition;
- page = 1;
- this.getCount();
- } else {
- this.allowFilter = true;
- }
- return false;
- }
- },
- reconfigure: function(store, columns){
- //改写reconfigure方法
- var d = this.headerCt;
- if (this.columns.length <= 1 && columns) {//this.columns.length > 1表示grid的columns已存在,没必要remove再add
- if(!Ext.isChrome){//ie,firefox下,format出现NaN-NaN-NaN,暂时作string处理
- Ext.each(columns, function(c){
- if(c.xtype == 'datecolumn'){
- c.xtype = "";
- c.format = "";
- }
- });
- }
- d.suspendLayout = true;
- d.removeAll();
- d.add(columns);
- }
- if (store) {
- if(!Ext.isChrome){//ie,firefox下,format出现NaN-NaN-NaN
- Ext.each(store.fields, function(f){
- if(f.type == 'date'){
- f.type = "string";
- f.format = "";
- }
- });
- }
- this.bindStore(store);
- } else {
- this.getView().refresh();
- }
- if (columns) {
- d.suspendLayout = false;
- this.forceComponentLayout();
- }
- this.fireEvent("reconfigure", this);
- },
- /**
- * 重置条件
- * dbfindSet.ds_allowreset(1-允许)
- * dbfindSetUI.ds_allowreset(1-允许)
- */
- resetCondition: function(){
- condition = this.getCondition();
- this.filterCondition = '';
- var fields = this.plugins[0].fields;
- Ext.each(Ext.Object.getKeys(fields), function(key){
- fields[key].reset();
- });
- },
- getCondition: function() {
- condition = 'upper(' + key + ") like '%%'";
- if(!trigger.ownerCt || trigger.column){//如果是grid的dbfind
- condition = 'upper(' + keyField + ") like '%%'";
- if(dbGridCondition && dbGridCondition != null){
- condition += " AND " + decodeURIComponent(dbGridCondition).replace(/\s{1}IS\s{1}/g, '=');
- }
- }
- if(dbCondition && dbCondition != null){
- condition += " AND " + decodeURIComponent(dbCondition).replace(/\s{1}IS\s{1}/g, '=');
- }
- if(dbBaseCondition && dbBaseCondition != null){
- condition += " AND " + decodeURIComponent(dbBaseCondition).replace(/\s{1}IS\s{1}/g, '=').replace(/@/g,'%');
- }
- return condition;
- }
- });
|