guide_fast.tsx 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 { setFooter, 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 GuideFast() {
  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 [loaded, setLoaded] = useState(false)
  27. const health = useSelector((state: any) => state.health);
  28. const [errors, setErrors] = useState<any>([])
  29. const [highlight, setHighlight] = useState(true)
  30. const [selItem, setSelItem] = useState<any>(null)
  31. const [showTimePicker, setShowTimePicker] = useState(false)
  32. const { t } = useTranslation()
  33. const dispatch = useDispatch()
  34. const selMode = 'FAST'
  35. useEffect(() => {
  36. getSchedules({ window: '', sort_by: 'EVENT' }).then(res => {
  37. dispatch(setSchedules((res as any).data))
  38. dispatch(setFooter((res as any).footer))
  39. setLoaded(true)
  40. setTimeout(() => {
  41. setHighlight(false)
  42. }, 2000)
  43. })
  44. }, [])
  45. function modalContent() {
  46. const strTime = selItem.time
  47. var title = selItem.title
  48. var color = getThemeColor(selItem.window)
  49. return <TimePicker time={strTime}
  50. color={color}
  51. title={title}
  52. confirm={(e) => {
  53. // selItem.time = e
  54. setSelItem(selItem)
  55. setShowTimePicker(false)
  56. var array = JSON.parse(JSON.stringify(health.schedules))
  57. array.map(item => {
  58. if (item.id == selItem.id) {
  59. item.time = e
  60. item.op_ms = new Date().getTime()
  61. }
  62. })
  63. dispatch(setSchedules(array))
  64. check(array)
  65. // var array = JSON.parse(JSON.stringify(list))
  66. // array[selIndex].time = e
  67. // setList(array)
  68. // checkData(array)
  69. }}
  70. cancel={() => {
  71. setShowTimePicker(false)
  72. }} />
  73. }
  74. function check(array) {
  75. createSchedule({
  76. schedules: array,
  77. only_check: true,
  78. return_all: true,
  79. op_page: 'SCHEDULE_WALKTHROUGH_1', sort_by: 'EVENT'
  80. }).then(res => {
  81. dispatch(setSchedules((res as any).schedules))
  82. dispatch(setFooter((res as any).footer))
  83. if ((res as any).result) {
  84. setErrors([])
  85. }
  86. else {
  87. setErrors((res as any).error_messages ? (res as any).error_messages : [])
  88. }
  89. })
  90. }
  91. function footerTitle() {
  92. if (health.footer) {
  93. return health.footer.fast.title
  94. }
  95. return ''
  96. }
  97. function footerDesc() {
  98. if (health.footer) {
  99. return health.footer.fast.description
  100. }
  101. return ''
  102. }
  103. function items() {
  104. var items = health.schedules.filter(item => item.window == 'FAST')
  105. return <Card>
  106. {
  107. errors.map((item1, index) => {
  108. return <View key={index} className='error_tip'>{item1}</View>
  109. })
  110. }
  111. {
  112. items.map((obj, i) => {
  113. return <ScheduleItem
  114. index={i}
  115. count={items.length}
  116. key={i * 100}
  117. obj={obj}
  118. highlight={highlight}
  119. showLine={i < items.length - 1}
  120. errors={errors}
  121. selMode={selMode}
  122. days={obj.plus_days != 0 ? obj.plus_days : null}
  123. hideReminderIcon={true}
  124. // days="+1 day"
  125. onChange={(time) => {
  126. var array = JSON.parse(JSON.stringify(health.schedules))
  127. array.map(item => {
  128. if (item.id == obj.id) {
  129. item.time = time
  130. item.op_ms = new Date().getTime()
  131. }
  132. })
  133. dispatch(setSchedules(array))
  134. check(array)
  135. }}
  136. />
  137. })
  138. }
  139. </Card>
  140. }
  141. if (!loaded) return <View />
  142. return <View style={{ flex: 1, display: 'flex', flexDirection: 'column', height: '100vh' }}>
  143. <View style={{ height: navigationBarHeight, backgroundColor: MainColorType.g05 }} />
  144. <View className="navi-bar" style={{ height: navigationBarHeight, zIndex: 1000, backgroundColor: MainColorType.g05 }}>
  145. <View style={{
  146. position: 'absolute',
  147. left: 0,
  148. right: 0,
  149. bottom: 0,
  150. height: 44,
  151. display: 'flex',
  152. alignItems: 'center',
  153. justifyContent: 'center'
  154. }}>
  155. <Image src={require('@assets/_health/navi_back.png')} style={{
  156. position: 'absolute',
  157. width: rpxToPx(92),
  158. height: rpxToPx(64),
  159. left: 0,
  160. top: 22 - rpxToPx(32)
  161. }}
  162. onClick={() => {
  163. Taro.navigateBack()
  164. }}
  165. />
  166. <Image src={user.avatar} mode="aspectFill" style={{
  167. background: user.isLogin ? 'transparent' : '#fff',
  168. width: rpxToPx(64),
  169. height: rpxToPx(64),
  170. borderRadius: rpxToPx(32)
  171. }} />
  172. </View>
  173. </View>
  174. <NewHeader type={NewHeaderType.center_subtitle} title={t('health.guide_0_title')} subtitle={t('health.guide_0_desc')} />
  175. {
  176. items()
  177. }
  178. <CellFooter type={CellFooterType.left}>
  179. <View style={{ display: 'flex', flexDirection: 'column' }}>
  180. <CellFooterText text={footerTitle()} isBold />
  181. <CellFooterText text={footerDesc()} />
  182. </View>
  183. </CellFooter>
  184. <View style={{ flex: 1 }} />
  185. <View className="main_footer">
  186. <NewButton
  187. type={NewButtonType.fill}
  188. title={t('health.next')}
  189. disable={errors.length > 0}
  190. color={MainColorType.fast}
  191. width={rpxToPx(646)}
  192. height={rpxToPx(96)}
  193. onClick={() => {
  194. jumpPage('./guide_sleep')
  195. }}
  196. />
  197. </View>
  198. {
  199. showTimePicker && <Modal
  200. testInfo={null}
  201. dismiss={() => {
  202. setShowTimePicker(false)
  203. }}
  204. confirm={() => {
  205. }}>
  206. {
  207. modalContent()
  208. }
  209. </Modal>
  210. }
  211. </View>
  212. }