| | |
| | | getDayByOffset, |
| | | } from './utils'; |
| | | import Toast from '../toast/toast'; |
| | | import { requestAnimationFrame } from '../common/utils'; |
| | | VantComponent({ |
| | | props: { |
| | | title: { |
| | |
| | | }, |
| | | rangePrompt: String, |
| | | defaultDate: { |
| | | type: [Number, Array], |
| | | type: null, |
| | | observer(val) { |
| | | this.setData({ currentDate: val }); |
| | | this.scrollIntoView(); |
| | |
| | | value: 'bottom', |
| | | }, |
| | | rowHeight: { |
| | | type: [Number, String], |
| | | type: null, |
| | | value: ROW_HEIGHT, |
| | | }, |
| | | round: { |
| | |
| | | value: true, |
| | | }, |
| | | maxRange: { |
| | | type: [Number, String], |
| | | type: null, |
| | | value: null, |
| | | }, |
| | | }, |
| | |
| | | ]; |
| | | } |
| | | if (type === 'multiple') { |
| | | return [defaultDate || minDate]; |
| | | return defaultDate || [minDate]; |
| | | } |
| | | return defaultDate || minDate; |
| | | }, |
| | | scrollIntoView() { |
| | | setTimeout(() => { |
| | | requestAnimationFrame(() => { |
| | | const { |
| | | currentDate, |
| | | type, |
| | |
| | | minDate, |
| | | maxDate, |
| | | } = this.data; |
| | | // @ts-ignore |
| | | const targetDate = type === 'single' ? currentDate : currentDate[0]; |
| | | const displayed = show || !poppable; |
| | | if (!targetDate || !displayed) { |
| | |
| | | } |
| | | return false; |
| | | }); |
| | | }, 100); |
| | | }); |
| | | }, |
| | | onOpen() { |
| | | this.$emit('open'); |
| | |
| | | const { date } = event.detail; |
| | | const { type, currentDate, allowSameDay } = this.data; |
| | | if (type === 'range') { |
| | | // @ts-ignore |
| | | const [startDay, endDay] = currentDate; |
| | | if (startDay && !endDay) { |
| | | const compareToStart = compareDay(date, startDay); |
| | |
| | | } |
| | | } else if (type === 'multiple') { |
| | | let selectedIndex; |
| | | // @ts-ignore |
| | | const selected = currentDate.some((dateItem, index) => { |
| | | const equal = compareDay(dateItem, date) === 0; |
| | | if (equal) { |
| | |
| | | return equal; |
| | | }); |
| | | if (selected) { |
| | | // @ts-ignore |
| | | const cancelDate = currentDate.splice(selectedIndex, 1); |
| | | this.setData({ currentDate }); |
| | | this.unselect(cancelDate); |
| | | } else { |
| | | // @ts-ignore |
| | | this.select([...currentDate, date]); |
| | | } |
| | | } else { |
| | |
| | | return true; |
| | | }, |
| | | onConfirm() { |
| | | if (this.data.type === 'range' && !this.checkRange()) { |
| | | if ( |
| | | this.data.type === 'range' && |
| | | !this.checkRange(this.data.currentDate) |
| | | ) { |
| | | return; |
| | | } |
| | | wx.nextTick(() => { |
| | | // @ts-ignore |
| | | this.$emit('confirm', copyDates(this.data.currentDate)); |
| | | }); |
| | | }, |