Ext.define('uas.view.trigger.MultiDbfindTriggerPanel', { extend: 'Ext.grid.Panel', xtype: 'multidbfindtriggerpanel', dataUrl: '', dbSearchFields: [], condition:'', selectRecordArr:[], plugins: { gridHeaderFilter: true }, selModel: { checkOnly:true, type:'checkboxmodel', ignoreRightMouseSelection : false, listeners:{ select:function(selModel,record,c,d){ if(!selModel.noChange){ var selectRecordArr = selModel.view.ownerCt.selectRecordArr; selectRecordArr.push(record); } }, deselect:function(selModel,record){ if(!selModel.noChange){ var selectRecordArr = selModel.view.ownerCt.selectRecordArr; var index = -1; index = selectRecordArr.findIndex(function(f){ return f.id==record.id }); if(index>-1){ selectRecordArr.splice(index,1); } } } } }, listeners:{ itemdblclick:function( view, record, item, index, e, eOpts ) { var grid = view.ownerCt; var index = -1; index = grid.selectRecordArr.findIndex(function(f){ return f.id==record.id }); grid.selModel.noChange = true; if(index==-1){ grid.selectRecordArr.push(record); grid.selModel.select(grid.selectRecordArr); // grid.store.loadPage(grid.store.currentPage); grid.updateLayout(); grid.view.updateLayout(); Ext.resumeLayouts(); }else{ grid.selectRecordArr.splice(index,1); grid.selModel.deselect(record); } grid.selModel.noChange = false; } }, 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('multidbfindtriggerpanel'); if(!grid.searchPlanWindow){ grid.searchPlanWindow = Ext.create('widget.searchPlanWindow',{ modal: false, height:grid.getHeight()*0.95, width:grid.getWidth()*0.95, renderTo:grid.ownerCt.body, grid:grid }).show(); }else{ grid.searchPlanWindow.show(); } } },{ cls:'x-btn-green', margin:'0 0 0 6', xtype:'button', text:'确定', handler:function(me){ var grid = me.up('multidbfindtriggerpanel'); var selectRecordArr = grid.selectRecordArr; var dbfinds = grid.dbfinds; //点开放大镜的行 var mainGrid = grid.dbfindtrigger.column.ownerCt.ownerCt; var rec = mainGrid.selModel.getLastSelected(); Ext.Array.each(selectRecordArr,function(record,_index) { Ext.Array.each(dbfinds,function(dbfind) { if(rec){ var nowRec = mainGrid.store.getData().getByKey(rec.id); nowRec.set(dbfind.to,record.get(dbfind.from)); } }); var index = mainGrid.store.data.items.findIndex(function(f){ return f.id==(rec&&rec.id?rec.id:0) }); rec = mainGrid.store.data.getAt(index+1); if(!rec&&_index!=selectRecordArr.length-1){//添加下一行 var data = {}; data[mainGrid.ownerCt.detnoColumn] = index + 2; mainGrid.store.insert(index+1, data); rec = mainGrid.store.data.getAt(index+1); } }); //mainGrid.up('detailGridField').fireEvent('edit'); grid.ownerCt.close(); } },{ 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: 'multidbfindPaging' }], initComponent: function() { var me = this; me.selectRecordArr = []; 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', url: me.dataUrl, timeout:8000, 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.ownerCt.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=multidbfindPaging]'); 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(); }, /** * 获得过滤条件 */ 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; }, 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) {} }); } });