[bugfix] DatetimePicker: incorrect value when use formatter (#2059)

This commit is contained in:
neverland 2018-11-09 20:18:57 +08:00 committed by GitHub
parent f272f661b3
commit d1cad717f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,7 +30,7 @@ export default create({
}, },
props: { props: {
value: {}, value: null,
title: String, title: String,
itemHeight: Number, itemHeight: Number,
visibleItemCount: Number, visibleItemCount: Number,
@ -264,12 +264,13 @@ export default create({
}, },
onChange(picker) { onChange(picker) {
const values = picker.getValues();
let value; let value;
if (this.type === 'time') { if (this.type === 'time') {
value = values.join(':'); const indexes = picker.getIndexes();
value = `${indexes[0] + this.minHour}:${indexes[1] + this.minMinute}`;
} else { } else {
const values = picker.getValues();
const year = this.getTrueValue(values[0]); const year = this.getTrueValue(values[0]);
const month = this.getTrueValue(values[1]); const month = this.getTrueValue(values[1]);
const maxDate = this.getMonthEndDay(year, month); const maxDate = this.getMonthEndDay(year, month);
@ -284,10 +285,11 @@ export default create({
hour = this.getTrueValue(values[3]); hour = this.getTrueValue(values[3]);
minute = this.getTrueValue(values[4]); minute = this.getTrueValue(values[4]);
} }
value = new Date(year, month - 1, date, hour, minute); value = new Date(year, month - 1, date, hour, minute);
} }
value = this.correctValue(value);
this.innerValue = value; this.innerValue = this.correctValue(value);
this.$nextTick(() => { this.$nextTick(() => {
this.$nextTick(() => { this.$nextTick(() => {
@ -301,10 +303,10 @@ export default create({
const { formatter, pad } = this; const { formatter, pad } = this;
if (this.type === 'time') { if (this.type === 'time') {
const currentValue = value.split(':'); const pair = value.split(':');
values = [ values = [
formatter('hour', currentValue[0]), formatter('hour', pair[0]),
formatter('minute', currentValue[1]) formatter('minute', pair[1])
]; ];
} else { } else {
values = [ values = [