import React, { useCallback, useEffect, useState } from 'react' import styles from './index.module.scss' import TopCom from '@/components/TopCom' import classNames from 'classnames' import { APIN_getList } from '@/store/action/all' import { A3NlistType } from './type' import ZFlooBtn from '@/components/ZFlooBtn' import history from '@/utils/history' import dayjs from 'dayjs' const week = ['日', '一', '二', '三', '四', '五', '六'] const nowDay = dayjs().format('YYYY-MM-DD') function A3selectDayNew() { const [list, setList] = useState([]) const [loding, setLoding] = useState(false) const getListFu = useCallback(async () => { const res = await APIN_getList(7) if (res.code === 0) { setLoding(true) const obj: any = res.data.time || {} let arr: A3NlistType[] = [] for (const k in obj) { arr.push({ name: k, arr: obj[k] }) } setList(arr) } }, []) useEffect(() => { getListFu() }, [getListFu]) const [acObj, setAcObj] = useState({ bookDate: '', bookTime: '', id: 0 }) // 当天的日期过滤 已经超过现在的时间 返回true const timeFile = useCallback((date: string, time: string) => { let falg = false if (nowDay === date) { const nowTime = dayjs(date + ' ' + time).valueOf() if (Date.now() > nowTime) falg = true } return falg }, []) return (
{list.length ? (
{list.map(item => (
{item.name} {`星期${week[dayjs(item.name).day()]}`}
{item.arr.map(vv => (
setAcObj({ bookDate: item.name, bookTime: `${vv.timeStart}-${vv.timeEnd}`, id: vv.id }) } className={classNames( acObj.id === vv.id ? 'A3ac' : '', vv.pcs === 0 || timeFile(item.name, vv.timeStart) ? 'A3R2rowNo' : '' )} > {vv.timeStart} - {vv.timeEnd} {vv.pcs === 0 ? ' 已满' : ''}
))}
))}
) : ( )}
history.push(`/selectCourse/${acObj.id}/${acObj.bookDate}/${acObj.bookTime}`) } />
) } const MemoA3selectDayNew = React.memo(A3selectDayNew) export default MemoA3selectDayNew