zhuguifei
2026-03-10 2c1fd10c6fbabb8e9f0e9f07fe66fb36c008e883
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/**
    @name Edo.controls.Date
    @class
    @typeName date
    @description 日期输入框
    @extend Edo.controls.Trigger
*/
Edo.controls.Date = function(config){    
    /**
        @name Edo.controls.Date#beforedatechange
        @event
        @description 日期改变事件                
        @property {Date} date 日期值
    */
    /**
        @name Edo.controls.Date#datechange
        @event
        @description 日期改变事件                
        @property {Date} date 日期值
    */
 
    Edo.controls.Date.superclass.constructor.call(this);    
    //this.date = new Date();
};
Edo.controls.Date.extend(Edo.controls.Trigger,{
    /**        
        @name Edo.controls.Date#enableResizePopup
        @property
        @default false
    */  
    enableResizePopup: false,
    /**        
        @name Edo.controls.Date#valueField
        @property
        @default date
    */
    valueField: 'date',
    /**        
        @name Edo.controls.Date#popupWidth
        @property
        @default 178
    */
    popupWidth: 178,
    /**        
        @name Edo.controls.Date#popupHeight
        @property
        @default auto
    */
    popupHeight: 'auto',
    /**        
        @name Edo.controls.Date#popupType
        @property
        @default ct
    */
    popupType: 'ct',
    /**        
        @name Edo.controls.Date#triggerPopup
        @property
        @default true
    */
    triggerPopup: true,
    
    
    
    /**
        @name Edo.controls.Date#format
        @property
        @type String
        @description 格式化显示日期字符串,显示在text上
    */    
    format: 'Y-m-d',
    /**
        @name Edo.controls.Date#inputFormat
        @property
        @type String
        @description 如果输入日期字符串,则用此格式化器得到日期对象
    */
    inputFormat: 'Y-m-dTH:i:s',
    /**
        @name Edo.controls.Date#date
        @property
        @type Date
        @description 日期,默认是今天
    */    
    
    elCls: 'e-text e-date',
    
    enableTime: true,
    
    datepickerClass: 'datepicker',
    
    valueFormat: false,
    
    getValue: function(){
        var v = Edo.controls.DatePicker.superclass.getValue.call(this);
        if(v && this.valueFormat) v = v.format(this.format);
        return v;
    },
    
    convertDate : function(date){
        var v = date;
        if(!Edo.isDate(date)) {
            date = Date.parseDate(v, this.inputFormat);
            if(!Edo.isDate(date)) date = Date.parseDate(v, this.format);
        }
        return date;
    },
    /**
        @name Edo.controls.Date#required
        @property
        @type Boolean
        @default true
        @description 是否不能为空
    */   
    required: true,
    _setRequired: function(v){
        if(this.required != v){
            this.required = v;
            if(this.datePicker){
               this.datePicker.set('required', v); 
            }
        }
    },
    _setDate: function(value){    
    //if(this.id == 'birthday') debugger
        value = this.convertDate(value);
        if(!Edo.isValue(value)) {
            value = null;
            if(this.required) return false;
        }
        
        if(this.date != value){
        
            if(this.fireEvent('beforedatechange', {
                type: 'beforedatechange',
                source: this,
                date: value
            }) == false) return;
        
            this.date = value;
            
            this._setText(value ? value.format(this.format) : '');
            
            this.changeProperty('date', value);
            
            this.fireEvent('datechange', {
                type: 'datechange',
                target: this,
                date: this.date
            });
        }
    },
    _dateChangeHandler: function(e){    
        if(this.datePicker && this.datePicker.created){
            this._setDate(e.date);
            this.hidePopup();
            this.focus();
        }
    },
    within: function(e){      //传递一个事件对象,判断是否在此控件的点击区域内.
    
        var r = false;
        if(this.datePicker) r = this.datePicker.within(e);      //datePicker有一些下拉框是脱离这个环境的
        return Edo.controls.Date.superclass.within.call(this, e) || r;
    },
    createPopup: function(){ 
    
        Edo.controls.Date.superclass.createPopup.apply(this, arguments);        
        
        if(!this.datePicker){
            this.datePicker = Edo.build({                
                type: this.datepickerClass,                
                width: '100%',
                height: '100%',
                date: this.date,
                required: this.required,
                onDatechange: this._dateChangeHandler.bind(this)                
            });
            
            this.popupCt.addChild(this.datePicker);
            
            //this.popupCt.doLayout();
        }else{
            this.datePicker.set('date', this.date);
        }
    },
    _onTextChange: function(e){   
        
        Edo.controls.Date.superclass._onTextChange.c(this, e);        
        
        this._setDate(this.text);        
    }
});
Edo.controls.Date.regType('date');