guide_full.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import { View, Text, Image } from "@tarojs/components";
  2. import './guide.scss'
  3. import '@/_health/pages/schedules.scss'
  4. import NewHeader, { NewHeaderType } from "../components/new_header";
  5. import { useEffect, useState } from "react";
  6. import { createSchedule, getSchedules } from "@/services/health";
  7. import { setSchedules } from "@/store/health";
  8. import { useDispatch, useSelector } from "react-redux";
  9. import Card from "../components/card";
  10. import { rpxToPx } from "@/utils/tools";
  11. import { getThemeColor } from "@/features/health/hooks/health_hooks";
  12. import Modal from "@/components/layout/Modal.weapp";
  13. import TimePicker from "@/features/common/TimePicker";
  14. import NewButton, { NewButtonType } from "../base/new_button";
  15. import { MainColorType } from "@/context/themes/color";
  16. import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
  17. import ScheduleItem from "../components/schedule_item";
  18. import { useTranslation } from "react-i18next";
  19. import CellFooter, { CellFooterType } from "../base/cell_footer";
  20. import CellFooterText from "../base/cell_footer_text";
  21. import Taro from "@tarojs/taro";
  22. export default function GuideFull() {
  23. const systemInfo: any = Taro.getWindowInfo?Taro.getWindowInfo():Taro.getSystemInfoSync();
  24. const navigationBarHeight = systemInfo.statusBarHeight + 44;
  25. const user = useSelector((state: any) => state.user);
  26. const health = useSelector((state: any) => state.health);
  27. const [errors, setErrors] = useState<any>([])
  28. const [posting,setPosting] = useState(false)
  29. const [selItem, setSelItem] = useState<any>(null)
  30. const { t } = useTranslation()
  31. const dispatch = useDispatch()
  32. const selMode = 'SLEEP'
  33. useEffect(() => {
  34. }, [])
  35. function commit() {
  36. if (posting) return
  37. setPosting(true)
  38. createSchedule({
  39. schedules: health.schedules,
  40. op_page: 'SCHEDULE_FINISH_SETUP'
  41. // only_check: true
  42. }).then(res => {
  43. const data = {
  44. title: t('health.guide_done_title'),
  45. description: t('health.guide_done_desc'),
  46. current_window: (res as any).current_window
  47. }
  48. jumpPage('./post_result?type=schedule&data=' + JSON.stringify(data))
  49. if (global.refreshWindow) {
  50. global.refreshWindow()
  51. }
  52. setPosting(false)
  53. }).catch(e=>{
  54. setPosting(false)
  55. })
  56. }
  57. function footerDesc() {
  58. if (health.footer) {
  59. return health.footer.summary.description
  60. }
  61. return ''
  62. }
  63. function items() {
  64. var array = JSON.parse(JSON.stringify(health.schedules))
  65. array.sort((a, b) => {
  66. return a.time.localeCompare(b.time);
  67. });
  68. return <Card>
  69. {
  70. array.map((obj, i) => {
  71. return <ScheduleItem
  72. index={i}
  73. count={array.length}
  74. key={i * 100}
  75. obj={obj}
  76. disable
  77. showLine={i < array.length - 1}
  78. errors={errors}
  79. selMode={selMode}
  80. />
  81. })
  82. }
  83. </Card>
  84. }
  85. return <View style={{ flex: 1, display: 'flex', flexDirection: 'column', height: '100vh' }}>
  86. <View style={{ height: navigationBarHeight, backgroundColor: MainColorType.g05,flexShrink:0 }} />
  87. <View className="navi-bar" style={{ height: navigationBarHeight, zIndex: 1000, backgroundColor: MainColorType.g05 }}>
  88. <View style={{
  89. position: 'absolute',
  90. left: 0,
  91. right: 0,
  92. bottom: 0,
  93. height: 44,
  94. display: 'flex',
  95. alignItems: 'center',
  96. justifyContent: 'center'
  97. }}>
  98. <Image src={require('@assets/_health/navi_back.png')} style={{
  99. position: 'absolute',
  100. width: rpxToPx(92),
  101. height: rpxToPx(64),
  102. left: 0,
  103. top: 22 - rpxToPx(32)
  104. }}
  105. onClick={() => {
  106. Taro.navigateBack()
  107. }}
  108. />
  109. <Image src={user.avatar} mode="aspectFill" style={{
  110. background: user.isLogin ? 'transparent' : '#fff',
  111. width: rpxToPx(64),
  112. height: rpxToPx(64),
  113. borderRadius: rpxToPx(32)
  114. }} />
  115. </View>
  116. </View>
  117. <NewHeader type={NewHeaderType.center_subtitle} title={t('health.guide_end_title')} subtitle={t('health.guide_end_desc')} />
  118. {
  119. items()
  120. }
  121. <CellFooter type={CellFooterType.left}>
  122. <View style={{ display: 'flex', flexDirection: 'column' }}>
  123. <CellFooterText text={footerDesc()} />
  124. </View>
  125. </CellFooter>
  126. <View style={{ height: 200, flexShrink: 0 }} />
  127. <View style={{ flex: 1 }} />
  128. <View className="main_footer">
  129. <NewButton
  130. type={NewButtonType.fill}
  131. title={t('health.done')}
  132. color={MainColorType.fast}
  133. width={rpxToPx(646)}
  134. height={rpxToPx(96)}
  135. onClick={commit}
  136. />
  137. </View>
  138. </View>
  139. }