|
@@ -12,6 +12,8 @@ import { useRouter } from "@tarojs/taro";
|
|
|
import Card from "../components/card";
|
|
import Card from "../components/card";
|
|
|
import { MainColorType } from "@/context/themes/color";
|
|
import { MainColorType } from "@/context/themes/color";
|
|
|
import Taro from "@tarojs/taro";
|
|
import Taro from "@tarojs/taro";
|
|
|
|
|
+import { clockTimes, fastWithSleep } from "@/services/health";
|
|
|
|
|
+import NewDurationPicker, { DurationPickerType } from "../base/new_durationpicker";
|
|
|
|
|
|
|
|
let useRoute;
|
|
let useRoute;
|
|
|
let useNavigation;
|
|
let useNavigation;
|
|
@@ -38,14 +40,14 @@ export default function LogTime() {
|
|
|
const isSingle = router.params.single == '1'
|
|
const isSingle = router.params.single == '1'
|
|
|
const isFast = router.params.window == 'FAST'
|
|
const isFast = router.params.window == 'FAST'
|
|
|
const isStart = router.params.is_start == '1'
|
|
const isStart = router.params.is_start == '1'
|
|
|
- const data = JSON.parse(router.params.data)
|
|
|
|
|
|
|
+ const [data, setData] = useState<any>(null)
|
|
|
const health = useSelector((state: any) => state.health);
|
|
const health = useSelector((state: any) => state.health);
|
|
|
- const [time, setTime] = useState(dayjs().format('HH:mm'))
|
|
|
|
|
- const [isToday, setIsToday] = useState(true)
|
|
|
|
|
const [showGoal, setShowGoal] = useState(false)
|
|
const [showGoal, setShowGoal] = useState(false)
|
|
|
const tapIndex = router.params.index ?? 0
|
|
const tapIndex = router.params.index ?? 0
|
|
|
|
|
|
|
|
- const [expandIndex, setExpandIndex] = useState(0)
|
|
|
|
|
|
|
+ const [expandIndex, setExpandIndex] = useState(tapIndex)
|
|
|
|
|
+ const [array, setArray] = useState<any>([])
|
|
|
|
|
+ const [loaded, setLoaded] = useState(false)
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
if (isSingle) {
|
|
if (isSingle) {
|
|
@@ -61,8 +63,113 @@ export default function LogTime() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ loadData()
|
|
|
|
|
+
|
|
|
}, [])
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
+ function loadData() {
|
|
|
|
|
+ fastWithSleep().then(res => {
|
|
|
|
|
+ setData(res)
|
|
|
|
|
+ initDatas(res)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function initDatas(res = data) {
|
|
|
|
|
+ const { fast, sleep } = res
|
|
|
|
|
+ var list: any = []
|
|
|
|
|
+ if (isSingle) {
|
|
|
|
|
+ var timeline: any;
|
|
|
|
|
+ if (isFast) {
|
|
|
|
|
+ timeline = isStart ? fast.timeline[0] : fast.timeline[1]
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ timeline = isStart ? sleep.timeline[0] : sleep.timeline[1]
|
|
|
|
|
+ }
|
|
|
|
|
+ list.push({
|
|
|
|
|
+ event_id: timeline.event_id,
|
|
|
|
|
+ schedule_id: timeline.schedule_id,
|
|
|
|
|
+ time: dayjs().format('HH:mm'),
|
|
|
|
|
+ today: true,
|
|
|
|
|
+ extra: {
|
|
|
|
|
+ set_time: new Date().getTime(),
|
|
|
|
|
+ confirm_time: new Date().getTime()
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ setExpandIndex(0)
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ for (var i = 0; i <= tapIndex; i++) {
|
|
|
|
|
+ var timeline: any;
|
|
|
|
|
+ if (i == 0 || i == 3) {
|
|
|
|
|
+ timeline = i == 0 ? fast.timeline[0] : fast.timeline[1]
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ timeline = i == 1 ? sleep.timeline[0] : sleep.timeline[1]
|
|
|
|
|
+ }
|
|
|
|
|
+ list.push({
|
|
|
|
|
+ event_id: timeline.event_id,
|
|
|
|
|
+ schedule_id: timeline.schedule_id,
|
|
|
|
|
+ time: dayjs().format('HH:mm'),
|
|
|
|
|
+ today: true,
|
|
|
|
|
+ extra: {
|
|
|
|
|
+ set_time: new Date().getTime(),
|
|
|
|
|
+ confirm_time: new Date().getTime()
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //逆推初始化时间
|
|
|
|
|
+ var fastStartTime = new Date().getTime()
|
|
|
|
|
+ var fastEndTime = new Date().getTime()
|
|
|
|
|
+ var sleepStartTime = new Date().getTime()
|
|
|
|
|
+ var sleepEndTime = new Date().getTime()
|
|
|
|
|
+
|
|
|
|
|
+ fastStartTime = fastEndTime - fast.target.duration
|
|
|
|
|
+
|
|
|
|
|
+ var fastEndtoWakeDuration = 0
|
|
|
|
|
+ var time1 = fast.period.end_time
|
|
|
|
|
+ var time2 = sleep.period.end_time
|
|
|
|
|
+
|
|
|
|
|
+ var t1 = parseInt(time1.split(':')[0])*60+parseInt(time1.split(':')[1])
|
|
|
|
|
+ var t2 = parseInt(time2.split(':')[0])*60+parseInt(time2.split(':')[1])
|
|
|
|
|
+ fastEndtoWakeDuration = t1-t2>0?(t1-t2)*60*1000:(t1-t2)*60*1000+24*3600*1000
|
|
|
|
|
+
|
|
|
|
|
+ sleepEndTime = fastEndTime - fastEndtoWakeDuration//(fast.target.end_timestamp-sleep.target.end_timestamp)
|
|
|
|
|
+ sleepStartTime = sleepEndTime - sleep.target.duration
|
|
|
|
|
+
|
|
|
|
|
+ var isConflict = false;
|
|
|
|
|
+ if (fast.real && fast.real.start_timestamp && fast.real.start_timestamp > fastStartTime) {
|
|
|
|
|
+ isConflict = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (sleep.real && sleep.real.start_timestamp && sleep.real.start_timestamp > sleepStartTime) {
|
|
|
|
|
+ isConflict = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (sleep.real && sleep.real.end_timestamp && sleep.real.end_timestamp > sleepEndTime) {
|
|
|
|
|
+ isConflict = true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!isConflict) {
|
|
|
|
|
+ var fastStartToday = new Date().getDate() == new Date(fastStartTime).getDate()
|
|
|
|
|
+ list[0].today = fastStartToday
|
|
|
|
|
+ list[0].time = dayjs(fastStartTime).format('HH:mm')
|
|
|
|
|
+
|
|
|
|
|
+ var sleepStartToday = new Date().getDate() == new Date(sleepStartTime).getDate()
|
|
|
|
|
+ list[1].today = sleepStartToday
|
|
|
|
|
+ list[1].time = dayjs(sleepStartTime).format('HH:mm')
|
|
|
|
|
+
|
|
|
|
|
+ var sleepEndToday = new Date().getDate() == new Date(sleepEndTime).getDate()
|
|
|
|
|
+ list[2].today = sleepEndToday
|
|
|
|
|
+ list[2].time = dayjs(sleepEndTime).format('HH:mm')
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ setArray(list)
|
|
|
|
|
+
|
|
|
|
|
+ setLoaded(true)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
function footerBtnColor() {
|
|
function footerBtnColor() {
|
|
|
if (isSingle) {
|
|
if (isSingle) {
|
|
|
return isFast ? MainColorType.fast : MainColorType.sleep
|
|
return isFast ? MainColorType.fast : MainColorType.sleep
|
|
@@ -70,33 +177,134 @@ export default function LogTime() {
|
|
|
return MainColorType.fast
|
|
return MainColorType.fast
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ function getTimestamp(obj) {
|
|
|
|
|
+ var time = obj.time
|
|
|
|
|
+ var hour = parseInt(time.split(':')[0])
|
|
|
|
|
+ var minute = parseInt(time.split(':')[1])
|
|
|
|
|
+ var today = obj.today
|
|
|
|
|
+ var now = new Date()
|
|
|
|
|
+ now.setHours(hour)
|
|
|
|
|
+ now.setMinutes(minute)
|
|
|
|
|
+ var timestamp = now.getTime()
|
|
|
|
|
+ if (!today) {
|
|
|
|
|
+ timestamp -= 24 * 3600 * 1000
|
|
|
|
|
+ }
|
|
|
|
|
+ return timestamp
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function commit() {
|
|
|
|
|
+ var list: any = []
|
|
|
|
|
+ if (isSingle) {
|
|
|
|
|
+ var obj = array[0]
|
|
|
|
|
+ var timestamp = getTimestamp(obj)
|
|
|
|
|
+ var params: any = {
|
|
|
|
|
+ schedule_id: obj.schedule_id,
|
|
|
|
|
+ extra: obj.extra,
|
|
|
|
|
+ date: dayjs(timestamp).format('YYYYMMDD'),
|
|
|
|
|
+ timestamp: timestamp,
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isStart) {
|
|
|
|
|
+ params.duration = isFast ? data.fast.target.duration : data.sleep.target.duration
|
|
|
|
|
+ }
|
|
|
|
|
+ list.push(params)
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ const { status } = data
|
|
|
|
|
+ for (var i = 0; i <= tapIndex; i++) {
|
|
|
|
|
+ if ((status == 'OG1' || status == 'OG2' || status == 'OG3') && i == 0) {
|
|
|
|
|
+ }
|
|
|
|
|
+ else if ((status == 'OG2' || status == 'OG3' || status == 'OG2_NO1') && i == 1) {
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (status == 'OG3' && i == 2) {
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ var obj = array[i]
|
|
|
|
|
+ var timestamp = getTimestamp(obj)
|
|
|
|
|
+ list.push({
|
|
|
|
|
+ schedule_id: obj.schedule_id,
|
|
|
|
|
+ extra: obj.extra,
|
|
|
|
|
+ date: dayjs(timestamp).format('YYYYMMDD'),
|
|
|
|
|
+ timestamp: timestamp,
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ clockTimes({
|
|
|
|
|
+ check_items: list
|
|
|
|
|
+ }).then(res => {
|
|
|
|
|
+ global.refreshWindow()
|
|
|
|
|
+ if (global.refreshFastSleep)
|
|
|
|
|
+ global.refreshFastSleep()
|
|
|
|
|
+ Taro.navigateBack({
|
|
|
|
|
+ delta: 1
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function changeToScheduleTime(schedule_time, index) {
|
|
|
|
|
+ var nowTime = parseInt(dayjs().format('HHmm'))
|
|
|
|
|
+ var scheduleTime = parseInt(schedule_time.replace(':', ''))
|
|
|
|
|
+ var isToday = true
|
|
|
|
|
+ if (scheduleTime > nowTime) {
|
|
|
|
|
+ isToday = false
|
|
|
|
|
+ }
|
|
|
|
|
+ var list = JSON.parse(JSON.stringify(array))
|
|
|
|
|
+ list[index].today = isToday
|
|
|
|
|
+ list[index].time = schedule_time
|
|
|
|
|
+ setArray(list)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function durationTime() {
|
|
|
|
|
+ const { fast, sleep } = data
|
|
|
|
|
+ var seconds = isFast ? fast.target.duration / 1000 : sleep.target.duration / 1000
|
|
|
|
|
+ var hour = Math.floor(seconds / 3600)
|
|
|
|
|
+ var minutes = Math.floor((seconds % 3600) / 60)
|
|
|
|
|
+ var str = ''
|
|
|
|
|
+ if (hour > 0) {
|
|
|
|
|
+ str = hour + '小时'
|
|
|
|
|
+ }
|
|
|
|
|
+ if (minutes > 0) {
|
|
|
|
|
+ str += minutes + '分钟'
|
|
|
|
|
+ }
|
|
|
|
|
+ return str
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
function logItem(index: number, iFast: boolean, iStart: boolean, showLine: boolean) {
|
|
function logItem(index: number, iFast: boolean, iStart: boolean, showLine: boolean) {
|
|
|
- const {fast,sleep} = data
|
|
|
|
|
|
|
+ const { fast, sleep } = data
|
|
|
var schedule_time = ''
|
|
var schedule_time = ''
|
|
|
- if (iFast){
|
|
|
|
|
- schedule_time = iStart?fast.period.start_time:fast.period.end_time
|
|
|
|
|
|
|
+ var title = ''
|
|
|
|
|
+ if (iFast) {
|
|
|
|
|
+ schedule_time = iStart ? fast.period.start_time : fast.period.end_time
|
|
|
|
|
+ title = iStart ? 'Fast starts' : 'Fast ends'
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
- schedule_time = iStart?sleep.period.start_time:sleep.period.end_time
|
|
|
|
|
|
|
+ schedule_time = iStart ? sleep.period.start_time : sleep.period.end_time
|
|
|
|
|
+ title = iStart ? 'Bedtime' : 'Wake up'
|
|
|
}
|
|
}
|
|
|
return <View style={{ position: 'relative' }}>
|
|
return <View style={{ position: 'relative' }}>
|
|
|
<View className="card_header">
|
|
<View className="card_header">
|
|
|
- <View style={{ flex: 1 }} />
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ isSingle ? <View style={{ flex: 1 }} /> :
|
|
|
|
|
+ <View className="h34" style={{ flex: 1 }}>{title}</View>
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
<NewButton
|
|
<NewButton
|
|
|
type={NewButtonType.gray}
|
|
type={NewButtonType.gray}
|
|
|
- title={isToday ? "Today" : "Yesterday"}
|
|
|
|
|
|
|
+ title={array[index].today ? "Today" : "Yesterday"}
|
|
|
fontSize={rpxToPx(34)}
|
|
fontSize={rpxToPx(34)}
|
|
|
width={rpxToPx(196)}
|
|
width={rpxToPx(196)}
|
|
|
height={rpxToPx(84)}
|
|
height={rpxToPx(84)}
|
|
|
onClick={() => {
|
|
onClick={() => {
|
|
|
- setIsToday(!isToday)
|
|
|
|
|
|
|
+ var list = JSON.parse(JSON.stringify(array))
|
|
|
|
|
+ list[index].today = !list[index].today
|
|
|
|
|
+ setArray(list)
|
|
|
}}
|
|
}}
|
|
|
/>
|
|
/>
|
|
|
<View style={{ width: rpxToPx(12) }} />
|
|
<View style={{ width: rpxToPx(12) }} />
|
|
|
<NewButton
|
|
<NewButton
|
|
|
- type={NewButtonType.alpha}
|
|
|
|
|
- color={iFast?MainColorType.fast:MainColorType.sleep}
|
|
|
|
|
- title={time}
|
|
|
|
|
|
|
+ type={expandIndex == index ? NewButtonType.alpha : NewButtonType.gray}
|
|
|
|
|
+ color={iFast ? MainColorType.fast : MainColorType.sleep}
|
|
|
|
|
+ title={array[index].time}
|
|
|
fontSize={rpxToPx(34)}
|
|
fontSize={rpxToPx(34)}
|
|
|
width={rpxToPx(196)}
|
|
width={rpxToPx(196)}
|
|
|
height={rpxToPx(84)}
|
|
height={rpxToPx(84)}
|
|
@@ -104,17 +312,21 @@ export default function LogTime() {
|
|
|
setExpandIndex(index)
|
|
setExpandIndex(index)
|
|
|
}}
|
|
}}
|
|
|
/>
|
|
/>
|
|
|
- <View style={{ flex: 1 }} />
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ isSingle && <View style={{ flex: 1 }} />
|
|
|
|
|
+ }
|
|
|
<View className='border_footer_line' />
|
|
<View className='border_footer_line' />
|
|
|
</View>
|
|
</View>
|
|
|
{
|
|
{
|
|
|
- expandIndex == index && <NewTimePicker time={time} onChange={(e) => {
|
|
|
|
|
- setTime(e)
|
|
|
|
|
- }} color={iFast?MainColorType.fast:MainColorType.sleep} />
|
|
|
|
|
|
|
+ expandIndex == index && <NewTimePicker time={array[index].time} onChange={(e) => {
|
|
|
|
|
+ var list = JSON.parse(JSON.stringify(array))
|
|
|
|
|
+ list[index].time = e
|
|
|
|
|
+ setArray(list)
|
|
|
|
|
+ }} color={iFast ? MainColorType.fast : MainColorType.sleep} />
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
{
|
|
{
|
|
|
- expandIndex == index && <View className='card_footer'>
|
|
|
|
|
|
|
+ expandIndex == index && <View className='card_footer' onClick={() => changeToScheduleTime(schedule_time, index)}>
|
|
|
<IconCalendar width={rpxToPx(24)} color='#5C7099' />
|
|
<IconCalendar width={rpxToPx(24)} color='#5C7099' />
|
|
|
<Text style={{ color: '#5C7099', marginLeft: rpxToPx(12), fontSize: rpxToPx(26) }}>Scheduled for {schedule_time}</Text>
|
|
<Text style={{ color: '#5C7099', marginLeft: rpxToPx(12), fontSize: rpxToPx(26) }}>Scheduled for {schedule_time}</Text>
|
|
|
</View>
|
|
</View>
|
|
@@ -128,7 +340,7 @@ export default function LogTime() {
|
|
|
|
|
|
|
|
function multiContent() {
|
|
function multiContent() {
|
|
|
const { status } = data
|
|
const { status } = data
|
|
|
- switch (parseInt(tapIndex+'')) {
|
|
|
|
|
|
|
+ switch (parseInt(tapIndex + '')) {
|
|
|
case 1:
|
|
case 1:
|
|
|
return <View style={{ position: 'relative' }}>
|
|
return <View style={{ position: 'relative' }}>
|
|
|
{
|
|
{
|
|
@@ -159,7 +371,7 @@ export default function LogTime() {
|
|
|
(status == 'WFS' || status == 'OG1') && logItem(1, false, true, true)
|
|
(status == 'WFS' || status == 'OG1') && logItem(1, false, true, true)
|
|
|
}
|
|
}
|
|
|
{
|
|
{
|
|
|
- (status == 'WFS' || status == 'OG1' || status == 'OG2'|| status == 'OG2_NO1') && logItem(2, false, false, true)
|
|
|
|
|
|
|
+ (status == 'WFS' || status == 'OG1' || status == 'OG2' || status == 'OG2_NO1') && logItem(2, false, false, true)
|
|
|
}
|
|
}
|
|
|
{
|
|
{
|
|
|
logItem(3, true, false, false)
|
|
logItem(3, true, false, false)
|
|
@@ -168,6 +380,9 @@ export default function LogTime() {
|
|
|
}
|
|
}
|
|
|
return <View style={{ position: 'relative' }}></View>
|
|
return <View style={{ position: 'relative' }}></View>
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if (!loaded) return <View />
|
|
|
|
|
+
|
|
|
return <View className="page_container">
|
|
return <View className="page_container">
|
|
|
<Card>
|
|
<Card>
|
|
|
{
|
|
{
|
|
@@ -199,10 +414,27 @@ export default function LogTime() {
|
|
|
<NewButton
|
|
<NewButton
|
|
|
type={NewButtonType.gray}
|
|
type={NewButtonType.gray}
|
|
|
height={rpxToPx(84)}
|
|
height={rpxToPx(84)}
|
|
|
- title="xxx"
|
|
|
|
|
- onClick={() => { }}
|
|
|
|
|
|
|
+ title={durationTime()}
|
|
|
|
|
+ onClick={() => { setExpandIndex(-1) }}
|
|
|
/>
|
|
/>
|
|
|
</View>
|
|
</View>
|
|
|
|
|
+ {
|
|
|
|
|
+ expandIndex == -1 && <NewDurationPicker
|
|
|
|
|
+ type={DurationPickerType.normal}
|
|
|
|
|
+ value={isFast ? data.fast.target.duration : data.sleep.target.duration}
|
|
|
|
|
+ onChange={e => {
|
|
|
|
|
+ var temp = JSON.parse(JSON.stringify(data))
|
|
|
|
|
+ if (isFast) {
|
|
|
|
|
+ temp.fast.target.duration = e
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ temp.sleep.target.duration = e
|
|
|
|
|
+ }
|
|
|
|
|
+ setData(temp)
|
|
|
|
|
+ }}
|
|
|
|
|
+ color={isFast ? MainColorType.fast : MainColorType.sleep} />
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
</View>
|
|
</View>
|
|
|
</Card>
|
|
</Card>
|
|
|
}
|
|
}
|
|
@@ -215,9 +447,7 @@ export default function LogTime() {
|
|
|
width={rpxToPx(670)}
|
|
width={rpxToPx(670)}
|
|
|
height={rpxToPx(96)}
|
|
height={rpxToPx(96)}
|
|
|
bold={true}
|
|
bold={true}
|
|
|
- onClick={() => {
|
|
|
|
|
-
|
|
|
|
|
- }} />
|
|
|
|
|
|
|
+ onClick={commit} />
|
|
|
</View>
|
|
</View>
|
|
|
|
|
|
|
|
</View>
|
|
</View>
|