move_setting_time.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { View, Text, Input } from "@tarojs/components";
  2. import './move_setting_time.scss'
  3. import Cell from "../base/cell";
  4. import { useEffect, useState } from "react";
  5. import { createSchedule, getMoveSchedules } from "@/services/health";
  6. import { rpxToPx } from "@/utils/tools";
  7. import NewHeader, { NewHeaderType } from "../components/new_header";
  8. import NewButton, { NewButtonType } from "../base/new_button";
  9. import StatusIndicator, { StatusType } from "../base/status_indicator";
  10. import { MainColorType } from "@/context/themes/color";
  11. import ConsoleCell from "../components/console_cell";
  12. import Layout from "@/components/layout/layout";
  13. import { NaviBarTitleShowType, TemplateType } from "@/utils/types";
  14. import Card from "../components/card";
  15. import { useTranslation } from "react-i18next";
  16. export default function MoveSettingTime() {
  17. const [selIndex, setSelIndex] = useState(-1)
  18. const [hours, setHours] = useState('')
  19. const [total, setTotal] = useState('')
  20. const [detail, setDetail] = useState<any>(null)
  21. const {t} = useTranslation()
  22. useEffect(() => {
  23. getDatas()
  24. }, [])
  25. function getDatas() {
  26. getMoveSchedules().then(res => {
  27. setDetail(res)
  28. setHours((res as any).goal.hour)
  29. setTotal((res as any).goal.day)
  30. })
  31. }
  32. if (!detail) return <View />
  33. function detailContent() {
  34. return <View>
  35. <NewHeader
  36. type={NewHeaderType.left_subtitle}
  37. title={t('health.hour_step_goal')}
  38. subtitle={t('health.avg_total_steps',{avg:hours,total:total})}//{`平均 ${hours} 步,全天 ${total} 步`}
  39. />
  40. <Card>
  41. <View style={{ display: 'flex', flexDirection: 'column', width: rpxToPx(700) }}>
  42. {
  43. detail.schedules.map((item, index) => {
  44. return <ConsoleCell key={index}
  45. moveCell
  46. status={<StatusIndicator
  47. type={StatusType.normal}
  48. text={t('health.waking_hour')+' ' + (index + 1)}
  49. color={MainColorType.active}
  50. />
  51. }
  52. right={selIndex != index ? <Text className="h26" style={{ color: MainColorType.link }} onClick={() => {
  53. setSelIndex(index)
  54. }}>{t('health.change_goal')}</Text> : null}
  55. disable={true}
  56. showLine={true}
  57. fullLine={false}
  58. description={`${item.time}-${item.end_time}`}
  59. title={selIndex != index ? `Hit ${item.goal} Steps` : null}
  60. titleComponent={selIndex == index ? <Input className='item_name h34' style={{ flex: 1, height: rpxToPx(46), marginLeft: rpxToPx(32) }}
  61. // value={item.goal}
  62. autoFocus={true}
  63. focus={true}
  64. type="number"
  65. // cursor={item.goal.length}
  66. onBlur={() => {
  67. setSelIndex(-1)
  68. createSchedule({
  69. schedules: [{
  70. id: item.id,
  71. goal: item.goal
  72. }],
  73. }).then(res => {
  74. if (global.refreshWindow) {
  75. global.refreshWindow()
  76. }
  77. if (global.refreshSchedules) {
  78. global.refreshSchedules()
  79. }
  80. if (global.updateMove) {
  81. global.updateMove()
  82. }
  83. getDatas()
  84. })
  85. }}
  86. onInput={(e) => {
  87. // item.goal = e.detail.value
  88. var obj = JSON.parse(JSON.stringify(detail))
  89. obj.schedules[index].goal = e.detail.value
  90. setDetail(obj)
  91. }} /> : null}
  92. />
  93. })
  94. }
  95. </View>
  96. </Card>
  97. </View>
  98. }
  99. return <Layout children={detailContent()}
  100. // title={router.params.title}
  101. header={null}
  102. secondPage={true}
  103. titleColor={'#fff'}
  104. title={t('health.hour_step_goal')}
  105. type={TemplateType.customHeader}
  106. titleShowStyle={NaviBarTitleShowType.scrollToShow} />
  107. }