|
|
@@ -1,5 +1,189 @@
|
|
|
-import { View } from "@tarojs/components";
|
|
|
+import { View, Image, Text, Switch } from "@tarojs/components";
|
|
|
+import Taro, { useRouter } from "@tarojs/taro";
|
|
|
+import './post_result.scss'
|
|
|
+import { getThemeColor } from "@/features/health/hooks/health_hooks";
|
|
|
+import { rpxToPx } from "@/utils/tools";
|
|
|
+import NewButton, { NewButtonType } from "../base/new_button";
|
|
|
+import { IconCheck, IconNotificationOff } from "@/components/basic/Icons";
|
|
|
+import { MainColorType } from "@/context/themes/color";
|
|
|
+import { useState } from "react";
|
|
|
+import dayjs from "dayjs";
|
|
|
+import { useDispatch } from "react-redux";
|
|
|
+import { setMode } from "@/store/health";
|
|
|
+import NewModal from "../base/new_modal";
|
|
|
+import Card from "../components/card";
|
|
|
|
|
|
-export default function PostResult(){
|
|
|
- return <View></View>
|
|
|
+let useRoute;
|
|
|
+let useNavigation;
|
|
|
+if (process.env.TARO_ENV == 'rn') {
|
|
|
+ useRoute = require("@react-navigation/native").useRoute
|
|
|
+ useNavigation = require("@react-navigation/native").useNavigation
|
|
|
+}
|
|
|
+export default function PostResult() {
|
|
|
+ let router
|
|
|
+ let navigation;
|
|
|
+ if (useNavigation) {
|
|
|
+ navigation = useNavigation()
|
|
|
+ }
|
|
|
+
|
|
|
+ if (process.env.TARO_ENV == 'rn') {
|
|
|
+ router = useRoute()
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ router = useRouter()
|
|
|
+ }
|
|
|
+
|
|
|
+ const [data, setData] = useState(JSON.parse(router.params.data))
|
|
|
+ const [showSetting, setShowSetting] = useState(false)
|
|
|
+ const dispatch = useDispatch()
|
|
|
+ console.log(JSON.parse(router.params.data))
|
|
|
+
|
|
|
+ function getMainColor() {
|
|
|
+ return getThemeColor(data.window)
|
|
|
+ }
|
|
|
+
|
|
|
+ function nextTitle() {
|
|
|
+ const today = dayjs();
|
|
|
+
|
|
|
+ var timestamp = data.next.timestamp
|
|
|
+ const dt = dayjs(timestamp);
|
|
|
+ const yesterday = today.subtract(1, 'day');
|
|
|
+ const tomorrow = today.subtract(-1, 'day');
|
|
|
+ var date = ''
|
|
|
+ var time = dt.format('HH:mm')
|
|
|
+ if (dt.isSame(today, 'day')) {
|
|
|
+ date = '今天';
|
|
|
+ } else if (dt.isSame(yesterday, 'day')) {
|
|
|
+ date = '昨天';
|
|
|
+ } else if (dt.isSame(tomorrow, 'day')) {
|
|
|
+ date = '明天';
|
|
|
+ } else {
|
|
|
+ date = dt.format('MM-DD');
|
|
|
+ }
|
|
|
+ return date + ' ' + time + ' ' + data.next.title
|
|
|
+ }
|
|
|
+
|
|
|
+ function showSwitchBtn() {
|
|
|
+ if (data.extra && data.extra.fast_type == 'LF') return false;
|
|
|
+ return data.schedule_completed
|
|
|
+ }
|
|
|
+
|
|
|
+ function swithBtnText() {
|
|
|
+ switch (data.window) {
|
|
|
+ case 'FAST':
|
|
|
+ return 'Switch to Eat'
|
|
|
+ case 'EAT':
|
|
|
+ return 'Switch to Fast'
|
|
|
+ case 'ACTIVE':
|
|
|
+ return 'Switch to Sleep'
|
|
|
+ case 'SLEEP':
|
|
|
+ return 'Swtich to Active'
|
|
|
+ }
|
|
|
+ return ''
|
|
|
+ }
|
|
|
+
|
|
|
+ function tapSwitch() {
|
|
|
+ switch (data.window) {
|
|
|
+ case 'FAST':
|
|
|
+ dispatch(setMode('EAT'))
|
|
|
+ break
|
|
|
+ case 'EAT':
|
|
|
+ dispatch(setMode('FAST'))
|
|
|
+ break
|
|
|
+ case 'ACTIVE':
|
|
|
+ dispatch(setMode('SLEEP'))
|
|
|
+ break
|
|
|
+ case 'SLEEP':
|
|
|
+ dispatch(setMode('ACTIVE'))
|
|
|
+ break
|
|
|
+ }
|
|
|
+ Taro.navigateBack()
|
|
|
+ }
|
|
|
+
|
|
|
+ function headerIcon() {
|
|
|
+ if (data.images) {
|
|
|
+ return <View className="result_icon_bg">
|
|
|
+ <Image className="result_icon_bg" mode="aspectFill" src={data.images[0]} />
|
|
|
+ <View className="result_icon_small" style={{ backgroundColor: getMainColor() }}>
|
|
|
+ <IconCheck color="#fff" width={rpxToPx(18)} height={rpxToPx(18)} />
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+
|
|
|
+ if (data.scenario == 'MOVE') {
|
|
|
+ return <Image className="result_icon_bg" mode="aspectFill" src={require('@assets/_health/sit.png')} />
|
|
|
+ }
|
|
|
+ return <View className="result_icon_bg" style={{ backgroundColor: getMainColor() }}>
|
|
|
+ <IconCheck color="#fff" width={rpxToPx(40)} height={rpxToPx(40)} />
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+
|
|
|
+ return <View className="post_result_container">
|
|
|
+ {
|
|
|
+ headerIcon()
|
|
|
+ }
|
|
|
+
|
|
|
+ <View className="h50 bold" style={{ color: getMainColor(), marginTop: rpxToPx(30) }}>{data.title}</View>
|
|
|
+ <View className="h30" style={{ marginTop: rpxToPx(12) }}>{data.description}</View>
|
|
|
+ {
|
|
|
+ data.next && <View className="result_next">
|
|
|
+ <View className="result_top_line" />
|
|
|
+ <View className="next_target">
|
|
|
+ <NewButton
|
|
|
+ type={NewButtonType.link}
|
|
|
+ title={nextTitle()}
|
|
|
+ onClick={() => {
|
|
|
+ setShowSetting(true)
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <IconNotificationOff color={MainColorType.link} width={rpxToPx(26)} />
|
|
|
+ </NewButton>
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+
|
|
|
+ <View style={{ flex: 1 }} />
|
|
|
+ <View className="result_footer">
|
|
|
+ <NewButton
|
|
|
+ type={NewButtonType.gray}
|
|
|
+ width={rpxToPx(400)}
|
|
|
+ height={rpxToPx(96)}
|
|
|
+ title="Done"
|
|
|
+ onClick={() => {
|
|
|
+ Taro.navigateBack()
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ {
|
|
|
+ showSwitchBtn() && <View style={{ marginTop: rpxToPx(36), width: rpxToPx(400), height: rpxToPx(72), display: 'flex' }}>
|
|
|
+ <NewButton
|
|
|
+ type={NewButtonType.link}
|
|
|
+ title={swithBtnText()}
|
|
|
+ onClick={tapSwitch}
|
|
|
+ />
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ </View>
|
|
|
+ {
|
|
|
+ showSetting && <NewModal
|
|
|
+ themeColor={getMainColor()}
|
|
|
+ title='开启提醒'
|
|
|
+ dismiss={()=>setShowSetting(false)}
|
|
|
+ confirm={()=>setShowSetting(false)}
|
|
|
+ >
|
|
|
+ <View style={{marginBottom:rpxToPx(72)}}>
|
|
|
+ <Card>
|
|
|
+ <View className="setting_item">
|
|
|
+ <View style={{flex:1}}>
|
|
|
+ <View className="h24" style={{color:MainColorType.g01}}>{dayjs(data.next.timestamp).format('HH:mm')}</View>
|
|
|
+ <View className="h34">{data.next.title}</View>
|
|
|
+ </View>
|
|
|
+ <Switch color={getMainColor()}/>
|
|
|
+ </View>
|
|
|
+ </Card>
|
|
|
+ </View>
|
|
|
+ </NewModal>
|
|
|
+ }
|
|
|
+ </View>
|
|
|
}
|