|
|
@@ -0,0 +1,457 @@
|
|
|
+Ext.define('saas.view.core.dbfind.AddMultiDbfindGridPanel', {
|
|
|
+ extend: 'Ext.grid.Panel',
|
|
|
+ xtype: 'addmultidbfindgridpanel',
|
|
|
+
|
|
|
+ dataUrl: '',
|
|
|
+ dbSearchFields: [],
|
|
|
+ condition:'',
|
|
|
+ selectRecordArr:[],
|
|
|
+
|
|
|
+ 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:{
|
|
|
+ boxready: function(grid, width, height, eOpts) {
|
|
|
+ var store = grid.getStore(),
|
|
|
+ gridBodyBox = grid.body.dom.getBoundingClientRect(),
|
|
|
+ gridBodyBoxHeight = gridBodyBox.height;
|
|
|
+
|
|
|
+ var pageSize = Math.floor(gridBodyBoxHeight / 33);
|
|
|
+
|
|
|
+ store.setPageSize(pageSize);
|
|
|
+ },
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ 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: 6,
|
|
|
+ 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.responseJson);
|
|
|
+ saas.util.BaseUtil.showErrorToast('查询失败:' + 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)
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ Ext.apply(me, {
|
|
|
+ dockedItems:[{
|
|
|
+ xtype:'toolbar',
|
|
|
+ dock:'top',
|
|
|
+ items:me.getSearchFields().concat([{
|
|
|
+ xtype:'button',
|
|
|
+ text:'查询',
|
|
|
+ handler:function(b){
|
|
|
+ var grid = me,items=[];
|
|
|
+ grid.condition = '';
|
|
|
+ Ext.Array.each(grid.dbSearchFields,function(f) {
|
|
|
+ var field = b.ownerCt.down('[name='+f.name+']')
|
|
|
+ items.push(field);
|
|
|
+ });
|
|
|
+ grid.condition = grid.getCondition(items);
|
|
|
+ grid.store.loadPage(1);
|
|
|
+ grid.selModel.noChange = true;
|
|
|
+ grid.selModel.deselectAll();
|
|
|
+ grid.selModel.select(grid.selectRecordArr);
|
|
|
+ grid.selModel.noChange = false;
|
|
|
+ }
|
|
|
+ },'->',{
|
|
|
+ text:'确定',
|
|
|
+ cls:'x-formpanel-btn-blue',
|
|
|
+ handler:function(b){
|
|
|
+ debugger
|
|
|
+ var grid = me;//grid
|
|
|
+ var selectRecordArr = grid.selectRecordArr;
|
|
|
+ var dbfinds = grid.dbfinds;
|
|
|
+ //点开放大镜的行
|
|
|
+ var mainGrid = grid.dbfindtrigger.column.ownerCt.ownerCt;
|
|
|
+ var rec = mainGrid.selModel.getLastSelected();
|
|
|
+ var nowRec = mainGrid.store.getData().getByKey(rec.id);
|
|
|
+ var v = '';
|
|
|
+ Ext.Array.each(selectRecordArr,function(record,_index) {
|
|
|
+ v = v + record.get(dbfinds[0].from)+','
|
|
|
+ });
|
|
|
+ if(v.length>0){
|
|
|
+ nowRec.set(dbfinds[0].to,v.substring(0,v.length-1));
|
|
|
+ }
|
|
|
+ mainGrid.up('detailGridField').fireEvent('edit');
|
|
|
+ grid.ownerCt.close();
|
|
|
+ }
|
|
|
+ },{
|
|
|
+ xtype:'button',
|
|
|
+ text:'新增',
|
|
|
+ handler:function(b){
|
|
|
+ var grid = me;
|
|
|
+ var trigger = grid.ownerCt.trigger;
|
|
|
+ saas.util.BaseUtil.openTab(trigger.addXtype, '新增'+trigger.addTitle,trigger.addXtype + '_add');
|
|
|
+ },
|
|
|
+ listeners:{
|
|
|
+ afterrender:function(b){
|
|
|
+ var grid = me;
|
|
|
+ var trigger = grid.ownerCt.trigger;
|
|
|
+ if(!trigger.addXtype||trigger.addXtype==''){
|
|
|
+ b.hide();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }])
|
|
|
+ },{
|
|
|
+ xtype: 'pagingtoolbar',
|
|
|
+ dock: 'bottom',
|
|
|
+ displayInfo: true,
|
|
|
+ height:32,
|
|
|
+ style:'padding: 0;',
|
|
|
+ store: me.store,
|
|
|
+ items:[{
|
|
|
+ xtype:'checkbox',
|
|
|
+ id:'showSelectRecord',
|
|
|
+ boxLabel:'已选中数据',
|
|
|
+ handler:function(b){
|
|
|
+ var grid = me;
|
|
|
+ if(b.checked){
|
|
|
+ grid.store.loadData(grid.selectRecordArr);
|
|
|
+ grid.selModel.noChange = true;
|
|
|
+ grid.selModel.deselectAll();
|
|
|
+ grid.selModel.select(grid.selectRecordArr);
|
|
|
+ grid.selModel.noChange = false;
|
|
|
+ //刷新展示数据
|
|
|
+ var dataCount = grid.selectRecordArr.length,msg;
|
|
|
+ var display = b.ownerCt.child('#displayItem');
|
|
|
+ if (dataCount === 0) {
|
|
|
+ msg = b.ownerCt.emptyMsg;
|
|
|
+ } else {
|
|
|
+ msg = Ext.String.format(
|
|
|
+ b.ownerCt.displayMsg,
|
|
|
+ 1,
|
|
|
+ dataCount,
|
|
|
+ dataCount
|
|
|
+ );
|
|
|
+ }
|
|
|
+ display.setText(msg);
|
|
|
+ b.ownerCt.child('#inputItem').setValue(1);
|
|
|
+ b.ownerCt.child("#afterTextItem").setText('页,共'+dataCount+'页');
|
|
|
+ }else{
|
|
|
+ grid.selModel.noChange = true;
|
|
|
+ grid.selModel.deselectAll();
|
|
|
+ grid.selModel.select(grid.selectRecordArr);
|
|
|
+ grid.selModel.noChange = false;
|
|
|
+ grid.store.loadPage(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }],
|
|
|
+ moveFirst: function() {
|
|
|
+ if(Ext.getCmp('showSelectRecord').checked==false){
|
|
|
+ if (this.fireEvent('beforechange', this, 1) !== false) {
|
|
|
+ this.store.loadPage(1);
|
|
|
+ this.ownerCt.selModel.noChange = true;
|
|
|
+ this.ownerCt.selModel.deselectAll();
|
|
|
+ this.ownerCt.selModel.select(this.ownerCt.selectRecordArr);
|
|
|
+ this.ownerCt.selModel.noChange = false;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ movePrevious: function() {
|
|
|
+ var me = this,
|
|
|
+ store = me.store,
|
|
|
+ prev = store.currentPage - 1;
|
|
|
+ if(Ext.getCmp('showSelectRecord').checked==false){
|
|
|
+ if (prev > 0) {
|
|
|
+ if (me.fireEvent('beforechange', me, prev) !== false) {
|
|
|
+ store.previousPage();
|
|
|
+ this.ownerCt.selModel.noChange = true;
|
|
|
+ this.ownerCt.selModel.deselectAll();
|
|
|
+ this.ownerCt.selModel.select(this.ownerCt.selectRecordArr);
|
|
|
+ this.ownerCt.selModel.noChange = false;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ moveNext: function() {
|
|
|
+ var me = this,
|
|
|
+ store = me.store,
|
|
|
+ total = me.getPageData().pageCount,
|
|
|
+ next = store.currentPage + 1;
|
|
|
+ if(Ext.getCmp('showSelectRecord').checked==false){
|
|
|
+ if (next <= total) {
|
|
|
+ if (me.fireEvent('beforechange', me, next) !== false) {
|
|
|
+ store.nextPage();
|
|
|
+ this.ownerCt.selModel.noChange = true;
|
|
|
+ this.ownerCt.selModel.deselectAll();
|
|
|
+ this.ownerCt.selModel.select(this.ownerCt.selectRecordArr);
|
|
|
+ this.ownerCt.selModel.noChange = false;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ moveLast: function() {
|
|
|
+ var me = this,
|
|
|
+ last = me.getPageData().pageCount;
|
|
|
+ if(Ext.getCmp('showSelectRecord').checked==false){
|
|
|
+ if (me.fireEvent('beforechange', me, last) !== false) {
|
|
|
+ me.store.loadPage(last);
|
|
|
+ this.ownerCt.selModel.noChange = true;
|
|
|
+ this.ownerCt.selModel.deselectAll();
|
|
|
+ this.ownerCt.selModel.select(this.ownerCt.selectRecordArr);
|
|
|
+ this.ownerCt.selModel.noChange = false;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ doRefresh: function() {
|
|
|
+ var me = this,
|
|
|
+ store = me.store,
|
|
|
+ current = store.currentPage;
|
|
|
+ if(Ext.getCmp('showSelectRecord').checked==false){
|
|
|
+ if (me.fireEvent('beforechange', me, current) !== false) {
|
|
|
+ store.loadPage(current);
|
|
|
+ this.ownerCt.selModel.noChange = true;
|
|
|
+ this.ownerCt.selModel.deselectAll();
|
|
|
+ this.ownerCt.selModel.select(this.ownerCt.selectRecordArr);
|
|
|
+ this.ownerCt.selModel.noChange = false;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ updateInfo: function() {
|
|
|
+ var me = this,
|
|
|
+ displayItem = me.child('#displayItem'),
|
|
|
+ store = me.store,
|
|
|
+ pageData = me.getPageData(),
|
|
|
+ count, msg;
|
|
|
+ if (displayItem) {
|
|
|
+ count = store.getCount();
|
|
|
+ if (count === 0) {
|
|
|
+ msg = me.emptyMsg;
|
|
|
+ } else {
|
|
|
+ msg = Ext.String.format(me.displayMsg, pageData.fromRecord, pageData.toRecord, pageData.total);
|
|
|
+ }
|
|
|
+ displayItem.setText(msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }]
|
|
|
+ });
|
|
|
+ }
|
|
|
+ me.callParent(arguments);
|
|
|
+ },
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+});
|