|
|
@@ -8,14 +8,8 @@ Ext.define('saas.view.core.base.BasePanelController', {
|
|
|
query: function() {
|
|
|
var form = this.view;
|
|
|
var grid = form.down('core-base-gridpanel');
|
|
|
- grid.condition = '';
|
|
|
- var fields = form.searchField.map(f => f.name);
|
|
|
- var items = [];
|
|
|
- Ext.each(fields, function(f, index){
|
|
|
- var field = form.dockedItems.items[0].down('[name='+f+']');
|
|
|
- items.push(field);
|
|
|
- });
|
|
|
- grid.condition = this.getCondition(items);
|
|
|
+
|
|
|
+ grid.condition = this.getConditions();
|
|
|
grid.store.loadPage(1);
|
|
|
},
|
|
|
|
|
|
@@ -25,11 +19,16 @@ Ext.define('saas.view.core.base.BasePanelController', {
|
|
|
saas.util.BaseUtil.openTab(form.xtype,'新增' + form._title,id);
|
|
|
},
|
|
|
|
|
|
- getCondition: function(items) {
|
|
|
- var me = this,
|
|
|
- conditions = [];
|
|
|
+ /**
|
|
|
+ * 获得过滤条件
|
|
|
+ */
|
|
|
+ getConditions: function() {
|
|
|
+ var me = this;
|
|
|
+ var form = this.view;
|
|
|
+ var items = form.dockedItems.items[0].items.items;
|
|
|
+ var conditions = [];
|
|
|
|
|
|
- for(var i = 0; i < items.length; i++) {
|
|
|
+ for(let i = 0; i < items.length; i++) {
|
|
|
var item = items[i];
|
|
|
var field = item.name,
|
|
|
func = item.getCondition,
|
|
|
@@ -43,10 +42,9 @@ Ext.define('saas.view.core.base.BasePanelController', {
|
|
|
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);
|
|
|
+ var type = item.fieldType || me.getDefaultFieldType(item),
|
|
|
+ operation = item.operation || me.getDefaultFieldOperation(item),
|
|
|
+ conditionValue = me.getConditionValue(item, value);
|
|
|
|
|
|
if(!conditionValue) {
|
|
|
continue;
|
|
|
@@ -60,38 +58,58 @@ Ext.define('saas.view.core.base.BasePanelController', {
|
|
|
}
|
|
|
conditions.push(condition);
|
|
|
}
|
|
|
- };
|
|
|
+ }
|
|
|
+
|
|
|
return conditions;
|
|
|
},
|
|
|
|
|
|
- getDefaultFieldType: function(xtype) {
|
|
|
- var type;
|
|
|
+ /**
|
|
|
+ * 只要arr1和arr2中存在相同项即返回真
|
|
|
+ */
|
|
|
+ isContainsAny: function (arr1, arr2) {
|
|
|
+ for (var i = 0; i < arr2.length; i++) {
|
|
|
+ var a2 = arr2[i];
|
|
|
+ if (!!arr1.find(function (a1) {
|
|
|
+ return a1 == a2
|
|
|
+ })) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+
|
|
|
+ getDefaultFieldType: function (field) {
|
|
|
+ var me = this,
|
|
|
+ xtypes = field.getXTypes().split('/'),
|
|
|
+ type;
|
|
|
|
|
|
- if(Ext.Array.contains(['numberfield'], xtype)) {
|
|
|
+ if (me.isContainsAny(xtypes, ['numberfield'])) {
|
|
|
type = 'number';
|
|
|
- }else if(Ext.Array.contains(['datefield', 'condatefield'], xtype)) {
|
|
|
+ } else if (me.isContainsAny(xtypes, ['datefield', 'condatefield', 'conmonthfield'])) {
|
|
|
type = 'date';
|
|
|
- }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo', 'radiofield', 'radio'], xtype)) {
|
|
|
+ } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
|
|
|
type = 'enum';
|
|
|
- }else {
|
|
|
+ } else if (me.isContainsAny(xtypes, ['combobox', 'multicombo', 'combo', 'radiofield', 'radio'])) {
|
|
|
+ type = 'enum';
|
|
|
+ } else {
|
|
|
type = 'string';
|
|
|
}
|
|
|
|
|
|
return type;
|
|
|
},
|
|
|
|
|
|
- getDefaultFieldOperation: function(xtype) {
|
|
|
- var operation;
|
|
|
+ getDefaultFieldOperation: function (field) {
|
|
|
+ var me = this,
|
|
|
+ xtypes = field.getXTypes().split('/'),
|
|
|
+ operation;
|
|
|
|
|
|
- if(Ext.Array.contains(['numberfield'], xtype)) {
|
|
|
- operation = '=';
|
|
|
- }else if(Ext.Array.contains(['datefield'], xtype)) {
|
|
|
+ if (me.isContainsAny(xtypes, ['numberfield', 'datefield', 'dbfindtrigger'])) {
|
|
|
operation = '=';
|
|
|
- }else if(Ext.Array.contains(['condatefield'], xtype)) {
|
|
|
+ } else if (me.isContainsAny(xtypes, ['condatefield', 'conmonthfield'])) {
|
|
|
operation = 'between';
|
|
|
- }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo'], xtype)) {
|
|
|
+ } else if (me.isContainsAny(xtypes, ['multidbfindtrigger', 'combobox', 'multicombo', 'combo'])) {
|
|
|
operation = 'in';
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
operation = 'like';
|
|
|
}
|
|
|
|
|
|
@@ -101,25 +119,34 @@ Ext.define('saas.view.core.base.BasePanelController', {
|
|
|
/**
|
|
|
* 处理部分字段值
|
|
|
*/
|
|
|
- getConditionValue: function(xtype, value) {
|
|
|
- var conditionValue;
|
|
|
- if(xtype == 'datefield') {
|
|
|
+ getConditionValue: function (field, value) {
|
|
|
+ var me = this,
|
|
|
+ xtypes = field.getXTypes().split('/'),
|
|
|
+ conditionValue;
|
|
|
+ if (me.isContainsAny(xtypes, ['datefield'])) {
|
|
|
conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
|
|
|
- }else if(xtype == 'condatefield') {
|
|
|
+ } else if (me.isContainsAny(xtypes, ['conmonthfield'])) {
|
|
|
+ var from = value.from,
|
|
|
+ to = value.to;
|
|
|
+
|
|
|
+ conditionValue = from + ',' + to;
|
|
|
+ } else if (me.isContainsAny(xtypes, ['condatefield'])) {
|
|
|
var from = value.from,
|
|
|
- to = value.to;
|
|
|
+ to = value.to;
|
|
|
|
|
|
conditionValue = Ext.Date.format(new Date(from), 'Y-m-d 00:00:00') + ',' + Ext.Date.format(new Date(to), 'Y-m-d 23:59:59');
|
|
|
- }else if(xtype == 'combobox' || xtype == 'combo') {
|
|
|
+ } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
|
|
|
+ conditionValue = value;
|
|
|
+ } else if (me.isContainsAny(xtypes, ['combobox', 'combo'])) {
|
|
|
conditionValue = '\'' + value + '\'';
|
|
|
- }else if(xtype == 'multicombo') {
|
|
|
- conditionValue = value.map(function(v) {
|
|
|
+ } else if (me.isContainsAny(xtypes, ['multicombo'])) {
|
|
|
+ conditionValue = value.map ? value.map(function (v) {
|
|
|
return '\'' + v.value + '\'';
|
|
|
- }).join(',');
|
|
|
- }else {
|
|
|
+ }).join(',') : '';
|
|
|
+ } else {
|
|
|
conditionValue = value;
|
|
|
}
|
|
|
|
|
|
return conditionValue;
|
|
|
- }
|
|
|
+ },
|
|
|
});
|