',
'',
'' + cols + '',
'',
''
)
};
return cfg;
},
//输入值之后进行模糊查询
doQuery: function(queryString, forceAll, rawQuery) {
if(!this.fireEvent('beforequery', this)) {
return;
};
queryString = queryString || '';
var me = this;
me.judge(me);
var dbfinds=me.dbfinds;
me.lastQueryValue=queryString;
if(queryString.trim()==''){
me.collapse( );
}else{
//加载数据
var data,dbCondition=[];
if(me.dbfinds){
var dbtplcondition = "";
for (let index = 0; index < dbfinds.length; index++) {
var item = dbfinds[index].from;
if(!dbfinds[index].ignore){
dbtplcondition+= "upper("+item+") like '%"+queryString.toUpperCase()+"%' or ";
}
}
dbtplcondition = "(" + dbtplcondition.substring(0,dbtplcondition.length-4) + ")";
if(dbtplcondition.length>0){
dbCondition = [{
type: 'condition',
value:dbtplcondition
}];
}
}
//添加默认条件
if(me.defaultCondition) {
dbCondition.push({
type: 'condition',
value: me.defaultCondition
});
}
Ext.Ajax.request({
url: me.dataUrl,
params: {
number: 1,
size: 10,
condition:JSON.stringify(dbCondition),
page: 1,
start: 0,
limit: 10
},
method: 'GET',
success: function(response, opts) {
data = Ext.decode(response.responseText);
data = data.data?data.data.list:[];
if(data!=null && data.length>0 && me.store){
me.store.loadData(data,false);
me.expand();
}else{
me.store.removeAll();
me.collapse();
}
},
failure: function(response, opts) {}
});
}
return true;
},
onTriggerClick:function(f){
if(!this.fireEvent('beforetriggerclick', this)) {
return;
};
f.blur(f);
//判断dbfindtrigger归属
f.judge(f);
var panel = f.up('content-panel') || Ext.getCmp('content-panel'),panelEl;
if(!f.column&&f.ownerCt.ownerCt.id.indexOf('window-')>-1){
panelEl = f.ownerCt.ownerCt.getEl();
}else{
panelEl = panel.getEl()
}
var box = panelEl.getBox();
var height = box.height;
var width = box.width;
var win = panel.add(Ext.create('Ext.window.Window', {
cls:'x-window-dbfind',
trigger:f,
belong:f.ownerCt,
modal:true,
height: height * 0.9,
width: width * 0.9,
title: '查找' + f.addTitle,
scrollable: true,
bodyPadding: 10,
constrain: true,
closable: true,
layout:'fit',
renderTo:panelEl,
items:[{
xtype:'multidbfindtriggerpanel',
columns: f.dbColumns,
dataUrl: f.dataUrl,
dbfinds: f.dbfinds,
belong: f.belong,
searchUrl: f.searchUrl,
dbSearchFields:f.dbSearchFields?f.dbSearchFields:[],
dbfindtrigger:f
}]
}));
win.show();
},
listeners: {
blur:function(f,e){
return true;//先不使用
var me = f,data;
var dbfinds = me.dbfinds;
if(f.value&&f.value!=''){
//添加默认条件
var searchField = null;
var dbCondition = [];
if(me.defaultCondition) {
dbCondition.push({
type: 'condition',
value: me.defaultCondition
});
}
for (let index = 0; index < dbfinds.length; index++) {
var item = dbfinds[index].to;
if(item==me.name){
searchField = dbfinds[index].from;
}
}
dbCondition.push({
type: 'condition',
value: searchField + "='"+me.value+"'"
});
Ext.Ajax.request({
url: me.dataUrl,
async:false,
params: {
number: 1,
size: 1,
condition:JSON.stringify(dbCondition),
page: 1,
start: 0,
limit: 10
},
method: 'GET',
success: function(response, opts) {
data = Ext.decode(response.responseText);
data = data.data?data.data.list:[];
},
failure: function(response, opts) {}
});
}
if(!f.value||f.value==''||data.length>1||data.length==0){
if(dbfinds&&dbfinds.length>0){
if(me.belong=='grid'){
for (let index = 0; index < dbfinds.length; index++) {
var item = dbfinds[index];
var rec = me.column.ownerCt.ownerCt.selModel.getLastSelected();
var nowRec = me.column.ownerCt.ownerCt.store.getData().getByKey(rec.id);
if(nowRec.get(item.to)&&nowRec.get(item.to)!=""){
nowRec.set(item.to,null);
}
if(nowRec.modified){
delete nowRec.modified[item.to];
}
if(JSON.stringify(nowRec.modified)=="{}"){
nowRec.dirty = false
}
if(me.name==item.to){
me.column.getEditor().setValue('');
}
}
}
}
}else if(data.length==1){
if(dbfinds&&dbfinds.length>0){
if(me.belong=='grid'){
for (let index = 0; index < dbfinds.length; index++) {
var item = dbfinds[index];
var rec = me.column.ownerCt.ownerCt.selModel.getLastSelected();
var nowRec = me.column.ownerCt.ownerCt.store.getData().getByKey(rec.id);
nowRec.set(item.to,data[0][item.from]);
if(me.name==item.to){
me.column.getEditor().setValue(data[0][item.from]);
}
}
}
}
}
},
select:function(combo,record,eOpts){
var me = combo;
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.column.ownerCt.ownerCt.selModel.getLastSelected();
var nowRec = me.column.ownerCt.ownerCt.store.getData().getByKey(rec.id);
nowRec.set(item.to,record.get(item.from));
if(me.name==item.to){
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.down('[name='+item.to+']');
if(field){
var val = record.get(item.from);
if(field.xtype=='dbfindtrigger'){
field.setRawValue(val);
field.value = val;
field.lastTriggerValue=val;
}else{
field.setValue(val);
}
}
}
}
}
}
},
judge:function(f){
if(f.ownerCt.xtype.trim().toUpperCase().indexOf('QUERYFORMPANEL')>-1){
f.belong = 'form';
return f.ownerCt.ownerCt
}else if(f.ownerCt.xtype.trim().toUpperCase().indexOf('FORMPANEL')>-1){
f.belong = 'form';
return f.ownerCt
}else if(f.column){
f.belong = 'grid';
return f.column.ownerCt.ownerCt.ownerCt
}
}
});