From 73a34dfab5590ce73df021114bebeaf01b21273e Mon Sep 17 00:00:00 2001 From: Sergio Crisostomo Date: Wed, 31 Jan 2018 12:14:11 +0100 Subject: [PATCH] Fix year/month pre-selection --- src/components/date-picker/panel/Date/date-range.vue | 27 ++++++++++++++++++++++----- src/components/date-picker/panel/Date/date.vue | 10 +++++++--- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/components/date-picker/panel/Date/date-range.vue b/src/components/date-picker/panel/Date/date-range.vue index 005dc62..5ff78ca 100644 --- a/src/components/date-picker/panel/Date/date-range.vue +++ b/src/components/date-picker/panel/Date/date-range.vue @@ -13,15 +13,16 @@ :class="iconBtnCls('prev', '-double')" @click="prevYear('left')">
@@ -169,6 +171,12 @@ rightDatePanelLabel(){ return this.panelLabelConfig('right'); }, + leftDatePanelView(){ + return this.leftPickerTable.split('-').shift(); + }, + rightDatePanelView(){ + return this.rightPickerTable.split('-').shift(); + }, timeDisabled(){ return !(this.dates[0] && this.dates[1]); }, @@ -287,7 +295,16 @@ }, handlePreSelection(panel, value){ this[`${panel}PanelDate`] = value; - this[`${panel}PickerTable`] = `${this.currentView}-table`; + const currentViewType = this[`${panel}PickerTable`]; + if (currentViewType === 'year-table') this[`${panel}PickerTable`] = 'month-table'; + else this[`${panel}PickerTable`] = `${this.currentView}-table`; + + if (!this.splitPanels){ + const otherPanel = panel === 'left' ? 'right' : 'left'; + const type = currentViewType === 'year-table' ? 'FullYear' : 'Month'; + this[`${otherPanel}PanelDate`] = value; + this.changePanelDate(otherPanel, type, 1); + } }, handleRangePick (val) { if (this.rangeState.selecting || this.currentView === 'time'){ diff --git a/src/components/date-picker/panel/Date/date.vue b/src/components/date-picker/panel/Date/date.vue index 10912f7..7cf9775 100644 --- a/src/components/date-picker/panel/Date/date.vue +++ b/src/components/date-picker/panel/Date/date.vue @@ -12,17 +12,19 @@ :class="iconBtnCls('prev', '-double')" @click="changeYear(-1)"> @@ -155,7 +157,7 @@ this.pickerTable = this.getTableType(this.currentView); }, changeYear(dir){ - if (this.selectionMode === 'year'){ + if (this.selectionMode === 'year' || this.pickerTable === 'year-table'){ this.panelDate = new Date(this.panelDate.getFullYear() + dir * 10, 0, 1); } else { this.panelDate = siblingMonth(this.panelDate, dir * 12); @@ -169,7 +171,9 @@ }, handlePreSelection(value){ this.panelDate = value; - this.pickerTable = this.getTableType(this.currentView); + if (this.pickerTable === 'year-table') this.pickerTable = 'month-table'; + else this.pickerTable = this.getTableType(this.currentView); + }, handlePick (value) { const {selectionMode, panelDate} = this; -- libgit2 0.21.4