move_setting_reminder.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. import Layout from "@/components/layout/layout";
  14. import { NaviBarTitleShowType, TemplateType } from "@/utils/types";
  15. export default function MoveSettingReminder() {
  16. const [selIndex, setSelIndex] = useState(-1)
  17. const [hours, setHours] = useState('')
  18. const [total, setTotal] = useState('')
  19. const [detail, setDetail] = useState<any>(null)
  20. useEffect(() => {
  21. getData()
  22. }, [])
  23. function getData() {
  24. getMoveSchedules().then(res => {
  25. setDetail(res)
  26. setHours((res as any).goal.hour)
  27. setTotal((res as any).goal.day)
  28. })
  29. }
  30. if (!detail) return <View />
  31. function detailContent() {
  32. return <View>
  33. <NewHeader type={NewHeaderType.left} title="Full Check In Schedule" />
  34. {
  35. detail.schedules.map((item, index) => {
  36. return <View key={index}>
  37. <View key={index} className="schedule_item">
  38. {/* <View style={{ display: 'flex', flexDirection: 'column' }}>
  39. <Text>{item.reminder_time}</Text>
  40. <View>
  41. <Text style={{ flex: 1 }}>check in for {item.time}-{item.end_time}</Text>
  42. </View>
  43. </View> */}
  44. <View className="schedule_item_left">
  45. <StatusIndicator type={StatusType.normal}
  46. color={MainColorType.active}
  47. text={'WAKING HOUR ' + (index + 1)} />
  48. <View className="h34" style={{ marginLeft: rpxToPx(30) }}>Check in at {item.reminder_time}</View>
  49. <Text className="h22" style={{ color: MainColorType.g02, marginTop: rpxToPx(12), marginLeft: rpxToPx(30) }}>
  50. {item.title}
  51. </Text>
  52. {/* <Text className="schedule_item_target">{item.real_steps}/{item.target_steps} steps</Text> */}
  53. </View>
  54. <View style={{ flex: 1 }} />
  55. {
  56. item.reminder ? <IconNotification color={MainColorType.g03} width={rpxToPx(28)} /> : <IconNotificationOff color={MainColorType.g03} width={rpxToPx(28)} />
  57. }
  58. <View style={{ width: rpxToPx(12) }} />
  59. <Switch checked={item.reminder} color={getThemeColor('ACTIVE')} onChange={e => {
  60. console.log(item)
  61. createSchedule({
  62. schedules: [{
  63. id: item.id,
  64. reminder: e.detail.value
  65. }],
  66. }).then(res => {
  67. getData()
  68. if (global.refreshWindow) {
  69. global.refreshWindow()
  70. }
  71. if (global.refreshSchedules) {
  72. global.refreshSchedules()
  73. }
  74. if (global.updateMove) {
  75. global.updateMove()
  76. }
  77. })
  78. }} />
  79. {
  80. index < detail.schedules.length - 1 && <View className="border_footer_line" style={{ left: rpxToPx(72) }} />
  81. }
  82. </View>
  83. </View>
  84. })
  85. }
  86. </View>
  87. }
  88. return <Layout children={detailContent()}
  89. // title={router.params.title}
  90. header={null}
  91. secondPage={true}
  92. titleColor={'#fff'}
  93. title={'Full Check In Schedule'}
  94. type={TemplateType.customHeader}
  95. titleShowStyle={NaviBarTitleShowType.scrollToShow} />
  96. }