Browse Source

ConMonthField

zhuth 7 years ago
parent
commit
6e2c89622c

+ 81 - 0
frontend/saas-web/app/view/core/form/field/ConMonthField.js

@@ -0,0 +1,81 @@
+Ext.define('saas.view.core.form.field.ConMonthField', {
+    extend: 'Ext.form.FieldContainer',
+    alias: 'widget.conmonthfield',
+
+    layout: 'hbox',
+    items: [],
+    defaults: {
+        margin: '0 0 0 0'
+    },
+    columnWidth: 0.5,
+    defaultBindProperty: 'value',
+
+    combineErrors: true,
+
+    cls: 'x-conmonthfield',
+
+    initComponent : function(){
+        this.callParent(arguments);
+        var me = this, allowBlank = (Ext.isDefined(me.allowBlank) ? me.allowBlank : true);
+        me.from = me.insert(0, {
+            xtype: 'monthdatefield',
+            listeners: {
+                beforeChange: me.beforeFromChange,
+                change: me.fromChange
+            }
+        });
+        me.to = me.insert(1, {
+            xtype: 'monthdatefield',
+            listeners: {
+                beforeChange: me.beforeToChange,
+                change: me.toChange
+            }
+        });
+    },
+
+    setValue: function(value) {
+        this.value = value;
+        this.publishState('value', this.value);
+    },
+
+    beforeFromChange: function(picker, value) {
+        var container = picker.ownerCt,
+        toField = container.to,
+        toValue = toField.value;
+
+        if(Number(value) > Number(toValue)) {
+            toField.setValue('');
+        }
+        return true;
+    },
+
+    fromChange: function(picker, newValue, oldValue) {
+        var container = picker.ownerCt,
+        toField = container.to;
+        container.setValue({
+            from: newValue,
+            to: toField.value
+        });
+    },
+
+    beforeToChange: function(picker, value) {
+        var container = picker.ownerCt,
+        fromField = container.from,
+        fromValue = fromField.value;
+
+        if(Number(value) <= Number(fromValue)) {
+            return false;
+        }else {
+            return true;
+        }
+    },
+
+    toChange: function(picker, newValue, oldValue) {
+        var container = picker.ownerCt,
+        fromField = container.from;
+        container.setValue({
+            from: fromField.value,
+            to: newValue
+        });
+    }
+});

+ 12 - 9
frontend/saas-web/app/view/core/form/field/Month.js

@@ -80,25 +80,32 @@ Ext.define('saas.view.core.form.field.Month', {
             month = Number(month) + 1;
             month = month < 10 ? '0' + month : month;
             year = year == null ? new Date().getFullYear() : year;
+
+            var v = year + '' + month;
             if (this.minValue) {
-                if (Number(year + '' + month) < this.minYearMonth) {
+                if (Number(v) < this.minYearMonth) {
                     return;
                 }
             }
             if (this.maxValue) {
-                if (Number(year + '' + month) > this.maxYearMonth) {
+                if (Number(v) > this.maxYearMonth) {
                     return;
                 }
             }
-            this.setValue(year + '' + month);
+            if(!this.fireEvent('beforeChange', this, v)) {
+                this.monthPicker.hide();
+                return;
+            }
+            this.setValue(v);
+            this.fireEvent('select', this, v);
         }
-        me.onSelect();
+        this.monthPicker.hide();
     },
     getCurrentVal:function(){
         return Ext.Date.format(new Date(),this.format);
     },
     onCancelClick: function() {
-        this.onSelect();
+        this.monthPicker.hide();
     },
     getPickerValues:function() {
         var val = this.value, year, month;
@@ -118,8 +125,4 @@ Ext.define('saas.view.core.form.field.Month', {
         }
         this.callParent(arguments);
     },
-    onSelect: function() {
-        this.monthPicker.hide();
-    }
-
 });

+ 15 - 2
frontend/saas-web/app/view/core/report/ReportPanel.js

@@ -501,6 +501,10 @@ Ext.define('saas.view.core.report.ReportPanel', {
             conditions.push(condition);
         }
 
+        return me.myGetConditions(conditions);
+    },
+
+    myGetConditions: function(conditions) {
         return conditions;
     },
 
@@ -511,7 +515,7 @@ Ext.define('saas.view.core.report.ReportPanel', {
 
         if(me.isContainsAny(xtypes, ['numberfield'])) {
             type = 'number';
-        }else if(me.isContainsAny(xtypes, ['datefield', 'condatefield'])) {
+        }else if(me.isContainsAny(xtypes, ['datefield', 'condatefield', 'conmonthfield'])) {
             type = 'date';
         }else if(me.isContainsAny(xtypes, ['dbfindtrigger'])) {
             type = 'string';
@@ -544,7 +548,7 @@ Ext.define('saas.view.core.report.ReportPanel', {
 
         if(me.isContainsAny(xtypes, ['numberfield', 'datefield', 'dbfindtrigger'])) {
             operation = '=';
-        }else if(me.isContainsAny(xtypes, ['condatefield'])) {
+        }else if(me.isContainsAny(xtypes, ['condatefield', 'conmonthfield'])) {
             operation = 'between';
         }else if(me.isContainsAny(xtypes, ['multidbfindtrigger', 'combobox', 'multicombo', 'combo'])) {
             operation = 'in';
@@ -564,6 +568,15 @@ Ext.define('saas.view.core.report.ReportPanel', {
         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,
+            fy = Math.floor(Number(from)/100),
+            fm = Math.floor(Number(from)%100),
+            ty = Math.floor(Number(to)/100),
+            tm = Math.floor(Number(to)%100);
+
+            conditionValue = Ext.Date.format(new Date(fy+'/'+fm), 'Y-m-d 00:00:00') + ',' + Ext.Date.format(new Date(ty+'/'+tm), 'Y-m-d 23:59:59');
         }else if(me.isContainsAny(xtypes, ['condatefield'])) {
             var from = value.from,
             to = value.to;

+ 3 - 8
frontend/saas-web/app/view/money/report/TotalPayDetail.js

@@ -25,15 +25,10 @@ Ext.define('saas.view.money.report.TotalPayDetail', {
             return "(upper(vm_vendcode) like '%"+v.toUpperCase()+"%' or upper(vm_vendname) like '%"+v.toUpperCase()+"%')";
         },
     }, {
-        xtype: 'monthdatefield',
+        xtype: 'conmonthfield',
+        fieldLabel: '期间',
         name: 'vm_yearmonth',
-        fieldLabel: '起始期间',
-        columnWidth: 0.2
-    }, {
-        xtype: 'monthdatefield',
-        name: 'vm_yearmonthTo',
-        fieldLabel: '结束期间',
-        columnWidth: 0.2
+        columnWidth: 0.4
     }],
 
     reportColumns: [{

+ 3 - 8
frontend/saas-web/app/view/money/report/TotalRecDetail.js

@@ -25,15 +25,10 @@ Ext.define('saas.view.money.report.TotalRecDetail', {
             return "(upper(cm_custcode) like '%" + v.toUpperCase() + "%' or upper(cm_custname) like '%" + v.toUpperCase() + "%')";
         },
     }, {
-        xtype: 'monthdatefield',
+        xtype: 'conmonthfield',
+        fieldLabel: '期间',
         name: 'cm_yearmonth',
-        fieldLabel: '起始期间',
-        columnWidth: 0.2
-    }, {
-        xtype: 'monthdatefield',
-        name: 'cm_yearmonthTo',
-        fieldLabel: '结束期间',
-        columnWidth: 0.2
+        columnWidth: 0.4
     }],
 
     reportColumns: [{