Ext.define('saas.view.document.uusetting.UUSetting', { extend: 'Ext.panel.Panel', xtype: 'document-uusetting', autoScroll: true, layout:'fit', controller:'document-uusetting', viewModel: { type: 'document-uusetting' }, defaultType:'vendorkind', requires: [ 'Ext.button.Segmented' ], etc:{ common: { columns: [{ xtype:'actioncolumn', text:'操作', align: 'center', items: [{ xtype: 'button', tooltip: 'UU设置', iconCls: 'x-sa sa-setting', handler: 'onUUSetting' }] }] }, vendorkind:{ columns: [{ text: '供应商编号', dataIndex: 've_code', width: 120 }, { text: '供应商名称', dataIndex: 've_name', width: 200 }, { text: '状态', dataIndex: 've_status', width: 80, align: 'center' }, { text: '类型', dataIndex: 've_type', width: 100, align: 'center' }, { text: '采购员', dataIndex: 've_buyername', width: 120, }, { text: '供应商UU', dataIndex: 've_uu', width: 120 }], }, customerkind:{ columns: [{ text: '客户编号', dataIndex: 'cu_code', width: 120 }, { text: '客户名称', dataIndex: 'cu_name', width: 200 }, { text: '状态', dataIndex: 'cu_status', width: 80, align: 'center' }, { text: '类型', dataIndex: 'cu_type', width: 100, align: 'center' }, { text: '业务员', dataIndex: 'cu_sellername', width: 120, }, { text: '客户UU', dataIndex: 'cu_uu', width: 120 }], } }, initComponent: function() { var me = this; Ext.apply(me, { dockedItems: [{ xtype: 'toolbar', dock: 'top', padding: '12 5 0 12', items: [{ xtype: 'segmentedbutton', reference: 'dataKind', value: 'vendorkind', name : 'segmentedbutton', items: [{ name:'vendorkind', text: '供应商', value: 'vendorkind', }, { name:'customerkind', text: '客户', value: 'customerkind', }], listeners: { toggle: 'onToggle' } }, '->', { xtype: 'textfield', name: 'vendorkind', hidden: false, emptyText: '输入供应商编号或名称', getCondition: function(value) { return ' (ve_code like\'%' + value + '%\' or ve_name like \'%'+value+'%\' ) '; }, enableKeyEvents: true, listeners: { keydown: function(th, e, eOpts) { if(e.keyCode == 13) { me.getController().onQuery(); } } } }, { xtype: 'textfield', name: 'customerkind', hidden: true, emptyText: '输入客户编号或名称', getCondition: function(value) { return ' (cu_code like\'%' + value + '%\' or cu_name like \'%'+value+'%\' ) '; }, enableKeyEvents: true, listeners: { keydown: function(th, e, eOpts) { if(e.keyCode == 13) { me.getController().onQuery(); } } } }, { xtype: 'button', text: '查询', handler: 'onQuery' }] }], items:[{ xtype:'grid', margin: 12, flex: 1, border: 1, plugins: [{ ptype: 'menuclipboard' }], dockedItems: [{ xtype: 'pagingtoolbar', dock: 'bottom', cls:'x-basepanel-pagingtoolbar', displayInfo: true, bind: { store: '{vendorkind}', } }], listeners:{ boxready: 'onBoxReady', render:'loadDefualt' } }], }); me.callParent(arguments); }, /** * 获得过滤条件 */ getConditions: function() { var me = this, items = me.dockedItems.items[0].query('[xtype=textfield]'), conditions = []; for(let i = 0; i < items.length; i++) { var item = items[i]; var field = item.name, func = item.getCondition, value = item.value, condition; if(!item.isVisible()) { continue; } if(value !== undefined && value !== null && 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 === undefined && conditionValue === null && 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; }, refresh: function() { var store = this.down('grid').store; store.load(); } })