move_setting_reminder.tsx 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { View, Text, Switch } from "@tarojs/components";
  2. import './move_setting_reminder.scss'
  3. import './move_schedule.scss'
  4. import Cell from "../base/cell";
  5. import { useEffect, useState } from "react";
  6. import { createSchedule, getMoveSchedules } from "@/services/health";
  7. import { getThemeColor } from "@/features/health/hooks/health_hooks";
  8. import NewHeader, { NewHeaderType } from "../components/new_header";
  9. import { IconNotification, IconNotificationOff } from "@/components/basic/Icons";
  10. import { MainColorType } from "@/context/themes/color";
  11. import { rpxToPx } from "@/utils/tools";
  12. import StatusIndicator, { StatusType } from "../base/status_indicator";
  13. export default function MoveSettingReminder() {
  14. const [selIndex, setSelIndex] = useState(-1)
  15. const [hours, setHours] = useState('')
  16. const [total, setTotal] = useState('')
  17. const [detail, setDetail] = useState<any>(null)
  18. useEffect(() => {
  19. getData()
  20. }, [])
  21. function getData() {
  22. getMoveSchedules().then(res => {
  23. setDetail(res)
  24. setHours((res as any).goal.hour)
  25. setTotal((res as any).goal.day)
  26. })
  27. }
  28. if (!detail) return <View />
  29. return <View>
  30. <NewHeader type={NewHeaderType.left} title="Full Check In Schedule" />
  31. {
  32. detail.schedules.map((item, index) => {
  33. return <View key={index}>
  34. <View key={index} className="schedule_item">
  35. {/* <View style={{ display: 'flex', flexDirection: 'column' }}>
  36. <Text>{item.reminder_time}</Text>
  37. <View>
  38. <Text style={{ flex: 1 }}>check in for {item.time}-{item.end_time}</Text>
  39. </View>
  40. </View> */}
  41. <View className="schedule_item_left">
  42. <StatusIndicator type={StatusType.normal}
  43. color={MainColorType.active}
  44. text={'WAKING HOUR ' + (index + 1)} />
  45. <View className="h34" style={{ marginLeft: rpxToPx(30) }}>Check in at {item.reminder_time}</View>
  46. <Text className="h22" style={{ color: MainColorType.g02, marginTop: rpxToPx(12), marginLeft: rpxToPx(30) }}>
  47. {item.title}
  48. </Text>
  49. {/* <Text className="schedule_item_target">{item.real_steps}/{item.target_steps} steps</Text> */}
  50. </View>
  51. <View style={{ flex: 1 }} />
  52. {
  53. item.reminder ? <IconNotification color={MainColorType.g03} width={rpxToPx(28)} /> : <IconNotificationOff color={MainColorType.g03} width={rpxToPx(28)} />
  54. }
  55. <View style={{ width: rpxToPx(12) }} />
  56. <Switch checked={item.reminder} color={getThemeColor('ACTIVE')} onChange={e => {
  57. console.log(item)
  58. createSchedule({
  59. schedules: [{
  60. id: item.id,
  61. reminder: e.detail.value
  62. }],
  63. }).then(res => {
  64. getData()
  65. if (global.refreshWindow) {
  66. global.refreshWindow()
  67. }
  68. if (global.refreshSchedules) {
  69. global.refreshSchedules()
  70. }
  71. if (global.updateMove) {
  72. global.updateMove()
  73. }
  74. })
  75. }} />
  76. {
  77. index < detail.schedules.length - 1 && <View className="border_footer_line" style={{ left: rpxToPx(72) }} />
  78. }
  79. </View>
  80. </View>
  81. })
  82. }
  83. </View>
  84. }