import { formatDate, formatNumber } from '@/utils/common' // 拼接 预约时间 picker export function getAppointFun (time) { let arr = [] // 当天剩余时间段 let obj = getCurrentDatePicker(time) arr.push(obj) // 后六天的可选时间段 let tempArr = getAfterTimeList() arr.push(...tempArr) return arr } // 拼接 当天剩余的可预约时间段(默认第一个是两小时之后可选) const getCurrentDatePicker = time => { let obj = {} obj.text = formatDate(time); let timeArr = getCurrentTimeList() obj.children = timeArr return obj } // 当天日期的时间段 const getCurrentTimeList = () => { let todayDate = new Date() let tempArr = [] tempArr.push({ text: '尽快到' }); // 首先添加尽快到 if( todayDate.getMinutes() <= 30 && todayDate.getMinutes() > 0 ) { let tempVal = todayDate.getHours() + 2; let tempHalfHours = formatNumber(tempVal) + ':30'; tempArr.push({ text: tempHalfHours }); } let startFlag = (todayDate.getMinutes() == 0) ? (todayDate.getHours() + 2) : (todayDate.getHours() + 3) tempArr = getDateTimeList(startFlag, tempArr) return tempArr } // 获取后六天的 预约时间 picker const getAfterTimeList = () => { let afterArr = [] for(let i = 1; i < 7; i++ ) { let obj = {}; let tempTime = formatDate(new Date().getTime() + (i * 24* 60 * 60 * 1000)) obj.text = tempTime let timeArr = [] obj.children = getDateTimeList(0, timeArr) afterArr.push(obj) } return afterArr } // 获取某个时间段后的所有可选时段 const getDateTimeList = (startHours = 0, list) => { for(let i = startHours; i < 24; i++ ) { list.push({ text: formatNumber(i) + ':' + '00' }) list.push({ text: formatNumber(i) + ':' + '30' }) } return list }