| | |
| | | import { VantComponent } from '../common/component'; |
| | | import { isDef } from '../common/utils'; |
| | | import { isDef } from '../common/validator'; |
| | | import { pickerProps } from '../picker/shared'; |
| | | const currentYear = new Date().getFullYear(); |
| | | function isValidDate(date) { |
| | |
| | | return result; |
| | | } |
| | | function getTrueValue(formattedValue) { |
| | | if (!formattedValue) return; |
| | | if (formattedValue === undefined) { |
| | | formattedValue = '1'; |
| | | } |
| | | while (isNaN(parseInt(formattedValue, 10))) { |
| | | formattedValue = formattedValue.slice(1); |
| | | } |
| | |
| | | function getMonthEndDay(year, month) { |
| | | return 32 - new Date(year, month - 1, 32).getDate(); |
| | | } |
| | | const defaultFormatter = (_, value) => value; |
| | | const defaultFormatter = (type, value) => value; |
| | | VantComponent({ |
| | | classes: ['active-class', 'toolbar-class', 'column-class'], |
| | | props: Object.assign(Object.assign({}, pickerProps), { |
| | |
| | | methods: { |
| | | updateValue() { |
| | | const { data } = this; |
| | | const val = this.correctValue(this.data.value); |
| | | const val = this.correctValue(data.value); |
| | | const isEqual = val === data.innerValue; |
| | | if (!isEqual) { |
| | | this.updateColumnValue(val).then(() => { |
| | |
| | | const { data } = this; |
| | | let value; |
| | | const picker = this.getPicker(); |
| | | const originColumns = this.getOriginColumns(); |
| | | if (data.type === 'time') { |
| | | const indexes = picker.getIndexes(); |
| | | value = `${+data.columns[0].values[indexes[0]]}:${+data.columns[1] |
| | | value = `${+originColumns[0].values[indexes[0]]}:${+originColumns[1] |
| | | .values[indexes[1]]}`; |
| | | } else { |
| | | const values = picker.getValues(); |
| | | const indexes = picker.getIndexes(); |
| | | const values = indexes.map( |
| | | (value, index) => originColumns[index].values[value] |
| | | ); |
| | | const year = getTrueValue(values[0]); |
| | | const month = getTrueValue(values[1]); |
| | | const maxDate = getMonthEndDay(year, month); |
| | |
| | | }, |
| | | updateColumnValue(value) { |
| | | let values = []; |
| | | const { type, formatter = defaultFormatter } = this.data; |
| | | const { type } = this.data; |
| | | const formatter = this.data.formatter || defaultFormatter; |
| | | const picker = this.getPicker(); |
| | | if (type === 'time') { |
| | | const pair = value.split(':'); |