hy il y a 7 ans
Parent
commit
eb10e5245e

+ 34 - 8
frontend/saas-web/app/view/core/dbfind/DbfindTrigger.js

@@ -190,9 +190,7 @@ Ext.define('saas.view.core.dbfind.DbfindTrigger', {
     listeners: {
         blur:function(f,e){
             var me = f;
-            var count = f.store.getCount();
-            var searchCount = false;//校验数据库是否有该字段
-            var dbfinds = me.dbfinds;
+            var dbfinds = me.dbfinds,data;
             if(f.value&&f.value!=''){
                 //添加默认条件
                 var searchField = null;
@@ -211,7 +209,7 @@ Ext.define('saas.view.core.dbfind.DbfindTrigger', {
                 }
                 dbCondition.push({
                     type: 'condition',
-                    value: searchField + "='"+me.value+"'"
+                    value: searchField + " like '%"+me.value+"%'"
                 });
                 Ext.Ajax.request({
                     url: me.dataUrl,
@@ -228,14 +226,11 @@ Ext.define('saas.view.core.dbfind.DbfindTrigger', {
                     success: function(response, opts) {
                         data = Ext.decode(response.responseText);
                         data = data.data?data.data.list:[];
-                        if(data.length>0){
-                            searchCount = true
-                        }
                     },
                     failure: function(response, opts) {}
                 }); 
             }
-            if(!f.value||f.value==''||!searchCount){
+            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++) {
@@ -269,6 +264,37 @@ Ext.define('saas.view.core.dbfind.DbfindTrigger', {
                         }
                     }
                 }
+            }else if(data.length==1){
+                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,data[0][item.from]);
+                            if(me.name==item.to){
+                                me.column.getEditor().setValue(data[0][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 = data[0][item.from];
+                                if(field.xtype=='dbfindtrigger'){
+                                    field.setRawValue(val);
+                                    field.setValue(val);
+                                    field.value = val;
+                                    field.lastTriggerValue=val;
+                                }else{
+                                    field.setValue(val);
+                                }    
+                            }
+                        }
+                    }
+                }
             }
         },
         select:function(combo,record,eOpts){

+ 13 - 17
frontend/saas-web/app/view/core/dbfind/MultiDbfindTrigger.js

@@ -172,9 +172,7 @@ Ext.define('saas.view.core.dbfind.MultiDbfindTrigger', {
 
     listeners: {
         blur:function(f,e){
-            var me = f;
-            var count = f.store.getCount();
-            var searchCount = false;//校验数据库是否有该字段
+            var me = f,data;
             var dbfinds = me.dbfinds;
             if(f.value&&f.value!=''){
                 //添加默认条件
@@ -194,7 +192,7 @@ Ext.define('saas.view.core.dbfind.MultiDbfindTrigger', {
                 }
                 dbCondition.push({
                     type: 'condition',
-                    value: searchField + "='"+me.value+"'"
+                    value: searchField + " like '%"+me.value+"%'"
                 });
                 Ext.Ajax.request({
                     url: me.dataUrl,
@@ -211,14 +209,11 @@ Ext.define('saas.view.core.dbfind.MultiDbfindTrigger', {
                     success: function(response, opts) {
                         data = Ext.decode(response.responseText);
                         data = data.data?data.data.list:[];
-                        if(data.length>0){
-                            searchCount = true
-                        }
                     },
                     failure: function(response, opts) {}
                 }); 
             }
-            if(!f.value||f.value==''||!searchCount){
+            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++) {
@@ -238,17 +233,18 @@ Ext.define('saas.view.core.dbfind.MultiDbfindTrigger', {
                                 me.column.getEditor().setValue('');
                             }
                         }
-                    }else if(me.belong=='form'){
+                    }
+                }
+            }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 field = me.ownerCt.down('[name='+item.to+']');
-                            if(field){
-                                if(field.xtype=='dbfindtrigger'){
-                                    field.setValue(null);
-                                    field.lastTriggerValue=null;
-                                }else{
-                                    field.setValue(null);
-                                }    
+                            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]);
                             }
                         }
                     }