|
|
@@ -0,0 +1,232 @@
|
|
|
+import { View, Image, Text } from "@tarojs/components";
|
|
|
+import './fast_sleep_popup.scss'
|
|
|
+import Card from "./card";
|
|
|
+import NewButton, { NewButtonType } from "../base/new_button";
|
|
|
+import { rpxToPx } from "@/utils/tools";
|
|
|
+import { useTranslation } from "react-i18next";
|
|
|
+import { useSelector } from "react-redux";
|
|
|
+import { MainColorType } from "@/context/themes/color";
|
|
|
+import { TimeFormatter } from "@/utils/time_format";
|
|
|
+import StatusIndicator, { StatusType } from "../base/status_indicator";
|
|
|
+import { IconCheck } from "@/components/basic/Icons";
|
|
|
+
|
|
|
+export default function FastSleepPopup(props: { close: any, data: any }) {
|
|
|
+ const health = useSelector((state: any) => state.health);
|
|
|
+ const { t } = useTranslation()
|
|
|
+
|
|
|
+ function total() {
|
|
|
+ const { fast } = props.data
|
|
|
+ return diffentTime(fast.period.start_time, fast.period.end_time)
|
|
|
+ }
|
|
|
+
|
|
|
+ function total1() {
|
|
|
+ const { fast, sleep } = props.data
|
|
|
+ return diffentTime(fast.period.start_time, sleep.period.start_time)
|
|
|
+ }
|
|
|
+
|
|
|
+ function total2() {
|
|
|
+ const { sleep } = props.data
|
|
|
+ return diffentTime(sleep.period.start_time, sleep.period.end_time)
|
|
|
+ }
|
|
|
+
|
|
|
+ function total3() {
|
|
|
+ const { fast, sleep } = props.data
|
|
|
+ return diffentTime(sleep.period.end_time, fast.period.end_time)
|
|
|
+ }
|
|
|
+
|
|
|
+ function step1() {
|
|
|
+ if (health.fast_with_sleep.status == 'OG2_MISALIGNED') {
|
|
|
+ return '-'
|
|
|
+ }
|
|
|
+ const { fast, sleep, status } = props.data
|
|
|
+ if (status == 'WFS') {
|
|
|
+ return ('-')
|
|
|
+ }
|
|
|
+ else if (status == 'OG1') {
|
|
|
+ return TimeFormatter.countdown(fast.real.start_timestamp)
|
|
|
+ }
|
|
|
+ else if (status == 'OG2_NO1') {
|
|
|
+ return ('-')
|
|
|
+ }
|
|
|
+ return TimeFormatter.calculateTimeDifference(fast.real.start_timestamp, sleep.real.start_timestamp)
|
|
|
+ }
|
|
|
+
|
|
|
+ function step2() {
|
|
|
+ const { fast, sleep, status } = props.data
|
|
|
+ if (status == 'WFS' || status == 'OG1') {
|
|
|
+ return '-'
|
|
|
+ }
|
|
|
+
|
|
|
+ if (status == 'OG2_NO1' || status == 'OG2') {
|
|
|
+ return TimeFormatter.countdown(sleep.real.start_timestamp)
|
|
|
+ }
|
|
|
+ else if (status == 'OG3') {
|
|
|
+ return TimeFormatter.calculateTimeDifference(sleep.real.start_timestamp, sleep.real.end_timestamp)
|
|
|
+ }
|
|
|
+ return TimeFormatter.calculateTimeDifference(sleep.target.start_timestamp, sleep.target.end_timestamp)
|
|
|
+ }
|
|
|
+
|
|
|
+ function step3() {
|
|
|
+ const { fast, sleep, status } = props.data
|
|
|
+ if (status == 'WFS' || status == 'OG1' || status == 'OG2_NO1' || status == 'OG2') {
|
|
|
+ return '-'
|
|
|
+ }
|
|
|
+ if (status == 'OG3') {
|
|
|
+ return TimeFormatter.countdown(sleep.real.end_timestamp)
|
|
|
+ }
|
|
|
+ return TimeFormatter.calculateTimeDifference(sleep.target.end_timestamp, fast.target.end_timestamp)
|
|
|
+ }
|
|
|
+
|
|
|
+ function diffentTime(time2, time1) {
|
|
|
+ var duration = 0
|
|
|
+
|
|
|
+ var t1 = parseInt(time1.split(':')[0]) * 60 + parseInt(time1.split(':')[1])
|
|
|
+ var t2 = parseInt(time2.split(':')[0]) * 60 + parseInt(time2.split(':')[1])
|
|
|
+ duration = t1 - t2 >= 0 ? (t1 - t2) * 60 * 1000 : (t1 - t2) * 60 * 1000 + 24 * 3600 * 1000
|
|
|
+
|
|
|
+ var now = new Date().getTime()
|
|
|
+ return TimeFormatter.calculateTimeDifference(now, now + duration)
|
|
|
+ }
|
|
|
+
|
|
|
+ function beforeStatus() {
|
|
|
+ const { status } = props.data
|
|
|
+ var type = StatusType.normal
|
|
|
+ if (status == 'WFS') {
|
|
|
+ type = StatusType.normal
|
|
|
+ }
|
|
|
+ else if (status == 'OG1') {
|
|
|
+ type = StatusType.ing
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ type = StatusType.img
|
|
|
+ }
|
|
|
+ return type
|
|
|
+ }
|
|
|
+
|
|
|
+ function beforeSleep() {
|
|
|
+ const type = beforeStatus()
|
|
|
+ return <StatusIndicator type={type}
|
|
|
+ color={MainColorType.fast}
|
|
|
+ fontColor={MainColorType.g01}
|
|
|
+ text={t('health.fast_befor_bed')}
|
|
|
+ >
|
|
|
+ {
|
|
|
+ type == StatusType.img && <Image style={{ width: rpxToPx(20), height: rpxToPx(20) }} src={require('@assets/_health/checked.png')} />
|
|
|
+ }
|
|
|
+ </StatusIndicator>
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function ingStatus() {
|
|
|
+ const { status } = props.data
|
|
|
+ var type = StatusType.normal
|
|
|
+ if (status == 'WFS' || status == 'OG1') {
|
|
|
+ type = StatusType.normal
|
|
|
+ }
|
|
|
+ else if (status == 'OG2') {
|
|
|
+ type = StatusType.ing
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ type = StatusType.img
|
|
|
+ }
|
|
|
+ return type;
|
|
|
+ }
|
|
|
+
|
|
|
+ function sleeping() {
|
|
|
+ const type = ingStatus()
|
|
|
+ return <StatusIndicator type={type}
|
|
|
+ color={MainColorType.sleep}
|
|
|
+ fontColor={MainColorType.g01}
|
|
|
+ text={t('health.fast_while_sleep')}
|
|
|
+ >
|
|
|
+ {
|
|
|
+ type == StatusType.img && <Image style={{ width: rpxToPx(20), height: rpxToPx(20) }} src={require('@assets/_health/checked.png')} />
|
|
|
+ }
|
|
|
+ </StatusIndicator>
|
|
|
+ }
|
|
|
+
|
|
|
+ function afterStatus() {
|
|
|
+ const { status } = props.data
|
|
|
+ var type = StatusType.normal
|
|
|
+ if (status == 'WFS' || status == 'OG1' || status == 'OG2') {
|
|
|
+ type = StatusType.normal
|
|
|
+ }
|
|
|
+ else if (status == 'OG3') {
|
|
|
+ type = StatusType.ing
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ type = StatusType.img
|
|
|
+ }
|
|
|
+ return type;
|
|
|
+ }
|
|
|
+
|
|
|
+ function afterSleep() {
|
|
|
+ const type = afterStatus()
|
|
|
+ return <StatusIndicator type={type}
|
|
|
+ color={MainColorType.fast}
|
|
|
+ fontColor={MainColorType.g01}
|
|
|
+ text={t('health.fast_after_sleep')}
|
|
|
+ >
|
|
|
+ {
|
|
|
+ type == StatusType.img && <Image style={{ width: rpxToPx(20), height: rpxToPx(20) }} src={require('@assets/_health/checked.png')} />
|
|
|
+ }
|
|
|
+ </StatusIndicator>
|
|
|
+ }
|
|
|
+
|
|
|
+ return <View className="popup_container1">
|
|
|
+ <View className="fast_sleep_content">
|
|
|
+ <View className="h34 bold">{t('health.my_fast_journal')}</View>
|
|
|
+ <View className="h24 bold g01" style={{ marginTop: rpxToPx(8) }}>{t('health.my_fast_duration', { time: total() })}</View>
|
|
|
+ <View className="pop_line1" />
|
|
|
+ <View className="pop_steps">
|
|
|
+ {
|
|
|
+ beforeSleep()
|
|
|
+ }
|
|
|
+ <View style={{ display: 'flex', flexDirection: 'row' }}>
|
|
|
+ <View style={{
|
|
|
+ marginLeft: rpxToPx(12.5),
|
|
|
+ marginRight: rpxToPx(24),
|
|
|
+ width: 1, height: rpxToPx(103),
|
|
|
+ backgroundColor: (ingStatus() == StatusType.ing || afterStatus() == StatusType.ing) ? MainColorType.g01 : MainColorType.g03
|
|
|
+ }} />
|
|
|
+ <Text className="bold h24"
|
|
|
+ style={{ marginTop: rpxToPx(12), color: beforeStatus() == StatusType.ing ? MainColorType.fast : '#000' }}><Text className="h34">{step1()}</Text> / {total1()}</Text>
|
|
|
+ </View>
|
|
|
+ {
|
|
|
+ sleeping()
|
|
|
+ }
|
|
|
+ <View style={{ display: 'flex', flexDirection: 'row' }}>
|
|
|
+ <View style={{
|
|
|
+ marginLeft: rpxToPx(12.5),
|
|
|
+ marginRight: rpxToPx(24),
|
|
|
+ width: 1, height: rpxToPx(103),
|
|
|
+ backgroundColor: afterStatus() == StatusType.ing ? MainColorType.g01 : MainColorType.g03
|
|
|
+ }} />
|
|
|
+ <Text className="bold h24"
|
|
|
+ style={{ marginTop: rpxToPx(12), color: ingStatus() == StatusType.ing ? MainColorType.sleep : '#000' }}><Text className="h34">{step2()}</Text> / {total2()}</Text>
|
|
|
+ </View>
|
|
|
+ {
|
|
|
+ afterSleep()
|
|
|
+ }
|
|
|
+ <View style={{ display: 'flex', flexDirection: 'row' }}>
|
|
|
+ <View style={{
|
|
|
+ marginLeft: rpxToPx(12.5),
|
|
|
+ marginRight: rpxToPx(24.5),
|
|
|
+ width: 1, height: rpxToPx(103),
|
|
|
+ backgroundColor: 'transparent'
|
|
|
+ }} />
|
|
|
+ <Text className="bold h24"
|
|
|
+ style={{ marginTop: rpxToPx(12), color: afterStatus() == StatusType.ing ? MainColorType.fast : '#000' }}><Text className="h34">{step3()}</Text> / {total3()}</Text>
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ <NewButton
|
|
|
+ type={NewButtonType.fill}
|
|
|
+ color={MainColorType.fast}
|
|
|
+ width={rpxToPx(440)}
|
|
|
+ height={rpxToPx(96)}
|
|
|
+ title={t('health.ok')}
|
|
|
+ onClick={props.close}
|
|
|
+ />
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+}
|