move_setting_reminder.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { View, Text, Switch } from "@tarojs/components";
  2. import './move_setting_reminder.scss'
  3. import Cell from "../base/cell";
  4. import { useEffect, useState } from "react";
  5. import { createSchedule, getMoveSchedules } from "@/services/health";
  6. import { getThemeColor } from "@/features/health/hooks/health_hooks";
  7. export default function MoveSettingReminder() {
  8. const [selIndex, setSelIndex] = useState(-1)
  9. const [hours, setHours] = useState('')
  10. const [total, setTotal] = useState('')
  11. const [detail, setDetail] = useState<any>(null)
  12. useEffect(() => {
  13. getMoveSchedules().then(res => {
  14. setDetail(res)
  15. setHours((res as any).goal.hour)
  16. setTotal((res as any).goal.day)
  17. })
  18. }, [])
  19. if (!detail) return <View />
  20. return <View>
  21. <Text>打卡时刻表</Text>
  22. {
  23. detail.schedules.map((item, index) => {
  24. return <View key={index}>
  25. <Cell className='demoCell' disable>
  26. <View style={{ display: 'flex', flexDirection: 'column' }}>
  27. <Text>{item.reminder_time}</Text>
  28. <View>
  29. <Text style={{ flex: 1 }}>check in for {item.time}-{item.end_time}</Text>
  30. <Switch checked={item.reminder} color={getThemeColor('ACTIVE')} onChange={e => {
  31. console.log(item)
  32. createSchedule({
  33. schedules: [{
  34. id: item.id,
  35. reminder: e.detail.value
  36. }],
  37. }).then(res => {
  38. if (global.refreshWindow){
  39. global.refreshWindow()
  40. }
  41. if (global.refreshSchedules){
  42. global.refreshSchedules()
  43. }
  44. if (global.updateMove){
  45. global.updateMove()
  46. }
  47. })
  48. }}/>
  49. </View>
  50. </View>
  51. </Cell>
  52. </View>
  53. })
  54. }
  55. </View>
  56. }