post_result.tsx 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. import { View, Image, Text, Switch } from "@tarojs/components";
  2. import Taro, { useRouter } from "@tarojs/taro";
  3. import './post_result.scss'
  4. import { getThemeColor } from "@/features/health/hooks/health_hooks";
  5. import { rpxToPx } from "@/utils/tools";
  6. import NewButton, { NewButtonType } from "../base/new_button";
  7. import { IconActive, IconCheck, IconNotification, IconNotificationOff, IconSit } from "@/components/basic/Icons";
  8. import { MainColorType } from "@/context/themes/color";
  9. import { useState } from "react";
  10. import dayjs from "dayjs";
  11. import { useDispatch, useSelector } from "react-redux";
  12. import { setMode, setShowActionTip } from "@/store/health";
  13. import NewModal from "../base/new_modal";
  14. import Card from "../components/card";
  15. import { updateReminder } from "@/services/health";
  16. import StatusIndicator, { StatusType } from "../base/status_indicator";
  17. import { useTranslation } from "react-i18next";
  18. let useRoute;
  19. let useNavigation;
  20. if (process.env.TARO_ENV == 'rn') {
  21. useRoute = require("@react-navigation/native").useRoute
  22. useNavigation = require("@react-navigation/native").useNavigation
  23. }
  24. export default function PostResult() {
  25. const user = useSelector((state: any) => state.user);
  26. let router
  27. let navigation;
  28. if (useNavigation) {
  29. navigation = useNavigation()
  30. }
  31. if (process.env.TARO_ENV == 'rn') {
  32. router = useRoute()
  33. }
  34. else {
  35. router = useRouter()
  36. }
  37. const [data, setData] = useState(JSON.parse(router.params.data))
  38. const [showSetting, setShowSetting] = useState(false)
  39. const dispatch = useDispatch()
  40. const { t } = useTranslation()
  41. function getMainColor() {
  42. if (data.scenario == 'MOVE' && data.extra.move_status == 'SEDENTARY') {
  43. return MainColorType.g02
  44. }
  45. return getThemeColor(data.window ? data.window : 'FAST')
  46. }
  47. function nextTitle() {
  48. return data.next.content
  49. }
  50. function showSwitchBtn() {
  51. if (data.extra && data.extra.fast_type == 'LF') return false;
  52. return data.schedule_completed
  53. }
  54. function changeReminder(e) {
  55. updateReminder({ reminder: e.detail.value }, data.next.schedule_id).then((res) => {
  56. var detail = JSON.parse(JSON.stringify(data))
  57. detail.next.reminder = e.detail.value
  58. setData(detail)
  59. })
  60. }
  61. function swithBtnText() {
  62. switch (data.window) {
  63. case 'FAST':
  64. return 'Switch to Eat'
  65. case 'EAT':
  66. return 'Switch to Fast'
  67. case 'ACTIVE':
  68. return 'Switch to Sleep'
  69. case 'SLEEP':
  70. return 'Swtich to Active'
  71. }
  72. return ''
  73. }
  74. function tapSwitch() {
  75. switch (data.window) {
  76. case 'FAST':
  77. dispatch(setMode('EAT'))
  78. break
  79. case 'EAT':
  80. dispatch(setMode('FAST'))
  81. break
  82. case 'ACTIVE':
  83. dispatch(setMode('SLEEP'))
  84. break
  85. case 'SLEEP':
  86. dispatch(setMode('ACTIVE'))
  87. break
  88. }
  89. Taro.navigateBack()
  90. }
  91. function headerIcon() {
  92. if (data.current_window) {
  93. return <View style={{
  94. width: rpxToPx(128), height: rpxToPx(128),
  95. borderRadius: rpxToPx(64),
  96. borderWidth: rpxToPx(4),
  97. boxSizing:'border-box',
  98. borderColor: getThemeColor(data.current_window),
  99. borderStyle: 'solid',
  100. display: 'flex',
  101. alignItems: 'center',
  102. justifyContent: 'center'
  103. }}>
  104. <Image src={user.avatar} mode="aspectFill" style={{
  105. background: user.isLogin ? 'transparent' : '#fff',
  106. width: rpxToPx(108),
  107. height: rpxToPx(108),
  108. borderRadius:rpxToPx(54)
  109. }} />
  110. </View>
  111. }
  112. if (data.images && data.images.length > 0) {
  113. return <View className="result_icon_bg">
  114. <Image className="result_icon_bg" mode="aspectFill" src={data.images[0]} />
  115. <View className="result_icon_small" style={{ backgroundColor: getMainColor() }}>
  116. <IconCheck color="#fff" width={rpxToPx(32)} height={rpxToPx(32)} />
  117. </View>
  118. </View>
  119. }
  120. if (data.scenario == 'MOVE') {
  121. return data.extra.move_status == 'ACTIVE' ?<IconActive width={rpxToPx(128)} color={MainColorType.active}/>:<IconSit width={rpxToPx(128)} color={MainColorType.g02}/>
  122. }
  123. return <View className="result_icon_bg" style={{ backgroundColor: getMainColor() }}>
  124. <IconCheck color="#fff" width={rpxToPx(88)} height={rpxToPx(88)} />
  125. </View>
  126. }
  127. function headerDesc() {
  128. if (data.scenario == 'MOVE') {
  129. if (data.extra.move_status == 'SEDENTARY') {
  130. return 'Sedentary Hour'
  131. }
  132. else {
  133. return 'Active Hour'
  134. }
  135. }
  136. return data.description
  137. }
  138. function statusText() {
  139. switch (data.current_window) {
  140. case 'FAST':
  141. return t('health.guide_current_scenario', { scenario: t('health.fast') })
  142. case 'EAT':
  143. return t('health.guide_current_scenario', { scenario: t('health.eat') })
  144. case 'SLEEP':
  145. return t('health.guide_current_scenario', { scenario: t('health.sleep') })
  146. case 'ACTIVE':
  147. return t('health.guide_current_scenario', { scenario: t('health.active') })
  148. }
  149. return ''
  150. }
  151. return <View className="post_result_container">
  152. {
  153. headerIcon()
  154. }
  155. <View className="h50 bold" style={{ color: data.current_window ? '#000' : getMainColor(), marginTop: rpxToPx(30) }}>{data.title}</View>
  156. <View className="h30" style={{ marginTop: rpxToPx(12) }}>{headerDesc()}</View>
  157. {
  158. data.next && <View className="result_next">
  159. <View className="result_top_line" />
  160. <View className="next_target">
  161. <NewButton
  162. type={NewButtonType.link}
  163. title={nextTitle()}
  164. onClick={() => {
  165. setShowSetting(true)
  166. }}
  167. >
  168. <View style={{marginRight:rpxToPx(8)}}>
  169. {
  170. data.next.reminder ? <IconNotification color={MainColorType.link} width={rpxToPx(26)} /> :
  171. <IconNotificationOff color={MainColorType.link} width={rpxToPx(26)} />
  172. }
  173. </View>
  174. </NewButton>
  175. </View>
  176. </View>
  177. }
  178. {
  179. data.current_window && <View className="result_next" style={{ alignItems: 'center' }}>
  180. <View className="result_top_line" />
  181. <StatusIndicator
  182. text={statusText()}
  183. type={StatusType.normal}
  184. color={getThemeColor(data.current_window)}
  185. fontColor={MainColorType.g01} />
  186. </View>
  187. }
  188. <View style={{ flex: 1 }} />
  189. <View className="result_footer">
  190. <NewButton
  191. type={NewButtonType.gray}
  192. width={rpxToPx(400)}
  193. height={rpxToPx(96)}
  194. title="Done"
  195. bold
  196. onClick={() => {
  197. if (data.current_window) {
  198. Taro.navigateBack({
  199. delta: 7
  200. })
  201. }
  202. else {
  203. Taro.navigateBack()
  204. }
  205. if (data.status_change){
  206. if (data.status_change.previous != data.status_change.current) {
  207. //灵动岛弹窗
  208. dispatch(setShowActionTip({
  209. isShow: true,
  210. isCompleted: false
  211. }))
  212. }
  213. }
  214. }}
  215. />
  216. {
  217. showSwitchBtn() && <View style={{ marginTop: rpxToPx(36), width: rpxToPx(400), height: rpxToPx(72), display: 'flex' }}>
  218. <NewButton
  219. type={NewButtonType.link}
  220. title={swithBtnText()}
  221. onClick={tapSwitch}
  222. />
  223. </View>
  224. }
  225. </View>
  226. {
  227. showSetting && <NewModal
  228. themeColor={getThemeColor(data.window)}
  229. title='开启提醒'
  230. dismiss={() => setShowSetting(false)}
  231. confirm={() => setShowSetting(false)}
  232. >
  233. <Card>
  234. <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', paddingRight: rpxToPx(40) }}>
  235. <View className="setting_item" style={{ flex: 1 }}>
  236. <View style={{ flex: 1 }}>
  237. <View className="h24" style={{ color: MainColorType.g01 }}>{data.next.time}</View>
  238. <View className="h34">{data.next.title}</View>
  239. </View>
  240. </View>
  241. <Switch color={getThemeColor(data.window)} checked={data.next.reminder} onChange={changeReminder} />
  242. </View>
  243. </Card>
  244. </NewModal>
  245. }
  246. </View>
  247. }