123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426 |
- Ext.define('uas.view.trigger.DbfindTrigger', {
- extend: 'Ext.form.ComboBox',
- xtype: 'dbfindtrigger',
- triggerCls: Ext.baseCSSPrefix + 'form-search-trigger',
- queryMode: 'local',
- displayField: 'dispaly',
- valueField: 'value',
- minChars: 1, // 设置用户输入字符多少时触发查询
- tpl: '',
- enableKeyEvents: true,
- initComponent: function () {
- var me = this;
- Ext.apply(me, me.applyConfig());
- me.callParent();
- },
- applyConfig: function() {
- var me = this,
- dbtpls = me.dbtpls || [],
- fields = [],
- minWidth = 0,
- cols = '';
- for(let x = 0; x < dbtpls.length; x++) {
- let dbtpl = dbtpls[x],
- width = dbtpl.width || 100,
- field = dbtpl.field;
- fields.push(field);
- minWidth += width;
- if(dbtpls.length==(x+1)){
- cols += '<span style="padding:0 10px 0 10px;width:' + width + 'px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">{' + field + '}</span>';
- }else{
- cols += '<span style="padding:0 10px 0 10px;width:' + width + 'px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;float:left;">{' + field + '}</span>';
- }
- }
- minWidth += 15;
- cfg = {
- store: Ext.create('Ext.data.Store', {
- fields: fields,
- data: []
- }),
- listConfig: {
- minWidth: minWidth,
- width: minWidth,
- maxHeight: 210,
- autoScroll: true
- },
- tpl: Ext.create('Ext.XTemplate',
- '<ul style="padding-left: 0px;"><tpl for=".">',
- '<li role="option" class="x-boundlist-item" style="list-style:none; padding: 0;">',
- '<div style="height:30px;">',
- '' + cols + '',
- '</li>',
- '</tpl></ul>'
- )
- };
- return cfg;
- },
- //输入值之后进行模糊查询
- doQuery: function (queryString, forceAll, rawQuery) {
- if (!this.fireEvent('beforequery', this)) {
- return;
- };
- queryString = queryString || '';
- var me = this;
- if (me.lastQueryValue != queryString) {
- me.judge(me);
- me.lastQueryValue = queryString;
- if (queryString.trim() == '') {
- me.collapse();
- } else {
- //加载数据
- var data, dbfinds = me.dbfinds, dbCondition = [];
- if (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;
- } else {
- return false;
- }
- },
- onTriggerClick: function (f) {
- var me = this;
- if (!this.fireEvent('beforetriggerclick', this)) {
- return;
- };
- f.blur(f,null,null,true);
- //判断dbfindtrigger归属
- f.judge(f); //form
- var panel = f.up('content-panel') || Ext.getCmp('content-panel'),
- panelEl;
- if (!f.column && f.ownerCt.ownerCt.id.indexOf('window-') > -1 && f.ownerCt.ownerCt.id.indexOf('document-') <0) {
- panelEl = f.ownerCt.ownerCt.getEl()
- } else {
- panelEl = panel.getEl()
- }
- var box = panelEl.getBox();
- var height = box.height;
- var width = box.width;
- var dbItem = {
- xtype: 'dbfindtriggerpanel',
- columns: f.dbColumns,
- dataUrl: f.dataUrl,
- searchUrl: f.searchUrl,
- dbfinds: f.dbfinds,
- belong: f.belong,
- dbSearchFields: f.dbSearchFields ? f.dbSearchFields : [],
- dbfindtrigger: f,
- };
- if (me.onAddClick) {
- dbItem.onAddClick = me.onAddClick;
- }
- 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: panel.getEl(),
- items: [dbItem]
- }));
- win.show();
- },
- judge: function (f) {
- if (f.ownerCt.xtype.trim().toUpperCase().indexOf('QUERYFORMPANEL') > -1 ||
- (f.ownerCt.ownerCt && (f.ownerCt.ownerCt.xtype.trim().toUpperCase().indexOf('BASEPANEL') > -1 ||
- f.ownerCt.ownerCt.xtype.trim().toUpperCase().indexOf('EDITDATALIST') > -1))) {
- f.belong = 'form';
- return f.ownerCt.ownerCt
- } else if (f.ownerCt.xtype.trim().toUpperCase().indexOf('FORM') > -1) {
- f.belong = 'form';
- return f.ownerCt
- } else if (f.column) {
- f.belong = 'grid';
- return f.column.ownerCt.ownerCt.ownerCt
- }
- },
- listeners: {
- blur: function (f, e, op, isTrigger) {
- return true;//先不使用
- var me = f;
- var dbfinds = me.dbfinds,
- data;
- 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) {
- me.dbValues = {};
- 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);
- delete nowRec.modified[item.to];
- }
- if (me.name == item.to) {
- me.column.getEditor().setValue('');
- }
- }
- } 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) {
- let xtypes = field.getXTypes().split('/');
- if (xtypes.indexOf('dbfindtrigger') != -1) {
- field.setValue(null);
- field.lastTriggerValue = null;
- } else {
- field.setValue(null);
- field.publishState('value', null);
- }
- }
- }
- }else {
- me.setValue(null);
- }
- }
- if(!isTrigger){
- let rec = {
- data:{},
- get:function(name){
- return this.data[name]
- }
- }
- f.aftertrigger(f,rec);
- }
- } else if (data.length == 1) {
- me.dbValues = data[0];
- 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);
- }
- }
- }
- }
- }
- if(!isTrigger){
- let rec = {
- data:data[0],
- get:function(name){
- return this.data[name]
- }
- }
- f.aftertrigger(f,rec);
- }
- }
- },
- select: function (combo, record, eOpts) {
- var me = combo;
- var dbfinds = me.dbfinds;
- me.dbValues = record.data;
- 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.setValue(val);
- field.value = val;
- field.lastTriggerValue = val;
- } else {
- field.setValue(val);
- }
- }
- }
- }else {
- var dbfind = Ext.Array.findBy(dbfinds, function(d) {
- return d.to = me.name;
- });
- if(dbfind) {
- me.setValue(record.get(dbfind.from));
- }
- }
-
- me.aftertrigger(me, record);
- }
- }
- },
- aftertrigger: function (f) {
- return true;
- },
- setValue: function (v) {
- this.callParent(arguments);
- this.publishState('value', v);
- },
- getValue: function (f) {
- var me = this,
- val = me.rawToValue(me.processRawValue(me.getRawValue()));
- me.value = val;
- return val;
- },
- autoSetValue: function (combo, record) {
- 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.setValue(val);
- field.value = val;
- field.lastTriggerValue = val;
- } else {
- field.setValue(val);
- }
- }
- }
- }
- me.aftertrigger(me, record);
- }
- }
- });
|