import { View, Text, Input, Switch } from "@tarojs/components"; import './add_label.scss' import { useEffect, useState } from "react"; import Modal from "@/components/layout/Modal.weapp"; import TimePicker from "@/features/common/TimePicker"; import dayjs from "dayjs"; import { MainColorType } from "@/context/themes/color"; import { createSchedule, getLabelsTime, getSchedules } from "@/services/health"; import Taro from "@tarojs/taro"; import { useSelector } from "react-redux"; import { getThemeColor } from "@/features/health/hooks/health_hooks"; export default function AddLabel(props: { labels: any, defaultValue?: string, disMiss?: any }) { const [showTimePicker, setShowTimePicker] = useState(false) const health = useSelector((state: any) => state.health); const [value, setValue] = useState(props.defaultValue ?? '') const [isFullday, setIsFullday] = useState(false) const [timeLabels, setTimeLabels] = useState([]) const [strTime, setStrTime] = useState('') // function timeContent() { // return { // setShowTimePicker(false) // }} // confirm={() => { }}> // { // pickerContent() // } // // } useEffect(() => { getData() }, []) function getData() { getLabelsTime({}).then(res => { setTimeLabels((res as any).labels) }) } function pickerContent() { const strTime = dayjs().format('HH:mm') return { confirmPickerTime(e) }} cancel={() => { setShowTimePicker(false) }} /> } function confirmPickerTime(e) { console.log(e) createSchedule({ schedules: [{ event: health.mode == 'EAT' ? 'EAT_CUSTOM' : 'ACTIVE_CUSTOM', title: value, time: e, is_all_day: false, }] }).then(res => { global.refreshWindow() global.refreshSchedules() // if (process.env.TARO_ENV == 'weapp') { // Taro.navigateBack() // } }) } function done() { createSchedule({ schedules: [{ event: health.mode == 'EAT' ? 'EAT_CUSTOM' : 'ACTIVE_CUSTOM', title: value, time: dayjs().format('HH:mm'), is_all_day: isFullday, time_label: isFullday ? strTime : null }] }).then(res => { if (global.refreshWindow) { global.refreshWindow() } if (global.refreshSchedules) { global.refreshSchedules() } setShowTimePicker(false) if (props.disMiss) { props.disMiss() } // if (process.env.TARO_ENV == 'weapp') { // Taro.navigateBack() // } }) } function timeContent() { return Set Time 全天时间 { setIsFullday(e.detail.value) // item.reminder = e.detail.value // setList([...list]) }} /> { isFullday ? { setStrTime(e.target.value) }} /> { timeLabels.map((item, index) => { return setStrTime(item.title)}>{item.title} }) } : {dayjs().format('HH:mm')} Picker placeholder } done()}>完成 } return 标记为 { setValue(e.target.value) }} /> { props.labels.map((item, index) => { return setValue(item.title)}>{item.title} }) } setShowTimePicker(true)}>下一步 {/* { showTimePicker && timeContent() } */} { showTimePicker && { setShowTimePicker(false) }} confirm={() => { }}> { timeContent() } } }