|
|
@@ -80,17 +80,13 @@ Ext.define('saas.view.core.dbfind.MultiDbfindGridPanel', {
|
|
|
xtype:'button',
|
|
|
text:'查询',
|
|
|
handler:function(b){
|
|
|
- var grid = me;
|
|
|
+ var grid = me,items=[];
|
|
|
grid.condition = '';
|
|
|
- var fields = grid.dbSearchFields;
|
|
|
- Ext.Array.each(fields,function(f) {
|
|
|
+ Ext.Array.each(grid.dbSearchFields,function(f) {
|
|
|
var field = b.ownerCt.down('[name='+f.name+']')
|
|
|
- var c = grid.getCondition(field,f.conditionExpression);
|
|
|
- grid.condition+=c;
|
|
|
+ items.push(field);
|
|
|
});
|
|
|
- if(grid.condition.length>0){
|
|
|
- grid.condition = grid.condition.substring(0,grid.condition.length-5);
|
|
|
- }
|
|
|
+ grid.condition = grid.getCondition(items);
|
|
|
grid.store.loadPage(1);
|
|
|
}
|
|
|
},'->',{
|
|
|
@@ -255,68 +251,102 @@ Ext.define('saas.view.core.dbfind.MultiDbfindGridPanel', {
|
|
|
me.callParent(arguments);
|
|
|
},
|
|
|
|
|
|
- loadData: function(grid, url) {
|
|
|
- this.BaseUtil.request({url})
|
|
|
- .then(function(response) {
|
|
|
- var data = Ext.decode(response.responseText);
|
|
|
- grid.getStore().loadData(data.data);
|
|
|
- grid.fireEvent('afterLoadData', grid, data.data);
|
|
|
- })
|
|
|
- .catch(function(response) {
|
|
|
- // something...
|
|
|
- });
|
|
|
- },
|
|
|
+ /**
|
|
|
+ * 获得过滤条件
|
|
|
+ */
|
|
|
+ getCondition: function(items) {
|
|
|
+ var me = this,
|
|
|
+ conditions = [];
|
|
|
|
|
|
- listeners:{
|
|
|
- afterrender:function(grid){
|
|
|
- if(grid.dataUrl){
|
|
|
- grid.loadData(grid, grid.dataUrl);
|
|
|
+ for(var i = 0; i < items.length; i++) {
|
|
|
+ var item = items[i];
|
|
|
+ var field = item.name,
|
|
|
+ func = item.getCondition,
|
|
|
+ value = item.value,
|
|
|
+ condition;
|
|
|
+
|
|
|
+ if(typeof func == 'function') {
|
|
|
+ condition = {
|
|
|
+ type: 'condition',
|
|
|
+ value: func(value)
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ var xtype = item.xtype || 'textfield',
|
|
|
+ type = item.fieldType || me.getDefaultFieldType(xtype),
|
|
|
+ operation = item.operation || me.getDefaultFieldOperation(xtype),
|
|
|
+ conditionValue = me.getConditionValue(xtype, value);
|
|
|
+
|
|
|
+ if(!conditionValue) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ condition = {
|
|
|
+ type: type,
|
|
|
+ field: field,
|
|
|
+ operation: operation,
|
|
|
+ value: conditionValue
|
|
|
+ }
|
|
|
}
|
|
|
- }//,
|
|
|
- // itemClick: function(view,record) {
|
|
|
- // var me = this;
|
|
|
- // var dbfinds = me.dbfinds;
|
|
|
- // if(dbfinds&&dbfinds.length>0){
|
|
|
- // if(me.belong=='grid'){
|
|
|
- // for (let index = 0; index < dbfinds.length; index++) {
|
|
|
- // var item = dbfinds[index];
|
|
|
- // var rec = me.dbfindtrigger.column.ownerCt.ownerCt.selModel.getLastSelected();
|
|
|
- // if(rec){
|
|
|
- // var nowRec = me.dbfindtrigger.column.ownerCt.ownerCt.store.getData().getByKey(rec.id);
|
|
|
- // nowRec.set(item.to,record.get(item.from));
|
|
|
- // //me.column.getEditor().setValue(record.get(item.from));
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }else if(me.belong=='form'){
|
|
|
- // for (let index = 0; index < dbfinds.length; index++) {
|
|
|
- // var item = dbfinds[index];
|
|
|
- // var field = me.ownerCt.belong.down('[name='+item.to+']');
|
|
|
- // if(field){
|
|
|
- // var val = record.get(item.from);
|
|
|
- // if(field.xtype=='dbfindtrigger'){
|
|
|
- // field.setValue(val);
|
|
|
- // field.lastTriggerValue=val;
|
|
|
- // }else{
|
|
|
- // field.setValue(val);
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // me.ownerCt.close();
|
|
|
- // }
|
|
|
+ conditions.push(condition);
|
|
|
+ };
|
|
|
+ return conditions;
|
|
|
+ },
|
|
|
+
|
|
|
+ getDefaultFieldType: function(xtype) {
|
|
|
+ var type;
|
|
|
+
|
|
|
+ if(Ext.Array.contains(['numberfield'], xtype)) {
|
|
|
+ type = 'number';
|
|
|
+ }else if(Ext.Array.contains(['datefield', 'condatefield'], xtype)) {
|
|
|
+ type = 'date';
|
|
|
+ }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo', 'radiofield', 'radio'], xtype)) {
|
|
|
+ type = 'enum';
|
|
|
+ }else {
|
|
|
+ type = 'string';
|
|
|
+ }
|
|
|
+
|
|
|
+ return type;
|
|
|
},
|
|
|
|
|
|
- getCondition: function(f,conditionExpression){
|
|
|
- var condition = '';
|
|
|
- if((f.xtype == 'checkbox' || f.xtype == 'radio')&&f.logic){
|
|
|
-
|
|
|
- }else if(f.xtype=='textfield'&&f.value!=''){
|
|
|
- condition=conditionExpression.replace(new RegExp("\\{0}","g"), f.value);
|
|
|
+ getDefaultFieldOperation: function(xtype) {
|
|
|
+ var operation;
|
|
|
+
|
|
|
+ if(Ext.Array.contains(['numberfield'], xtype)) {
|
|
|
+ operation = '=';
|
|
|
+ }else if(Ext.Array.contains(['datefield'], xtype)) {
|
|
|
+ operation = '=';
|
|
|
+ }else if(Ext.Array.contains(['condatefield'], xtype)) {
|
|
|
+ operation = 'between';
|
|
|
+ }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo'], xtype)) {
|
|
|
+ operation = 'in';
|
|
|
+ }else {
|
|
|
+ operation = 'like';
|
|
|
}
|
|
|
- if(condition.length>0){
|
|
|
- condition+= ' AND ';
|
|
|
+
|
|
|
+ return operation;
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理部分字段值
|
|
|
+ */
|
|
|
+ getConditionValue: function(xtype, value) {
|
|
|
+ var conditionValue;
|
|
|
+ if(xtype == 'datefield') {
|
|
|
+ conditionValue = Ext.Date.format(new Date(from), 'Y-m-d h:i:s');
|
|
|
+ }else if(xtype == 'condatefield') {
|
|
|
+ var from = value.from,
|
|
|
+ to = value.to;
|
|
|
+
|
|
|
+ conditionValue = Ext.Date.format(new Date(from), 'Y-m-d h:i:s') + ',' + Ext.Date.format(new Date(to), 'Y-m-d h:i:s');
|
|
|
+ }else if(xtype == 'combobox' || xtype == 'combo') {
|
|
|
+ conditionValue = '\'' + value + '\'';
|
|
|
+ }else if(xtype == 'multicombo') {
|
|
|
+ conditionValue = value.map(function(v) {
|
|
|
+ return '\'' + v.value + '\'';
|
|
|
+ }).join(',');
|
|
|
+ }else {
|
|
|
+ conditionValue = value;
|
|
|
}
|
|
|
- return condition;
|
|
|
+
|
|
|
+ return conditionValue;
|
|
|
}
|
|
|
});
|