| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382 |
- Ext.define('uas.view.trigger.DbfindTriggerPanel', {
- extend: 'Ext.grid.Panel',
- xtype: 'dbfindtriggerpanel',
- dataUrl: '',
- dbSearchFields: [],
- condition:'',
- plugins: {
- gridHeaderFilter: true
- },
- dockedItems: [{
- name:'operateToolbar',
- cls:'x-grid-operateToolbar',
- xtype: 'toolbar',
- dock: 'top',
- height:32,
- items:[{
- cls:'x-btn-blue',
- xtype:'button',
- text:'筛选',
- handler:function(me){
- const grid = me.up('dbfindtriggerpanel');
- if(!grid.searchPlanWindow){
- grid.searchPlanWindow = Ext.create('widget.searchPlanWindow',{
- modal: false,
- height:grid.getHeight()*0.95,
- width:grid.getWidth()*0.95,
- renderTo:grid.ownerCt.getEl(),
- grid:grid
- }).show();
- }else{
- grid.searchPlanWindow.show();
- }
- }
- },{
- margin:'0 0 0 6',
- xtype:'button',
- text:'批处理'
- },{
- margin:'0 0 0 6',
- xtype:'button',
- text:'上一页'
- },{
- margin:'0 0 0 6',
- xtype:'button',
- text:'下一页'
- },{
- margin:'0 0 0 6',
- xtype:'button',
- text:'导出'
- },{
- margin:'0 0 0 6',
- xtype:'button',
- text:'个性设置'
- },{
- margin:'0 0 0 12',
- xtype:'button',
- text:'关闭'
- }]
- },{
- xtype: 'toolbar',
- dock: 'top',
- name:'searchPlan',
- cls:'x-grid-searchPlan',
- height:32,
- items:[{
- xtype:'displayfield',
- value:'查询方案:'
- }]
- },{
- xtype: 'toolbar',
- dock: 'top',
- name:'filterToolbar',
- cls:'x-grid-filterToolbar',
- height:32,
- items:[{
- xtype:'displayfield',
- value:'筛选条件:'
- },'->']
- },{
- xtype: 'dataListPaging'
- }],
- initComponent: function() {
- var me = this;
- me.initColumns();
- if(me.columns){
- var fields = me.columns.map(column => column.dataIndex);
- me.store = Ext.create('Ext.data.Store',{
- fields:fields,
- autoLoad: true,
- pageSize: 10,
- grid:me,
- data: [],
- proxy: {
- type: 'ajax',
- timeout:8000,
- url: me.dataUrl,
- actionMethods: {
- read: 'GET'
- },
- reader: {
- type: 'json',
- rootProperty: 'data.list',
- totalProperty: 'data.total',
- },
- listeners: {
- exception: function(proxy, response, operation, eOpts) {
- if(operation.success) {
- if(response.timedout) {
- saas.util.BaseUtil.showErrorToast('请求超时');
- }
- }else {
- console.error('exception: ', response);
- saas.util.BaseUtil.showErrorToast('查询失败:' + (response.responseJson?response.responseJson.message:'请求超时'));
- }
- }
- }
- },
- listeners: {
- beforeload: function (store, op) {
- var condition = me.condition;
- if (Ext.isEmpty(condition)) {
- condition = [];
- }
- //添加默认条件
- if(me.up('window').trigger.defaultCondition) {
- condition.push({
- type: 'condition',
- value: me.ownerCt.trigger.defaultCondition
- });
- }
- Ext.apply(store.proxy.extraParams, {
- number: op._page,
- size: store.pageSize,
- condition: JSON.stringify(condition)
- });
- },
- load: function(store, records, successful, operation, eOpts) {
- const grid = store.grid;
- const paging = grid.down('[xtype=dataListPaging]');
- const pageCountItem = paging.down('#pageCountItem');
- const dataCount = paging.down('#dataCountItem');
- if(store.totalCount!==Number.MAX_SAFE_INTEGER){
- //展示*号
- if(store.currentPage===Number.MAX_SAFE_INTEGER){
- let page = store.totalCount/store.pageSize;
- page = page>parseInt(page)?page+1:page;
- store.currentPage = page;
- paging.down('#inputItem').setValue(page);
- }
- pageCountItem.update(Ext.String.format(paging.afterPageText,store.currentPage));
- dataCount.setValue("行/共"+store.totalCount+"行");
- }
- }
- }
- });
- }
- me.callParent(arguments);
- me.getSearchPlan();
- },
- listeners:{
- itemClick: function(view,record) {
- var me = this;
- var dbfinds = me.dbfinds;
- var ownerTrigger = me.ownerCt.trigger;
- ownerTrigger.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 mainGrid = me.dbfindtrigger.column.ownerCt.ownerCt;
- var rec = mainGrid.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));
- //mainGrid.up('detailGridField').fireEvent('edit');
- }
- }
- }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);
- }
- }
- }
- }else {
- var dbfind = Ext.Array.findBy(dbfinds, function(d) {
- return d.to = ownerTrigger.name;
- });
- if(dbfind) {
- ownerTrigger.setValue(record.get(dbfind.from));
- }
- }
-
- ownerTrigger.aftertrigger(ownerTrigger,record);
- }
- me.ownerCt.close();
- }
- },
- initColumns: function() {
- var me = this,
- columns = me.columns || [];
- Ext.Array.each(columns, function(c) {
- Ext.applyIf(c, {
- width: 200
- });
- });
- },
- getSearchFields: function() {
- var me = this,
- searchFields = me.dbSearchFields;
- Ext.Array.each(searchFields, function(f) {
- f.enableKeyEvents = true;
- f.listeners = {
- keydown: function(th, e, eOpts) {
- if(e.keyCode == 13) {
- me.condition = '', items = [];
- Ext.Array.each(searchFields,function(f) {
- var field = th.ownerCt.down('[name='+f.name+']')
- items.push(field);
- });
- me.condition = me.getCondition(items);
- me.store.loadPage(1);
- }
- }
- }
- });
- return searchFields;
- },
- /**
- * 获得过滤条件
- */
- getCondition: function(items) {
- var me = this,
- conditions = [];
- for(var i = 0; i < items.length; i++) {
- var item = items[i];
- var field = item.name,
- func = item.getCondition,
- value = item.value,
- condition;
- if(value&&value!=''){
- 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
- }
- }
- 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;
- },
- 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';
- }
- 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 00:00:00') + ',' + Ext.Date.format(new Date(to), 'Y-m-d 23:59:59');
- }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 conditionValue;
- },
- onAddClick: function(){
- var grid = this;
- var trigger = grid.ownerCt.trigger;
- saas.util.BaseUtil.openTab(trigger.addXtype, '新增'+trigger.addTitle,trigger.addXtype + '_add');
- },
- getSearchPlan:function(){
- const me = this;
- Ext.Ajax.request({
- url: me.searchUrl,
- params: '',
- method: 'GET',
- async:false,
- success: function(response, opts) {
- var _data = Ext.decode(response.responseText);
- if(_data&&_data.data){
- const searchPlan = me.down('[name=searchPlan]');
- let items = [];
- Ext.Array.each(_data.data,function(p){
- if(p.children&&p.children.length>0){
- Ext.Array.each(p.children,function(item){
- items.push({
- text:item.text,
- xtype:'button'
- })
- })
- }
- });
- searchPlan.add(items);
- }
- },
- failure: function(response, opts) {}
- });
- }
- });
|