|
@@ -1,15 +1,42 @@
|
|
|
-import { View, Text, Image } from "@tarojs/components";
|
|
|
|
|
|
|
+import { View, Text, Image, PageContainer } from "@tarojs/components";
|
|
|
import './TotalTime.scss'
|
|
import './TotalTime.scss'
|
|
|
import { useTranslation } from "react-i18next";
|
|
import { useTranslation } from "react-i18next";
|
|
|
import { ColorType } from "@/context/themes/color";
|
|
import { ColorType } from "@/context/themes/color";
|
|
|
import { rpxToPx } from "@/utils/tools";
|
|
import { rpxToPx } from "@/utils/tools";
|
|
|
import { TimeFormatter } from "@/utils/time_format";
|
|
import { TimeFormatter } from "@/utils/time_format";
|
|
|
|
|
+import Modal from "@/components/layout/Modal.weapp";
|
|
|
|
|
+import { useEffect, useRef, useState } from "react";
|
|
|
|
|
+import { durationDatas, durationIndex, getColor, getDurationTitle } from "../hooks/Console";
|
|
|
|
|
+import PickerViews from "@/components/input/PickerViews";
|
|
|
|
|
+import { useSelector } from "react-redux";
|
|
|
|
|
+import Taro from "@tarojs/taro";
|
|
|
|
|
|
|
|
export default function TotalTime(props: { record: any }) {
|
|
export default function TotalTime(props: { record: any }) {
|
|
|
|
|
+ const [showDurationPicker, setShowDurationPicker] = useState(false)
|
|
|
|
|
+ const [fastPickerValue, setFastPickerValue] = useState([0, 0])
|
|
|
|
|
+ const [sleepPickerValue, setSleepPickerValue] = useState([0, 0])
|
|
|
|
|
+ const [showEditPicker, setShowEditPicker] = useState(false)
|
|
|
|
|
+ const common = useSelector((state: any) => state.common);
|
|
|
|
|
+ const [isFast, setIsFast] = useState(true)
|
|
|
|
|
+ const durationPickerRef = useRef(null)
|
|
|
const { t } = useTranslation()
|
|
const { t } = useTranslation()
|
|
|
|
|
|
|
|
|
|
+ useEffect(()=>{
|
|
|
|
|
+ getStateDetail()
|
|
|
|
|
+ },[])
|
|
|
|
|
+
|
|
|
|
|
+ function getStateDetail() {
|
|
|
|
|
+ var current_record = props.record
|
|
|
|
|
+ // var fastCount = current_record.fast.target_end_time - current_record.fast.target_start_time
|
|
|
|
|
+ // setFastDuration(fastCount)
|
|
|
|
|
+ setFastPickerValue(durationIndex(current_record.fast.target_start_time, current_record.fast.target_end_time, common))
|
|
|
|
|
+
|
|
|
|
|
+ // var sleepCount = current_record.sleep.target_end_time - current_record.sleep.target_start_time
|
|
|
|
|
+ // setSleepDuration(sleepCount)
|
|
|
|
|
+ setSleepPickerValue(durationIndex(current_record.sleep.target_start_time, current_record.sleep.target_end_time, common))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
function sleepCompleteStatus() {
|
|
function sleepCompleteStatus() {
|
|
|
- debugger
|
|
|
|
|
if (props.record.sleep.status == "NOT_STARTED") {
|
|
if (props.record.sleep.status == "NOT_STARTED") {
|
|
|
return t('feature.common.not_started')
|
|
return t('feature.common.not_started')
|
|
|
}
|
|
}
|
|
@@ -47,14 +74,62 @@ export default function TotalTime(props: { record: any }) {
|
|
|
return TimeFormatter.countdown(props.record.sleep.target_end_time)
|
|
return TimeFormatter.countdown(props.record.sleep.target_end_time)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ function setFastDuration() {
|
|
|
|
|
+ setIsFast(true)
|
|
|
|
|
+ if (disableChange(true)) return
|
|
|
|
|
+ if (props.record.status == 'WAIT_FOR_START') {
|
|
|
|
|
+ setShowDurationPicker(true)
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ setShowEditPicker(true)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function setSleepDuration() {
|
|
|
|
|
+ setIsFast(false)
|
|
|
|
|
+ if (disableChange(false)) return
|
|
|
|
|
+ if (props.record.status == 'WAIT_FOR_START') {
|
|
|
|
|
+ Taro.showToast({
|
|
|
|
|
+ title: t('feature.track_time_duration.common.start_fasting_first'),
|
|
|
|
|
+ icon: 'none'
|
|
|
|
|
+ })
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (props.record.status == 'WAIT_FOR_START' || props.record.status == 'ONGOING1') {
|
|
|
|
|
+ setShowDurationPicker(true)
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ setShowEditPicker(true)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function disableChange(isFastStatus) {
|
|
|
|
|
+ if (props.record.status == 'WAIT_FOR_START') {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isFastStatus) {
|
|
|
|
|
+ if (props.record.status != 'COMPLETED')
|
|
|
|
|
+ return false;
|
|
|
|
|
+ return true
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ if (props.record.status == 'ONGOING3' || props.record.status == 'COMPLETED') {
|
|
|
|
|
+ return true
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
function fastOtherStatus() {
|
|
function fastOtherStatus() {
|
|
|
return <View>
|
|
return <View>
|
|
|
<View className="cell_full" >
|
|
<View className="cell_full" >
|
|
|
<Text className="cell_title" style={{ opacity: 0.2 }}>已进行</Text>
|
|
<Text className="cell_title" style={{ opacity: 0.2 }}>已进行</Text>
|
|
|
- <Text className="cell_value"
|
|
|
|
|
- style={{ color: props.record.status == 'WAIT_FOR_START' ?
|
|
|
|
|
- '#fff' : ColorType.fast,
|
|
|
|
|
- opacity: props.record.status == 'WAIT_FOR_START' ? 0.2 : 1 }}>{fastGoingText()}</Text>
|
|
|
|
|
|
|
+ <Text className="cell_value"
|
|
|
|
|
+ style={{
|
|
|
|
|
+ color: props.record.status == 'WAIT_FOR_START' ?
|
|
|
|
|
+ '#fff' : ColorType.fast,
|
|
|
|
|
+ opacity: props.record.status == 'WAIT_FOR_START' ? 0.2 : 1
|
|
|
|
|
+ }}>{fastGoingText()}</Text>
|
|
|
</View>
|
|
</View>
|
|
|
<View className="cell_line" style={{ height: 1 }} />
|
|
<View className="cell_line" style={{ height: 1 }} />
|
|
|
<View className="cell_full" >
|
|
<View className="cell_full" >
|
|
@@ -68,9 +143,11 @@ export default function TotalTime(props: { record: any }) {
|
|
|
return <View>
|
|
return <View>
|
|
|
<View className="cell_full" >
|
|
<View className="cell_full" >
|
|
|
<Text className="cell_title" style={{ opacity: 0.2 }}>已进行</Text>
|
|
<Text className="cell_title" style={{ opacity: 0.2 }}>已进行</Text>
|
|
|
- <Text className="cell_value" style={{ color: props.record.status == 'WAIT_FOR_START'||props.record.status == 'ONGOING1' ?
|
|
|
|
|
- '#fff' : ColorType.sleep,
|
|
|
|
|
- opacity: props.record.status == 'WAIT_FOR_START'||props.record.status == 'ONGOING1' ? 0.2 : 1 }}>{sleepGoingText()}</Text>
|
|
|
|
|
|
|
+ <Text className="cell_value" style={{
|
|
|
|
|
+ color: props.record.status == 'WAIT_FOR_START' || props.record.status == 'ONGOING1' ?
|
|
|
|
|
+ '#fff' : ColorType.sleep,
|
|
|
|
|
+ opacity: props.record.status == 'WAIT_FOR_START' || props.record.status == 'ONGOING1' ? 0.2 : 1
|
|
|
|
|
+ }}>{sleepGoingText()}</Text>
|
|
|
</View>
|
|
</View>
|
|
|
<View className="cell_line" style={{ height: 1 }} />
|
|
<View className="cell_line" style={{ height: 1 }} />
|
|
|
<View className="cell_full" >
|
|
<View className="cell_full" >
|
|
@@ -80,7 +157,97 @@ export default function TotalTime(props: { record: any }) {
|
|
|
</View>
|
|
</View>
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return <View style={{ marginLeft: -rpxToPx(50), marginRight: -rpxToPx(50) }}>
|
|
|
|
|
|
|
+ function durationPickerContent() {
|
|
|
|
|
+ var color = getColor(props.record)
|
|
|
|
|
+ var title = getDurationTitle(props.record, t)
|
|
|
|
|
+ return <View style={{ color: '#fff', backgroundColor: 'transparent' }}>
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ <PickerViews ref={durationPickerRef}
|
|
|
|
|
+ onChange={durationChange}
|
|
|
|
|
+ items={durationDatas(common)}
|
|
|
|
|
+ value={isFast ? fastPickerValue : sleepPickerValue}
|
|
|
|
|
+ themeColor={color}
|
|
|
|
|
+ title={title}
|
|
|
|
|
+ showBtns={true}
|
|
|
|
|
+ onCancel={() => {
|
|
|
|
|
+ setShowDurationPicker(false)
|
|
|
|
|
+ }} />
|
|
|
|
|
+ </View>
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function editPickerContent() {
|
|
|
|
|
+ return <View style={{ color: '#fff', backgroundColor: 'transparent' }}>
|
|
|
|
|
+ <PickerViews ref={durationPickerRef}
|
|
|
|
|
+ onChange={durationChange}
|
|
|
|
|
+ items={durationDatas(common)}
|
|
|
|
|
+ value={isFast ? fastPickerValue : sleepPickerValue}
|
|
|
|
|
+ themeColor={isFast ? ColorType.fast : ColorType.sleep}
|
|
|
|
|
+ title={isFast ? t('feature.track_time_duration.action_sheet.edit_fasting_goal') :
|
|
|
|
|
+ t('feature.track_time_duration.action_sheet.edit_sleeping_goal')}
|
|
|
|
|
+ showBtns={true}
|
|
|
|
|
+ onCancel={() => {
|
|
|
|
|
+ setShowEditPicker(false)
|
|
|
|
|
+ }} />
|
|
|
|
|
+ </View>
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function durationChange(e) {
|
|
|
|
|
+ // debugger
|
|
|
|
|
+ var count = (e[0] + common.duration.min) * 60 + e[1] * common.duration.step
|
|
|
|
|
+ // var count = (e[0] + 1) * 60 + e[1] * 5
|
|
|
|
|
+ if (showDurationPicker) {
|
|
|
|
|
+ global.changeTargetDuration(count, isFast)
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ setShowDurationPicker(false)
|
|
|
|
|
+ setShowEditPicker(false)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function modalContent() {
|
|
|
|
|
+ if (showDurationPicker || showEditPicker) {
|
|
|
|
|
+ if (process.env.TARO_ENV == 'weapp') {
|
|
|
|
|
+ return <Modal
|
|
|
|
|
+ testInfo={null}
|
|
|
|
|
+ dismiss={() => {
|
|
|
|
|
+ setShowDurationPicker(false)
|
|
|
|
|
+ setShowEditPicker(false)
|
|
|
|
|
+ }}
|
|
|
|
|
+ confirm={() => { }}>
|
|
|
|
|
+ {
|
|
|
|
|
+ showDurationPicker ? durationPickerContent() : editPickerContent()
|
|
|
|
|
+ }
|
|
|
|
|
+ </Modal>
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (process.env.TARO_ENV == 'rn') {
|
|
|
|
|
+ return <PageContainer style={{ backgroundColor: '#1c1c1c' }}
|
|
|
|
|
+ // overlayStyle='background-color:rgba(0,0,0,0.9)'
|
|
|
|
|
+ // custom-style='background-color:#1c1c1c'
|
|
|
|
|
+ overlayStyle={{ backgroundColor: 'rgba(0,0,0,0.9)' }}
|
|
|
|
|
+ customStyle={{ backgroundColor: '#1c1c1c' }}
|
|
|
|
|
+ closeOnSlideDown={false}
|
|
|
|
|
+ onBeforeEnter={() => {
|
|
|
|
|
+
|
|
|
|
|
+ }}
|
|
|
|
|
+ onBeforeLeave={() => {
|
|
|
|
|
+ }}
|
|
|
|
|
+ onClick={() => { alert('b') }}
|
|
|
|
|
+ onClickOverlay={() => { alert('a') }}
|
|
|
|
|
+ onAfterLeave={() => { setShowDurationPicker(false); setShowEditPicker(false) }}
|
|
|
|
|
+ show={showDurationPicker} round={true} overlay={true} position='bottom'
|
|
|
|
|
+ >
|
|
|
|
|
+ {
|
|
|
|
|
+ showDurationPicker ? durationPickerContent() : editPickerContent()
|
|
|
|
|
+ }
|
|
|
|
|
+ </PageContainer>
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return <View />
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return <View style={{ width: rpxToPx(600) }}>
|
|
|
{
|
|
{
|
|
|
props.record.fast && <View>
|
|
props.record.fast && <View>
|
|
|
<Text className="cell_header">断食</Text>
|
|
<Text className="cell_header">断食</Text>
|
|
@@ -90,21 +257,21 @@ export default function TotalTime(props: { record: any }) {
|
|
|
<View className="cell_full" >
|
|
<View className="cell_full" >
|
|
|
<Text className="cell_title">实际完成</Text>
|
|
<Text className="cell_title">实际完成</Text>
|
|
|
<Text className="cell_value" style={{ color: ColorType.fast }}>{TimeFormatter.durationFormate(props.record.fast.real_start_time, props.record.fast.real_end_time)}</Text>
|
|
<Text className="cell_value" style={{ color: ColorType.fast }}>{TimeFormatter.durationFormate(props.record.fast.real_start_time, props.record.fast.real_end_time)}</Text>
|
|
|
- <Image className="cell_arrow" src={require('@/assets/images/arrow3.png')} />
|
|
|
|
|
|
|
+ {/* <Image className="cell_arrow" src={require('@/assets/images/arrow3.png')} /> */}
|
|
|
</View> :
|
|
</View> :
|
|
|
- <View className="cell_full" >
|
|
|
|
|
|
|
+ <View className="cell_full" onClick={setFastDuration}>
|
|
|
<Text className="cell_title">本次目标</Text>
|
|
<Text className="cell_title">本次目标</Text>
|
|
|
<Text className="cell_value">{TimeFormatter.durationFormate(props.record.fast.target_start_time, props.record.fast.target_end_time)}</Text>
|
|
<Text className="cell_value">{TimeFormatter.durationFormate(props.record.fast.target_start_time, props.record.fast.target_end_time)}</Text>
|
|
|
- <Image className="cell_arrow" src={require('@/assets/images/arrow3.png')} />
|
|
|
|
|
|
|
+ {!disableChange(true) && <Image className="cell_arrow" src={require('@/assets/images/arrow3.png')} />}
|
|
|
</View>
|
|
</View>
|
|
|
}
|
|
}
|
|
|
<View className="cell_line" style={{ height: 1 }} />
|
|
<View className="cell_line" style={{ height: 1 }} />
|
|
|
{
|
|
{
|
|
|
props.record.status == 'COMPLETED' ?
|
|
props.record.status == 'COMPLETED' ?
|
|
|
- <View className="cell_full" >
|
|
|
|
|
|
|
+ <View className="cell_full" onClick={setFastDuration}>
|
|
|
<Text className="cell_title" style={{ opacity: 0.2 }}>本次目标</Text>
|
|
<Text className="cell_title" style={{ opacity: 0.2 }}>本次目标</Text>
|
|
|
- <Text className="cell_value" style={{ opacity: 0.2,color:'#fff' }}>{TimeFormatter.durationFormate(props.record.fast.target_start_time, props.record.fast.target_end_time)}</Text>
|
|
|
|
|
- <Image className="cell_arrow" src={require('@/assets/images/arrow3.png')} />
|
|
|
|
|
|
|
+ <Text className="cell_value" style={{ opacity: 0.2, color: '#fff' }}>{TimeFormatter.durationFormate(props.record.fast.target_start_time, props.record.fast.target_end_time)}</Text>
|
|
|
|
|
+ {!disableChange(true) && <Image className="cell_arrow" src={require('@/assets/images/arrow3.png')} />}
|
|
|
</View> :
|
|
</View> :
|
|
|
fastOtherStatus()
|
|
fastOtherStatus()
|
|
|
}
|
|
}
|
|
@@ -121,28 +288,29 @@ export default function TotalTime(props: { record: any }) {
|
|
|
<View className="cell_full" >
|
|
<View className="cell_full" >
|
|
|
<Text className="cell_title">实际完成</Text>
|
|
<Text className="cell_title">实际完成</Text>
|
|
|
<Text className="cell_value" style={{ color: ColorType.sleep }}>{sleepCompleteStatus()}</Text>
|
|
<Text className="cell_value" style={{ color: ColorType.sleep }}>{sleepCompleteStatus()}</Text>
|
|
|
- <Image className="cell_arrow" src={require('@/assets/images/arrow3.png')} />
|
|
|
|
|
</View> :
|
|
</View> :
|
|
|
- <View className="cell_full" >
|
|
|
|
|
|
|
+ <View className="cell_full" onClick={setSleepDuration}>
|
|
|
<Text className="cell_title">本次目标</Text>
|
|
<Text className="cell_title">本次目标</Text>
|
|
|
<Text className="cell_value">{TimeFormatter.durationFormate(props.record.sleep.target_start_time, props.record.sleep.target_end_time)}</Text>
|
|
<Text className="cell_value">{TimeFormatter.durationFormate(props.record.sleep.target_start_time, props.record.sleep.target_end_time)}</Text>
|
|
|
- <Image className="cell_arrow" src={require('@/assets/images/arrow3.png')} />
|
|
|
|
|
|
|
+ {!disableChange(false) && <Image className="cell_arrow" src={require('@/assets/images/arrow3.png')} />}
|
|
|
</View>
|
|
</View>
|
|
|
}
|
|
}
|
|
|
<View className="cell_line" style={{ height: 1 }} />
|
|
<View className="cell_line" style={{ height: 1 }} />
|
|
|
{
|
|
{
|
|
|
props.record.status == 'COMPLETED' || props.record.status == 'ONGOING3' ?
|
|
props.record.status == 'COMPLETED' || props.record.status == 'ONGOING3' ?
|
|
|
- <View className="cell_full" >
|
|
|
|
|
|
|
+ <View className="cell_full" onClick={setSleepDuration}>
|
|
|
<Text className="cell_title" style={{ opacity: 0.2 }}>本次目标</Text>
|
|
<Text className="cell_title" style={{ opacity: 0.2 }}>本次目标</Text>
|
|
|
- <Text className="cell_value" style={{ opacity: 0.2,color:'#fff' }}>{TimeFormatter.durationFormate(props.record.sleep.target_start_time, props.record.sleep.target_end_time)}</Text>
|
|
|
|
|
- <Image className="cell_arrow" src={require('@/assets/images/arrow3.png')} />
|
|
|
|
|
|
|
+ <Text className="cell_value" style={{ opacity: 0.2, color: '#fff' }}>{TimeFormatter.durationFormate(props.record.sleep.target_start_time, props.record.sleep.target_end_time)}</Text>
|
|
|
|
|
+ {!disableChange(false) && <Image className="cell_arrow" src={require('@/assets/images/arrow3.png')} />}
|
|
|
</View> :
|
|
</View> :
|
|
|
sleepOtherStatus()
|
|
sleepOtherStatus()
|
|
|
}
|
|
}
|
|
|
</View>
|
|
</View>
|
|
|
</View>
|
|
</View>
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ modalContent()
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
</View>
|
|
</View>
|
|
|
}
|
|
}
|