import { View, Image } from "@tarojs/components" import './choose_date_time.scss' import { rpxToPx, vibrate } from "@/utils/tools" import NewButton, { NewButtonType } from "../base/new_button" import { useEffect, useState } from "react" import NewDatePicker, { NewDatePickerType } from "../base/new_date_picker" import NewTimePicker from "../base/new_timepicker" import { IconCalendar } from "@/components/basic/Icons" import dayjs from "dayjs" import NewDateTimePicker from "../base/new_date_time_picker" import { TimeFormatter } from "@/utils/time_format" import { useTranslation } from "react-i18next" import { MainColorType } from "@/context/themes/color" export default function ChooseDateTime(props: { title?: any, disable?: boolean, showError?: boolean, showLine?: boolean, minTimestamp?: number, maxTimestamp?: number, hideFooter?: boolean, footerTitle?: string, tapFooter?: any, count?: number, color: string, date: string, time: string, expand: boolean, choose?: any, timeChange?: any, dateChange?: any, change?: any, enterTimestamp?: number, targetTimestamp?: number }) { const [chooseDate, setChooseDate] = useState(false) const { t } = useTranslation() const [count, setCount] = useState(0) const health = useEffect(() => { console.log('sss') setCount(count => count + 1) }, [props.count]) function dateTitle() { if (props.date == '') return global.language == 'en' ? 'Date' : '日期' var date = dayjs(props.date) if (TimeFormatter.isToday(date.unix() * 1000)) { return global.language == 'en' ? 'Today' : '今天' } if (TimeFormatter.isYesterday(date.unix() * 1000)) { return global.language == 'en' ? 'Yesterday' : '昨天' } else if (TimeFormatter.isTimestampInThisWeek(date.unix() * 1000)) { return date.format('dddd') } else { return global.language == 'en' ? date.format('MMM D') : date.format('MMMD日') } } function timeTitle() { if (props.time == '') return global.language == 'en' ? 'Time' : '时间' return props.time } function reset() { props.change([ dayjs(props.enterTimestamp).format('YYYY-MM-DD'), dayjs(props.enterTimestamp).format('HH:mm') ]) } function tapTarget() { props.change([ dayjs(props.targetTimestamp).format('YYYY-MM-DD'), dayjs(props.targetTimestamp).format('HH:mm') ]) } function targetDate(){ if (TimeFormatter.isToday(props.targetTimestamp!)){ return TimeFormatter.getTodayUnit()+' ' } if (TimeFormatter.isYesterday(props.targetTimestamp!)){ return TimeFormatter.getYesterdayUnit()+' ' } if (TimeFormatter.isTomorrowday(props.targetTimestamp!)){ return TimeFormatter.getTomorrowUnit()+' ' } return global.language=='en'?dayjs(props.targetTimestamp).format('MMM D '):dayjs(props.targetTimestamp).format('MMMD日') } function footerTitle() { if (dayjs(props.targetTimestamp!).format('YYYY-MM-DD HH:mm') == props.date + ' ' + props.time) { return {t('health.select_schedule')} {t('health.reset')} } if (new Date().getTime() > props.targetTimestamp!) { return {t('health.schedule_for', { time: targetDate()+dayjs(props.targetTimestamp).format('HH:mm') })} {t('health.select')} } else { return { vibrate() }}> {t('health.schedule_for', { time: targetDate()+dayjs(props.targetTimestamp).format('HH:mm') })} } } return { props.title ? {props.title} : } {/* {dateTitle()} {timeTitle()} */} { !props.title ? { // setChooseDate(false) if (props.choose) { props.choose() } }} >{dateTitle()} {timeTitle()} : { setChooseDate(false) if (props.choose) { props.choose() } }} /> } { !props.title && } { props.expand && !chooseDate && {/* { props.timeChange(e) }} color={props.color} /> */} { if (props.dateChange) props.dateChange(e[0]) if (props.timeChange) props.timeChange(e[1]) props.change(e) }} color={props.color} /> } { props.expand && !chooseDate && !props.hideFooter && { props.footerTitle } { props.targetTimestamp && footerTitle() } {/* */} } { props.showLine && } }