/** * Created by zhouy on 2018/10/18. */ Ext.define('saas.view.sys.account.DataList', { extend: 'Ext.grid.Panel', xtype: 'sys-account-datalist', controller: 'sys-account-datalist', viewModel: 'sys-account-datalist', autoScroll: true, frame:true, layout:'fit', dataUrl:'/api/account/account/accountRole/list', _openUrl:'/api/account/account/enable', _closeUrl:'/api/account/account/disable', tbar: [{ width: 150, name: 'username', xtype: 'textfield', emptyText : '账户名称' },{ width: 110, name: 'mobile', xtype: 'textfield', emptyText : '电话' },{ xtype:'button', text:'查询', listeners: { click:function(b){ var grid = b.ownerCt.ownerCt; var tbar = b.ownerCt; grid.condition = ''; var items = []; var fields = tbar.items.items.map(f => f.name); Ext.each(fields, function(f, index){ var field = tbar.down('[name='+f+']'); if(field){ items.push(field); } }); grid.condition = grid.getCondition(items); grid.store.loadPage(1); } } },'->',{ xtype:'button', text:'新增', listeners: { click: 'onAdd' } },{ xtype:'button', text:'刷新', listeners: { click: 'onRefresh' } }], columns : [{ text : 'id', hidden:true, dataIndex : 'id', xtype : 'numbercolumn', },{ text : 'accountId', hidden:true, dataIndex : 'accountId', xtype : 'numbercolumn', },{ text : '账户名称', width : 200.0, dataIndex : 'username', xtype : '', }, { text : '真实姓名', dataIndex : 'realname', width : 110.0, xtype : '', }, { text : '联系电话', dataIndex : 'mobile', width : 110.0, },{ text : '联系邮箱', dataIndex : 'email', width : 180.0, xtype : '', },{ text : '关联角色id', hidden:true, dataIndex : 'roleIds', width : 110.0, xtype : '', },{ text : '关联角色', dataIndex : 'roleNames', width : 220.0 },{ text: '账户状态', dataIndex: 'enabled', width:90, xtype: 'actioncolumn', align : 'center', items: [{ iconCls:'', getClass: function(v, meta, rec) { if(rec.get('enabled')){ return 'x-grid-checkcolumn-checked-btn'; }else{ return 'x-grid-checkcolumn-btn'; } }, handler: function(view, rowIndex, colIndex) { var rec = view.getStore().getAt(rowIndex); var type=rec.get('enabled'); // 禁用/启用 var grid = this.ownerCt.ownerCt; var params = { accountId:rec.get('id') }; saas.util.BaseUtil.request({ url: (!type?grid._openUrl:grid._closeUrl), params: params, method: 'POST', headers : { 'Access-Control-Allow-Origin': '*', "Content-Type":'application/x-www-form-urlencoded' } }) .then(function(localJson) { if(localJson.success){ saas.util.BaseUtil.showSuccessToast('操作成功'); grid.store.load(); } }) .catch(function(res) { console.error(res); saas.util.BaseUtil.showErrorToast('操作失败: ' + res.message); }); } }] }], dbSearchFields: [], condition:'', initComponent: function() { var me = this; if(me.columns){ var fields = me.columns.map(column => column.dataIndex); me.columns = me.insertFirstColumn(me.columns); me.store = Ext.create('Ext.data.Store',{ fields:fields, autoLoad: true, pageSize: 11, data: [], proxy: { timeout:8000, type: 'ajax', url: me.dataUrl, actionMethods: { read: 'GET' }, reader: { type: 'json', rootProperty: 'data.list', totalProperty: 'data.total', } }, listeners: { beforeload: function (store, op) { var condition = me.condition; if (Ext.isEmpty(condition)) { condition = ''; } Ext.apply(store.proxy.extraParams, { number: op._page, size: store.pageSize, condition: JSON.stringify(condition) }); } } }); Ext.apply(me, { dockedItems:[{ xtype: 'pagingtoolbar', dock: 'bottom', displayInfo: true, store: me.store }] }); } me.callParent(arguments); }, onVastDeal:function(url,type){ var form = this.ownerCt; var grid = this; var data = grid.getGridSelected(type); if(!data){ saas.util.BaseUtil.showErrorToast('请勾选符合条件的行进行操作。'); return false; } if(data&&data.length>0){ var params = JSON.stringify({baseDTOs:data}); saas.util.BaseUtil.request({ url: url, params: params, method: 'POST', async:false }) .then(function() { saas.util.BaseUtil.showSuccessToast('操作成功'); grid.store.load(); }) .catch(function(response) { saas.util.BaseUtil.showErrorToast('操作失败'); }); }else{ saas.util.BaseUtil.showErrorToast('请勾选至少一条明细。'); } }, listeners:{ boxready: function(grid, width, height, eOpts) { var store = grid.getStore(), gridBodyBox = grid.body.dom.getBoundingClientRect(), gridBodyBoxHeight = gridBodyBox.height; var pageSize = Math.floor(gridBodyBoxHeight / 32); store.setPageSize(pageSize); }, itemClick: function(view,record,a,index,c) { var classList = c.target.classList.value; var grid = this; if(classList.indexOf('fa-pencil')>-1){ var document = Ext.create('saas.view.document.kind.Kind',{}); var form = this.ownerCt; this.dialog = this.getController().getView().add({ xtype: 'document-kind-childwin', bind: { title: '修改账户信息' }, dataKind:'accountinformation', belong:document.etc['accountinformation'], _parent:this, record:record, session: true }); this.dialog.show(); } } }, insertFirstColumn:function(columns){ var me=this; if(columns.length>0 && columns[0].xtype!='actioncolumn'){ return Ext.Array.insert(columns,0,[{ xtype:'actioncolumn', width:50, dataIndex:'actioncolumn', text:'操作', items: [{ tooltip: '编辑', iconCls: 'x-fa fa-pencil fa-fw', scope:this }] }]); } return columns; }, getGridSelected:function(type){ var isErrorSelect = false; var checkField = this.statusCodeField; var me = this, items = me.selModel.getSelection(), data = new Array() ; Ext.each(items, function(item, index){ if(!Ext.isEmpty(item.data[me.idField])){ var o = new Object(); if(me.idField){ o['id'] = item.data[me.idField]; } if(me.codeField){ o['code'] = item.data[me.codeField]; } if(type&&type==item.data[checkField]){ isErrorSelect = true } data.push(o); } }); if(isErrorSelect){ return false; } return data; }, /** * 获得过滤条件 */ 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(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; }, refresh:function(){ //debugger } })