| | |
| | | }) |
| | | }, |
| | | initDoorTimeOptions() { |
| | | const now = new Date() |
| | | const currentYear = now.getFullYear() |
| | | const earliestTime = this.getEarliestDoorTime() |
| | | const currentYear = earliestTime.getFullYear() |
| | | this.years = this.createRange(currentYear, currentYear + 10) |
| | | this.months = this.createRange(1, 12) |
| | | this.hours = this.createRange(0, 23) |
| | | this.minutes = this.createRange(0, 59) |
| | | this.setDoorTimeValueByDate(now) |
| | | this.setDoorTimeValueByDate(earliestTime) |
| | | }, |
| | | createRange(start, end) { |
| | | const list = [] |
| | |
| | | return String(value).padStart(2, '0') |
| | | }, |
| | | setDoorTimeValueByDate(date) { |
| | | const yearIndex = Math.max(0, this.years.findIndex(item => Number(item) === date.getFullYear())) |
| | | const monthIndex = date.getMonth() |
| | | this.updateDays(this.years[yearIndex], this.months[monthIndex]) |
| | | const earliestTime = this.getEarliestDoorTime() |
| | | const selectedTime = date < earliestTime ? earliestTime : date |
| | | const yearIndex = Math.max(0, this.years.findIndex(item => Number(item) === selectedTime.getFullYear())) |
| | | const isEarliestYear = selectedTime.getFullYear() === earliestTime.getFullYear() |
| | | this.months = this.createRange(isEarliestYear ? earliestTime.getMonth() + 1 : 1, 12) |
| | | const monthIndex = this.months.findIndex(item => Number(item) === selectedTime.getMonth() + 1) |
| | | const isEarliestMonth = isEarliestYear && selectedTime.getMonth() === earliestTime.getMonth() |
| | | this.days = this.createRange(isEarliestMonth ? earliestTime.getDate() : 1, |
| | | this.getMonthDays(selectedTime.getFullYear(), selectedTime.getMonth() + 1)) |
| | | const dayIndex = this.days.findIndex(item => Number(item) === selectedTime.getDate()) |
| | | const isEarliestDay = isEarliestMonth && selectedTime.getDate() === earliestTime.getDate() |
| | | this.hours = this.createRange(isEarliestDay ? earliestTime.getHours() : 0, 23) |
| | | const hourIndex = this.hours.findIndex(item => Number(item) === selectedTime.getHours()) |
| | | const isEarliestHour = isEarliestDay && selectedTime.getHours() === earliestTime.getHours() |
| | | this.minutes = this.createRange(isEarliestHour ? earliestTime.getMinutes() : 0, 59) |
| | | const minuteIndex = this.minutes.findIndex(item => Number(item) === selectedTime.getMinutes()) |
| | | this.doorTimeValue = [ |
| | | yearIndex, |
| | | monthIndex, |
| | | date.getDate() - 1, |
| | | date.getHours(), |
| | | date.getMinutes() |
| | | dayIndex, |
| | | hourIndex, |
| | | minuteIndex |
| | | ] |
| | | this.tempDoorTimeValue = [...this.doorTimeValue] |
| | | }, |
| | | getEarliestDoorTime() { |
| | | const earliestTime = new Date() |
| | | earliestTime.setSeconds(0, 0) |
| | | earliestTime.setMinutes(earliestTime.getMinutes() + 1) |
| | | return earliestTime |
| | | }, |
| | | getMonthDays(year, month) { |
| | | return new Date(Number(year), Number(month), 0).getDate() |
| | | }, |
| | | updateDays(year, month) { |
| | | this.days = this.createRange(1, this.getMonthDays(year, month)) |
| | | }, |
| | | openDoorTimePicker() { |
| | | if (!this.years.length) { |
| | |
| | | }, |
| | | changeDoorTime(e) { |
| | | const value = [...e.detail.value] |
| | | const year = this.years[value[0]] |
| | | const month = this.months[value[1]] |
| | | const maxDay = this.getMonthDays(year, month) |
| | | if (value[2] >= maxDay) { |
| | | value[2] = maxDay - 1 |
| | | } |
| | | this.updateDays(year, month) |
| | | this.tempDoorTimeValue = value |
| | | const selectedTime = new Date( |
| | | Number(this.years[value[0]]), |
| | | Number(this.months[value[1]]) - 1, |
| | | Number(this.days[value[2]]), |
| | | Number(this.hours[value[3]]), |
| | | Number(this.minutes[value[4]]) |
| | | ) |
| | | this.setDoorTimeValueByDate(selectedTime) |
| | | }, |
| | | confirmDoorTimePicker() { |
| | | this.doorTimeValue = [...this.tempDoorTimeValue] |