import Modal from "@/components/layout/Modal.weapp"; import TimePicker from "@/features/common/TimePicker"; import { getScenario, getThemeColor } from "@/features/health/hooks/health_hooks"; import { createSchedule, getSchedules } from "@/services/health"; import { View, Text } from "@tarojs/components"; import Taro from "@tarojs/taro"; import { useEffect, useState } from "react"; import { useSelector } from "react-redux"; import './edit.scss' export default function SchedulesTime() { const health = useSelector((state: any) => state.health); const [scenario, setScenario] = useState(getScenario(health.windows, health.mode)) const [showTimePicker, setShowTimePicker] = useState(false) const [list, setList] = useState([]) const [selItem, setSelItem] = useState(null) useEffect(() => { schedules() }, []) function schedules() { getSchedules({ window: health.mode, is_all_day: false }).then(res => { if ((res as any).data && (res as any).data.length > 0) { setList((res as any).data) } }).catch(e => { }) } function changeTime(item) { setSelItem(item) setShowTimePicker(true) } function modalContent() { const strTime = selItem.time var title = selItem.title var color = getThemeColor(health.mode) return { confirmPickerTime(e) }} cancel={() => { setShowTimePicker(false) }} /> } function confirmPickerTime(e) { console.log(e) setShowTimePicker(false) selItem.time = e; setList([...list]) } function save() { var array: any = [] list.map((item) => { array.push({ id: item.id, time: item.time, event: item.event, title: item.title }) }) createSchedule({ schedules: array }).then(res => { global.refreshWindow() global.refreshSchedules() if (process.env.TARO_ENV == 'weapp') { Taro.navigateBack() } }) } if (list.length == 0) return return { list.map((item, index) => { return changeTime(item)}> {index + 1} {item.title} {item.time} { index <= list.length - 1 && } }) } 完成 { showTimePicker && { setShowTimePicker(false) }} confirm={() => { }}> { modalContent() } } }