123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- Ext.define('saas.view.core.base.BasePanel', {
- extend: 'Ext.form.Panel',
- xtype: 'core-base-basepanel',
-
- controller: 'core-base-basepanel',
- viewModel: 'core-base-basepanel',
- cls:'core-base-basepanel',
- //基础属性
- frame:false,
- autoScroll: true,
- border: 0,
- bodyPadding: 0,
- layout: 'fit',
-
- fieldDefaults: {
- margin: '0 5 5 0',
- labelAlign: 'right',
- labelWidth: 90,
- columnWidth: 0.25,
- blankText: '该字段不能为空'
- },
-
- searchField:[],
- gridColumns: [],
- deleteMoreMsg: '确认删除所选单据?',
- deleteOneMsg: '确认删除该单据?',
- initComponent: function() {
- var me = this,
- gridConfig = me.gridConfig,
- gridColumns = Ext.Array.clone(gridConfig.columns);
- var gridcfg = {
- layout: 'fit',
- xtype: 'core-base-gridpanel',
- padding: '8 12',
- _columns: gridColumns.map(function(c) {
- return Object.assign({}, c);
- }),
- };
- Ext.apply(gridcfg ,me.gridConfig);
- Ext.apply(me, {
- dockedItems: [{
- frame:false,
- xtype: 'toolbar',
- dock: 'top',
- layout: 'column',
- style: {
- margin: '0 0 12px 0',
- padding: '10px 0 14px 8px',
- },
- items: me.searchField.concat([{
- xtype: 'button',
- text: '查询',
- handler: function() {
- me.onQuery()
- }
- }])
- }],
- items: [gridcfg]
- });
- me.callParent(arguments);
- },
- listeners: {
- beforerender: function(form) {
- var items = form.dockedItems.items[0].items.items,
- searchField = form.searchField;
- Ext.Array.each(searchField, function(f) {
- var name = f.name;
- var field = form.getForm().findField(name);
- if(field) {
- field.enableKeyEvents = true;
- field.on && field.on({
- keydown: {
- fn: function(th, e, eOpts) {
- if(e.keyCode == 13) {
- form.onQuery()
- }
- }
- }
- });
- }
- });
- }
- },
- onQuery: function() {
- var me = this;
- var grid = me.down('core-base-gridpanel');
-
- grid.store.loadPage(1);
- },
- /**
- * 获得过滤条件
- */
- getConditions: function() {
- var me = this;
- var items = me.dockedItems.items[0].items.items;
- var 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(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;
- if(from && 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;
- },
- getExtraParams: function(store, op, condition) {
- return {
- number: store.exportNumber?store.exportNumber:op._page,
- size: store.exportPageSize?store.exportPageSize:store.pageSize,
- condition: JSON.stringify(condition)
- };
- },
- refresh: function () {
- this.items.items[0].store.load()
- },
- refreshViewConfig: function() {
- var me = this;
- var grid = me.items.items[0];
- grid.refreshColumns();
- }
- });
|