/** * Created by zhouy on 2018/10/18. */ Ext.define('saas.view.sys.invitation.DataList', { extend: 'Ext.grid.Panel', xtype: 'sys-invitation-datalist', controller: 'sys-invitation-datalist', viewModel: 'sys-invitation-datalist', autoScroll: true, frame:true, layout:'fit', dataUrl:'/api/commons/remind/apply/list', plugins: [{ ptype: 'cellediting', clicksToEdit: 1 }], tbar: [{ width: 110, name: 'username', xtype: 'textfield', emptyText : '姓名' },{ width: 140, name: 're_status', emptyText : '批准状态', xtype: 'combobox', queryMode: 'local', displayField: 'display', valueField: 'value', editable:false, store: Ext.create('Ext.data.ArrayStore', { fields: ['display', 'value'], data: [ ["全部", "ALL"], ["待批准", "2"], ["已批准", "1"], ["未批准", "0"] ] }), getCondition: function(value) { if(value == 'ALL') { return '1=1'; }else { return 're_status=\'' + value + '\''; } } },{ 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: 'onRefresh' } }], columns : [{ text : '操作', dataIndex : 'status', width:110, renderer:function(v,atr,rec,index){ var grid = this; if(typeof(window.showWin)!='function'){ window.showWin = function(x){ var record = grid.store.getAt(x); grid.dialog = grid.add({ xtype: 'sys-invitation-editwindow', bind: { title: '批准信息' }, _parent:grid, record:record, session: true }); grid.dialog.show(); } } if(typeof(window.disagree)!='function'){ window.disagree = function(x){ grid.setLoading(true); var record = grid.store.getAt(x); var _params = { id:Number(record.get('id')), status:0 }; saas.util.BaseUtil.request({ url: '/api/commons/remind/apply/confirm', params: JSON.stringify(_params), method: 'POST', }) .then(function(localJson) { grid.setLoading(false); if(localJson.success){ saas.util.BaseUtil.showSuccessToast('保存成功'); grid.store.load(); } }) .catch(function(res) { grid.setLoading(false); console.error(res); saas.util.BaseUtil.showErrorToast('保存失败: ' + res.message); }); } } if(v&&v!=''){ if(v=='2'){ return ""+" | "+ ""; }else if(v=='1'){ return '已批准'; }else if(v=='0'){ return '未批准' } } return v; } },{ text : 'id', hidden:true, dataIndex : 'id', xtype : 'numbercolumn', },{ text : 'accountId', hidden:true, dataIndex : 'accountId', xtype : 'numbercolumn', },{ text : '姓名', width : 90.0, dataIndex : 'username', },{ text : '手机号码', dataIndex : 'mobile', width : 150.0, },{ text : '岗位角色id', hidden:true, dataIndex : 'roles' },{ text : '岗位角色', dataIndex : 'roleNames', width : 220.0, }], dbSearchFields: [], condition:'', initComponent: function() { var me = this; if(me.columns){ var fields = me.columns.map(column => column.dataIndex); 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: { exception: function(proxy, response, operation, eOpts) { if(operation.success) { if(response.timedout) { saas.util.BaseUtil.showErrorToast('请求超时'); } }else { if(response.timedout) { saas.util.BaseUtil.showErrorToast('请求超时'); }else{ if(proxy.showPowerMessage){ saas.util.BaseUtil.showErrorToast('查询失败:' + response.responseJson?response.responseJson.message:'请求超时'); } } } } } }, 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); }, listeners:{ boxready: function(grid, width, height, eOpts) { var store = grid.getStore(), gridBodyBox = grid.body.dom.getBoundingClientRect(), gridBodyBoxHeight = gridBodyBox.height; var pageSize = Math.floor(gridBodyBoxHeight / 35); store.setPageSize(pageSize); } }, 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(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; }, refresh:function(){ this.store.load() } })