import { View, Text } from '@tarojs/components' import './fast_sleep_detail_card.scss' import { MainColorType } from '@/context/themes/color' import { TimeFormatter } from '@/utils/time_format' import { rpxToPx } from '@/utils/tools' export default function FastSleepDetailCard(props: { data: any }) { function total() { const { fast } = props.data return diffentTime(fast.period.start_time, fast.period.end_time) } function process() { const { fast, status } = props.data if (status == 'OG2_NO1' || status == 'WFS') { return '-' } return TimeFormatter.countdown(fast.real.start_timestamp) } function step1() { 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 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) } return 详情 断食 {process()}/{total()} 睡前断食 {step1()}/{total1()} 睡眠期间断食 {step2()}/{total2()} 起床后断食 {step3()}/{total3()} }