Ext.define('saas.view.purchase.reconciliation.DataList', { extend: 'Ext.grid.Panel', xtype: 'purchase-reconciliation-datalist', controller: 'purchase-reconciliation-datalist', viewModel: 'purchase-reconciliation-datalist', autoScroll: true, frame:true, layout:'fit', dataUrl:'http://10.1.80.35:8560/api/money/apcheck/list', plugins: [{ ptype: 'cellediting', clicksToEdit: 1 }, { ptype: 'menuclipboard' }], tbar: [{ width: 280, name: 'ac_vendname', xtype: 'textfield', emptyText : '请输入供应商名称', enableKeyEvents: true, listeners: { keydown: { fn: function(th, e, eOpts) { if(e.keyCode == 13) { var grid = th.up('grid'); grid.condition = grid.getConditions(); grid.store.loadPage(1); } } } } },{ columnWidth:0.5, xtype: 'condatefield', name: 'ac_date', fieldLabel: '日期', operation: 'between' },'->',{ xtype:'button', text:'查询', listeners: { click:function(b){ var grid = b.ownerCt.ownerCt; grid.condition = grid.getConditions(); grid.store.loadPage(1); } } }], columns : [{ text : '对账单编号', width:150, dataIndex : 'ac_code', cls:'x-querygrid-code-column', renderer:function(v,style,a,b,c){ return ''+v+''; } },{ text : 'id', hidden:true, dataIndex : 'id', xtype : 'numbercolumn', },{ text : 'ac_b2bid', hidden:true, dataIndex : 'ac_b2bid', xtype : 'numbercolumn', },{ text : 'accountId', hidden:true, dataIndex : 'accountId', xtype : 'numbercolumn', },{ text : 'ac_sendstatus', hidden:true, dataIndex : 'ac_sendstatus' },{ text : '供应商编号', dataIndex : 'ac_vendcode', hidden:true },{ text : '供应商名称', dataIndex : 'ac_vendname', width:110 },{ text : '币别', width : 90.0, dataIndex : 'ac_currency', },{ text : '本期应付', dataIndex : 'ac_thisamount', xtype:'numbercolumn', width : 110.0, },{ text : '本期发货', dataIndex : 'ac_thissend', xtype:'numbercolumn', width : 110.0, },{ text : '本期未对账', dataIndex : 'ac_thisuncheck', xtype:'numbercolumn', width : 110.0, },{ text : '本期已对账', dataIndex : 'ac_thischeck', xtype:'numbercolumn', width : 110.0, },{ text : '本期已付', dataIndex : 'ac_thispay', xtype:'numbercolumn', width : 110.0, },{ text : '应付金额', dataIndex : 'ac_payamont', xtype:'numbercolumn', width : 110.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 / 32); store.setPageSize(pageSize); grid.ownerCt.el.dom.style.left = '8px'; grid.el.dom.style.padding = '0px' }, itemClick: function(tableView, record, item, index, e, eOpts) { if(e.target.classList.contains('x-query-link')) { idValue = record.get('id'), codeValue = record.get('ac_code'), id = 'purchase-reconciliation-formpanel-' + idValue; saas.util.BaseUtil.openTab('purchase-reconciliation-formpanel', "平台对账单("+codeValue+")", id, { initId: idValue }); } }, }, 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; }, /** * 获得过滤条件 */ getConditions: function() { var me = this, tbar = me.getDockedItems()[0], items = Ext.Array.filter(tbar.items.items, function(item) { return !!item.name; }), 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 type = item.fieldType || me.getDefaultFieldType(item), operation = item.operation || me.getDefaultFieldOperation(item), conditionValue = me.getConditionValue(item, value); if(!conditionValue) { continue; } condition = { type: type, field: field, operation: operation, value: conditionValue } } conditions.push(condition); } } return conditions; }, /** * 只要arr1和arr2中存在相同项即返回真 */ isContainsAny: function (arr1, arr2) { for (var i = 0; i < arr2.length; i++) { var a2 = arr2[i]; if (!!arr1.find(function (a1) { return a1 == a2 })) { return true; } } return false; }, getDefaultFieldType: function (field) { var me = this, xtypes = field.getXTypes().split('/'), type; if (me.isContainsAny(xtypes, ['numberfield'])) { type = 'number'; } else if (me.isContainsAny(xtypes, ['datefield', 'condatefield', 'conmonthfield'])) { type = 'date'; } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) { type = 'enum'; } else if (me.isContainsAny(xtypes, ['combobox', 'multicombo', 'combo', 'radiofield', 'radio'])) { type = 'enum'; } else { type = 'string'; } return type; }, getDefaultFieldOperation: function (field) { var me = this, xtypes = field.getXTypes().split('/'), operation; if (me.isContainsAny(xtypes, ['numberfield', 'datefield', 'dbfindtrigger'])) { operation = '='; } else if (me.isContainsAny(xtypes, ['condatefield', 'conmonthfield'])) { operation = 'between'; } else if (me.isContainsAny(xtypes, ['multidbfindtrigger', 'combobox', 'multicombo', 'combo'])) { operation = 'in'; } else { operation = 'like'; } return operation; }, /** * 处理部分字段值 */ getConditionValue: function (field, value) { var me = this, xtypes = field.getXTypes().split('/'), conditionValue; if (me.isContainsAny(xtypes, ['datefield'])) { conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s'); } else if (me.isContainsAny(xtypes, ['conmonthfield'])) { var from = value.from, to = value.to; conditionValue = from + ',' + to; } else if (me.isContainsAny(xtypes, ['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 (me.isContainsAny(xtypes, ['dbfindtrigger'])) { conditionValue = value; } else if (me.isContainsAny(xtypes, ['combobox', 'combo'])) { conditionValue = '\'' + value + '\''; } else if (me.isContainsAny(xtypes, ['multicombo'])) { conditionValue = value.map ? value.map(function (v) { return '\'' + v.value + '\''; }).join(',') : ''; } else { conditionValue = value; } return conditionValue; } })