import { View, Text, Image } from '@tarojs/components' import './schedules_list.scss' import './edit.scss' import { useEffect, useState } from 'react' import Modal from '@/components/layout/Modal.weapp' import AddLabel from '../components/add_label' import { delSchedule, getLabels, getSchedules } from '@/services/health' import { AtSwipeAction } from "taro-ui" import { useSelector } from 'react-redux' import { getThemeColor } from '@/features/health/hooks/health_hooks' import showActionSheet from '@/components/basic/ActionSheet' import { jumpPage } from '@/features/trackTimeDuration/hooks/Common' import { IconAdd } from '@/components/basic/Icons' import { rpxToPx } from '@/utils/tools' export default function SchedulesList() { const [showModal, setShowModal] = useState(false) const [list, setList] = useState([]) const [labels, setLabels] = useState([]) const [showDel, setShowDel] = useState(false) const health = useSelector((state: any) => state.health); let navigation, showActionSheetWithOptions; useEffect(() => { schedules() }, []) global.refreshSchedules = () => { schedules() } function schedules() { let windows = '' switch (health.mode) { case 'FAST': windows = 'FAST,EAT'; break case 'EAT': windows = 'EAT,FAST'; break case 'SLEEP': windows = 'SLEEP,ACTIVE'; break case 'ACTIVE': windows = 'ACTIVE,SLEEP'; break } getSchedules({ window: windows }).then(res => { if ((res as any).data && (res as any).data.length > 0) { // setList((res as any).data) let grouped: any = {}; (res as any).data.forEach(item => { const window = item.window; if (!grouped[window]) { grouped[window] = { window: window, list: [] }; } grouped[window].list.push(item); }); var array = Object.values(grouped) array.map((dt: any) => { if (dt.window == 'EAT' || dt.window == 'ACTIVE') { dt.list.push({ add: true }) } }) setList(array) } }).catch(e => { }) getLabels({ window: health.mode }).then(res => { setLabels((res as any).labels) }) } function add() { setShowModal(true) } function delItem(index) { delSchedule(list[index].id).then(res => { schedules() global.refreshWindow() global.refreshHistory() }) } function tapEdit() { jumpPage('./schedules_edit') return; let array: any = [] switch (health.mode) { case 'DAY': case 'NIGHT': array = ['设置提醒'] break case 'FAST': case 'SLEEP': array = ['调整时间', '设置提醒'] break; case 'EAT': case 'ACTIVE': array = ['调整时间', '设置提醒', '编辑标记', '删除'] break; } showActionSheet({ showActionSheetWithOptions: showActionSheetWithOptions, title: 'Oprate Title', itemList: array, success: (res) => { tapActionSheet(res) } }) } function tapActionSheet(index) { const mode = health.mode; switch (index) { case 0: switch (mode) { case 'DAY': case 'NIGHT': jumpPage('/_health/pages/schedules_reminder') break; default: jumpPage('/_health/pages/schedules_time') break; } break; case 1: jumpPage('/_health/pages/schedules_reminder') break; case 2: jumpPage('/_health/pages/schedules_mark') break; case 3: jumpPage('/_health/pages/schedules_del') break; } } function getTitle() { switch (health.mode) { case 'FAST': return '断食和进食'; case 'EAT': return '进食和断食'; case 'SLEEP': return '睡眠和活动'; case 'ACTIVE': return '活动和睡眠'; } return '' } return {getTitle()} { list.map((item, index) => { return { item.list.map((obj, i) => { if (obj.add) { return 添加 {/* setShowDel(!showDel)}>移除 */} } return { }}> {i + 1} {obj.title} { !obj.reminder && } {obj.time} { i < item.list.length - 1 && } }) } }) } 批量编辑 { showModal && { setShowModal(false) }} confirm={() => { }}> } }