import React, { useState, useEffect, useRef } from "react"; import CommonPopup from "@/components/CommonPopup"; import Taro from "@tarojs/taro"; import { View } from "@tarojs/components"; import CalendarUI, { CalendarUIRef, } from "@/components/Picker/CalendarUI/CalendarUI"; import dayjs from "dayjs"; import styles from "../CalendarDialog/index.module.scss"; export interface DayDialogProps { value?: Date | Date[]; searchType?: "single" | "range" | "multiple"; onChange?: (date: string | string[]) => void; visible: boolean; onClose: () => void; title?: React.ReactNode; } const DayDialog: React.FC = ({ visible, searchType, onClose, title, value, onChange, }) => { const [selected, setSelected] = useState(value || new Date()); const calendarRef = useRef(null); const [type, setType] = useState<"year" | "month" | "time">("year"); const [pendingJump, setPendingJump] = useState<{ year: number; month: number; } | null>(null); const handleConfirm = () => { console.log(selected, 'selectedselected'); if (!selected) { Taro.showToast({ title: '请选择日期', icon: "none", }); return; } const finalDate = dayjs(selected as Date).format("YYYY-MM-DD"); if (onChange){ onChange(finalDate) } onClose(); }; const dialogClose = () => { setType("year"); onClose(); } const handleChange = (d: Date | Date[]) => { if (Array.isArray(d)) { setSelected(d[0]); } else { setSelected(d); } }; const onHeaderClick = (date: Date) => { console.log("onHeaderClick", date); setSelected(date); setType("month"); }; const getConfirmText = () => { return "完成" }; const onCancel = () => { onClose(); }; useEffect(() => { if (visible && value) { setSelected(value || new Date()); } }, [value, visible]); useEffect(() => { if (type === "year" && pendingJump && calendarRef.current) { calendarRef.current.jumpTo(pendingJump.year, pendingJump.month); setPendingJump(null); } }, [type, pendingJump]); return ( ); }; export default DayDialog;