73
73
<script >
74
74
import { isValidDate , isDateObejct , formatDate } from ' @/utils/index'
75
75
import locale from ' @/mixins/locale'
76
+ import emitter from ' @/mixins/emitter'
76
77
import scrollIntoView from ' @/utils/scroll-into-view'
77
78
import PanelDate from ' @/panel/date'
78
79
import PanelYear from ' @/panel/year'
@@ -82,7 +83,7 @@ import PanelTime from '@/panel/time'
82
83
export default {
83
84
name: ' CalendarPanel' ,
84
85
components: { PanelDate, PanelYear, PanelMonth, PanelTime },
85
- mixins: [locale],
86
+ mixins: [locale, emitter ],
86
87
props: {
87
88
value: {
88
89
default: null ,
@@ -203,7 +204,7 @@ export default {
203
204
},
204
205
methods: {
205
206
handelPanelChange (panel , oldPanel ) {
206
- this .$parent . $emit ( ' panel-change' , panel, oldPanel)
207
+ this .dispatch ( ' DatePicker ' , ' panel-change' , [ panel, oldPanel] )
207
208
if (panel === ' YEAR' ) {
208
209
this .firstYear = Math .floor (this .calendarYear / 10 ) * 10
209
210
} else if (panel === ' TIME' ) {
@@ -231,11 +232,13 @@ export default {
231
232
} else {
232
233
this .showPanelNone ()
233
234
}
234
- this .updateNow (this .value )
235
235
},
236
236
// 根据value更新日历
237
237
updateNow (value ) {
238
- this .now = value ? new Date (value) : new Date ()
238
+ const now = value ? new Date (value) : new Date ()
239
+ const oldNow = new Date (this .now )
240
+ this .dispatch (' DatePicker' , ' calendar-change' , [now, oldNow])
241
+ this .now = now
239
242
},
240
243
getCriticalTime (value ) {
241
244
if (! value) {
@@ -334,10 +337,10 @@ export default {
334
337
this .$emit (' select-time' , time, true )
335
338
},
336
339
changeCalendarYear (year ) {
337
- this .now = new Date (year, this .calendarMonth )
340
+ this .updateNow ( new Date (year, this .calendarMonth ) )
338
341
},
339
342
changeCalendarMonth (month ) {
340
- this .now = new Date (this .calendarYear , month)
343
+ this .updateNow ( new Date (this .calendarYear , month) )
341
344
},
342
345
getSibling () {
343
346
const calendars = this .$parent .$children .filter (v => v .$options .name === this .$options .name )
0 commit comments