|
|
@@ -3,7 +3,7 @@ import './log_record.scss'
|
|
|
import { useEffect, useState } from "react";
|
|
|
import Taro, { useRouter } from "@tarojs/taro";
|
|
|
import { rpxToPx } from "@/utils/tools";
|
|
|
-import { IconArrow, IconClose } from "@/components/basic/Icons";
|
|
|
+import { IconArrow, IconCheck, IconClose } from "@/components/basic/Icons";
|
|
|
import { MainColorType } from "@/context/themes/color";
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
import showAlert from "@/components/basic/Alert";
|
|
|
@@ -16,6 +16,7 @@ import { TimeFormatter } from "@/utils/time_format";
|
|
|
import { useSelector } from "react-redux";
|
|
|
import { addEvents, addUserTag, createMoment, updateMoment, userTags } from "@/services/health";
|
|
|
import PostMomentTime from "@/_health/components/post_moment_time";
|
|
|
+import ShareBtn from "@/components/basic/ShareBtn";
|
|
|
|
|
|
let useRoute;
|
|
|
let useNavigation;
|
|
|
@@ -30,11 +31,11 @@ export default function LogRecord() {
|
|
|
const long = useSelector((state: any) => state.long);
|
|
|
const health = useSelector((state: any) => state.health);
|
|
|
const record = useSelector((state: any) => state.record);
|
|
|
- const [pics, setPics] = useState<any>([])
|
|
|
+
|
|
|
const [title, setTitle] = useState('')
|
|
|
const [chooseTitle, setChooseTitle] = useState('')
|
|
|
const [desc, setDesc] = useState('')
|
|
|
- const [step, setStep] = useState(0)
|
|
|
+ const [step, setStep] = useState(2)
|
|
|
const { t } = useTranslation()
|
|
|
|
|
|
const [time, setTime] = useState(dayjs().format('HH:mm'))
|
|
|
@@ -43,8 +44,11 @@ export default function LogRecord() {
|
|
|
const [enterTimestmap] = useState(new Date().getTime())
|
|
|
const [posting, setPosting] = useState(false)
|
|
|
const [showTimePicker, setShowTimePicker] = useState(false)
|
|
|
+ const [result, setResult] = useState<any>(null)
|
|
|
+ const [showResult, setShowResult] = useState(false)
|
|
|
|
|
|
const [tags, setTags] = useState<any>([])
|
|
|
+ const [selPostCount, setPostCount] = useState(1)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -61,11 +65,12 @@ export default function LogRecord() {
|
|
|
router = useRouter()
|
|
|
}
|
|
|
|
|
|
- const { event_id, is_temp, schedule_id,scenario } = router.params
|
|
|
+ const { event_id, is_temp, schedule_id, scenario, imgs } = router.params
|
|
|
|
|
|
const moment = router.params.moment ? JSON.parse(router.params.moment) : null
|
|
|
|
|
|
const window = router.params.window ?? health.mode
|
|
|
+ const [pics, setPics] = useState<any>(imgs ? JSON.parse(imgs) : [])
|
|
|
|
|
|
useEffect(() => {
|
|
|
global.set_time = new Date().getTime()
|
|
|
@@ -74,10 +79,45 @@ export default function LogRecord() {
|
|
|
|
|
|
function getTags() {
|
|
|
userTags({ scenario: scenario }).then(res => {
|
|
|
+ var current = dayjs().format('HH:mm');
|
|
|
+ var isFind = false;
|
|
|
+ (res as any).tags.map(item => {
|
|
|
+ if (item.time_from && item.time_to) {
|
|
|
+ if (isInTimeRange(current, item.time_from, item.time_to)) {
|
|
|
+ isFind = true;
|
|
|
+ setTitle(item.title)
|
|
|
+ setChooseTitle(item.title)
|
|
|
+ setPostCount(item.log_count + 1)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if (!isFind) {
|
|
|
+ setTitle((res as any).tags[0].title)
|
|
|
+ setChooseTitle((res as any).tags[0].title)
|
|
|
+ setPostCount((res as any).tags[0].log_count + 1)
|
|
|
+ }
|
|
|
setTags((res as any).tags)
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ function isInTimeRange(currentTime, startTime, endTime) {
|
|
|
+ // 将时间字符串转换为 Date 对象
|
|
|
+ const current = new Date(`1970-01-01T${currentTime}:00`);
|
|
|
+ const start = new Date(`1970-01-01T${startTime}:00`);
|
|
|
+ const end = new Date(`1970-01-01T${endTime}:00`);
|
|
|
+
|
|
|
+ // 如果结束时间小于开始时间,说明时间段跨越了午夜
|
|
|
+ if (end < start) {
|
|
|
+ end.setDate(end.getDate() + 1); // 将结束时间加一天
|
|
|
+ if (current < start) {
|
|
|
+ current.setDate(current.getDate() + 1); // 如果当前时间在午夜之前,加一天
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断当前时间是否在时间段内
|
|
|
+ return current >= start && current < end;
|
|
|
+ }
|
|
|
+
|
|
|
function addTag() {
|
|
|
addUserTag({ scenario: scenario, title: title }).then(res => {
|
|
|
getTags()
|
|
|
@@ -246,7 +286,7 @@ export default function LogRecord() {
|
|
|
params.join_key = router.params.join_id
|
|
|
}
|
|
|
|
|
|
- var moment:any = {
|
|
|
+ var moment: any = {
|
|
|
description: desc,
|
|
|
}
|
|
|
if (pics.length > 0) {
|
|
|
@@ -285,10 +325,8 @@ export default function LogRecord() {
|
|
|
if (posting) return
|
|
|
setPosting(true)
|
|
|
addEvents(params).then(res => {
|
|
|
- Taro.showToast({
|
|
|
- title: '成功',
|
|
|
- icon: 'success'
|
|
|
- })
|
|
|
+ setShowResult(true)
|
|
|
+ setResult(res)
|
|
|
})
|
|
|
// createMoment(params).then(res => {
|
|
|
// // setTimeout(() => {
|
|
|
@@ -427,7 +465,19 @@ export default function LogRecord() {
|
|
|
alignItems: 'center',
|
|
|
justifyContent: 'center'
|
|
|
}}>
|
|
|
- <Image src={require('@assets/_health/navi_back.png')} style={{
|
|
|
+ <View style={{
|
|
|
+ position: 'absolute',
|
|
|
+ width: rpxToPx(92),
|
|
|
+ height: rpxToPx(64),
|
|
|
+ left: 22,
|
|
|
+ top: 22 - rpxToPx(32)
|
|
|
+ }}
|
|
|
+ onClick={() => {
|
|
|
+ Taro.navigateBack()
|
|
|
+ }}>
|
|
|
+ <IconClose color="#000" width={rpxToPx(64)} height={rpxToPx(64)} />
|
|
|
+ </View>
|
|
|
+ {/* <Image src={require('@assets/_health/navi_back.png')} style={{
|
|
|
position: 'absolute',
|
|
|
width: rpxToPx(92),
|
|
|
height: rpxToPx(64),
|
|
|
@@ -437,7 +487,7 @@ export default function LogRecord() {
|
|
|
onClick={() => {
|
|
|
Taro.navigateBack()
|
|
|
}}
|
|
|
- />
|
|
|
+ /> */}
|
|
|
{/* <View className="h36 bold">upcoming fast</View> */}
|
|
|
</View>
|
|
|
</View>
|
|
|
@@ -445,7 +495,7 @@ export default function LogRecord() {
|
|
|
{
|
|
|
step == 0 && <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', marginTop: rpxToPx(152) }}>
|
|
|
<Image src={require('@assets/_health/eat.png')} style={{ width: rpxToPx(96), height: rpxToPx(96) }} />
|
|
|
- <View className="h50 bold">选择打卡的{scenario=='MEAL'?'餐次':'活动'}</View>
|
|
|
+ <View className="h50 bold">选择打卡的{scenario == 'MEAL' ? '餐次' : '活动'}</View>
|
|
|
<View className="operate_bg">
|
|
|
{
|
|
|
tags.map((item, index) => {
|
|
|
@@ -486,60 +536,66 @@ export default function LogRecord() {
|
|
|
</View>
|
|
|
}
|
|
|
{
|
|
|
- step == 2 && <View>
|
|
|
- <View style={{ display: 'flex', flexDirection: 'row' }} onClick={() => {
|
|
|
- setStep(0)
|
|
|
- }}>
|
|
|
- <View className="sel_tag h34 bold">
|
|
|
- {chooseTitle}
|
|
|
- <View style={{ width: rpxToPx(6) }} />
|
|
|
- <IconArrow width={rpxToPx(34)} color={MainColorType.g02} />
|
|
|
+ step == 2 && <View className="cardShowAni">
|
|
|
+ <View className="content_card">
|
|
|
+ <View style={{ display: 'flex', flexDirection: 'row' }} onClick={() => {
|
|
|
+ setStep(0)
|
|
|
+ }}>
|
|
|
+ <View className="sel_tag h34 bold">
|
|
|
+ <View>{selPostCount}次</View>
|
|
|
+ {chooseTitle}
|
|
|
+ <View style={{ width: rpxToPx(6) }} />
|
|
|
+ <IconArrow width={rpxToPx(34)} color={MainColorType.g02} />
|
|
|
+ </View>
|
|
|
</View>
|
|
|
- </View>
|
|
|
-
|
|
|
- <Textarea placeholder={t('health.add_text')} className="textarea2 h44 bold"
|
|
|
- placeholder-style="color:rgba(0,0,0,0.2)"
|
|
|
- value={desc}
|
|
|
- onInput={e => {
|
|
|
- setDesc(e.detail.value)
|
|
|
- }} />
|
|
|
- <View className="form">
|
|
|
- {
|
|
|
- pics.map((item, index) => {
|
|
|
- return <View className="cover" key={index}>
|
|
|
- <Image src={item.url + scale} mode="aspectFill" className="cover" style={{
|
|
|
- margin: 0
|
|
|
- }} key={index} onClick={() => {
|
|
|
- Taro.previewImage({
|
|
|
- current: pics[index].url,
|
|
|
- urls: pics.map(file => file.url)
|
|
|
- })
|
|
|
- }} />
|
|
|
- <View className="cover_del" onClick={() => {
|
|
|
- showAlert({
|
|
|
- title: t('health.del_title'),
|
|
|
- content: '',
|
|
|
- cancelText: t('health.del_cancel'),
|
|
|
- confirmText: t('health.del_confirm'),
|
|
|
- showCancel: true,
|
|
|
- confirm: () => {
|
|
|
- var array = JSON.parse(JSON.stringify(pics))
|
|
|
- array.splice(index, 1)
|
|
|
- setPics(array)
|
|
|
- }
|
|
|
- })
|
|
|
- }}>
|
|
|
- <View className="cover_del_btn">
|
|
|
- <IconClose width={10} height={10} color="#fff" />
|
|
|
+ <Textarea placeholder={t('health.add_text')} className="textarea2 h44 bold"
|
|
|
+ placeholder-style="color:rgba(0,0,0,0.2)"
|
|
|
+ value={desc}
|
|
|
+ onInput={e => {
|
|
|
+ setDesc(e.detail.value)
|
|
|
+ }} />
|
|
|
+ <View className="form2">
|
|
|
+ {
|
|
|
+ pics.map((item, index) => {
|
|
|
+ return <View className="cover" key={index}>
|
|
|
+ <Image src={item.url + scale} mode="aspectFill" className="cover" style={{
|
|
|
+ margin: 0
|
|
|
+ }} key={index} onClick={() => {
|
|
|
+ Taro.previewImage({
|
|
|
+ current: pics[index].url,
|
|
|
+ urls: pics.map(file => file.url)
|
|
|
+ })
|
|
|
+ }} />
|
|
|
+ <View className="cover_del" onClick={() => {
|
|
|
+ showAlert({
|
|
|
+ title: t('health.del_title'),
|
|
|
+ content: '',
|
|
|
+ cancelText: t('health.del_cancel'),
|
|
|
+ confirmText: t('health.del_confirm'),
|
|
|
+ showCancel: true,
|
|
|
+ confirm: () => {
|
|
|
+ var array = JSON.parse(JSON.stringify(pics))
|
|
|
+ array.splice(index, 1)
|
|
|
+ setPics(array)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }}>
|
|
|
+ <View className="cover_del_btn">
|
|
|
+ <IconClose width={10} height={10} color="#fff" />
|
|
|
+ </View>
|
|
|
</View>
|
|
|
</View>
|
|
|
- </View>
|
|
|
- })
|
|
|
- }
|
|
|
- {
|
|
|
- pics.length < 9 && <View onClick={tapPic} className="cover" style={{}}><Image src={require('@assets/_health/camera.png')} style={{ width: 40, height: 40 }} /></View>
|
|
|
- }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ {
|
|
|
+ pics.length < 9 && <View onClick={tapPic} className="cover" style={{}}><Image src={require('@assets/_health/camera.png')} style={{ width: 40, height: 40 }} /></View>
|
|
|
+ }
|
|
|
+ </View>
|
|
|
</View>
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
<View className="time_view" onClick={() => {
|
|
|
setShowTimePicker(true)
|
|
|
}}>
|
|
|
@@ -550,16 +606,17 @@ export default function LogRecord() {
|
|
|
<IconArrow width={rpxToPx(34)} color={MainColorType.g02} />
|
|
|
<View className="border_footer_line" style={{ left: rpxToPx(48) }} />
|
|
|
</View>
|
|
|
- <View style={{ flex: 1 }} />
|
|
|
+ <View style={{ flex: 1,marginLeft:rpxToPx(52),marginTop:rpxToPx(35) }}>
|
|
|
|
|
|
- <View className="main_footer" style={{ backgroundColor: 'transparent' }}><NewButton
|
|
|
+ <NewButton
|
|
|
type={NewButtonType.fill}
|
|
|
color={MainColorType.orange}
|
|
|
width={rpxToPx(646)}
|
|
|
height={rpxToPx(96)}
|
|
|
title={t('health.log_moment')}
|
|
|
onClick={save}
|
|
|
- /></View>
|
|
|
+ />
|
|
|
+ </View>
|
|
|
|
|
|
</View>
|
|
|
}
|
|
|
@@ -581,5 +638,63 @@ export default function LogRecord() {
|
|
|
setShowTimePicker(false)
|
|
|
}} />
|
|
|
}
|
|
|
+ {
|
|
|
+ showResult && <View className="share_bg">
|
|
|
+ <View className="navi_bar" style={{ height: navigationBarHeight }}>
|
|
|
+ <View style={{
|
|
|
+ position: 'absolute',
|
|
|
+ left: 0,
|
|
|
+ right: 0,
|
|
|
+ bottom: 0,
|
|
|
+ height: 44,
|
|
|
+ display: 'flex',
|
|
|
+ alignItems: 'center',
|
|
|
+ justifyContent: 'center'
|
|
|
+ }}>
|
|
|
+ <View style={{
|
|
|
+ position: 'absolute',
|
|
|
+ width: rpxToPx(92),
|
|
|
+ height: rpxToPx(64),
|
|
|
+ left: 22,
|
|
|
+ top: 22 - rpxToPx(32)
|
|
|
+ }}
|
|
|
+ onClick={() => {
|
|
|
+ Taro.navigateBack()
|
|
|
+ // setShowShare(false)
|
|
|
+ }}>
|
|
|
+ <IconClose color="#fff" width={rpxToPx(64)} height={rpxToPx(64)} />
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+
|
|
|
+ </View>
|
|
|
+ <View className="share_card1" style={{ background: getBackground() }}>
|
|
|
+ {
|
|
|
+ result.images && result.images.length > 0 && <Image className="share_card_cover" mode="aspectFill" src={result.images[0]} />
|
|
|
+ }
|
|
|
+ {
|
|
|
+ result.images && result.images.length > 0 && <View className="share_card_layer" />
|
|
|
+ }
|
|
|
+ <View style={{ position: 'relative', zIndex: 1, display: 'flex', flexDirection: 'column', alignItems: 'center', height: '100%' }}>
|
|
|
+ <View className="log_result_success">
|
|
|
+ <IconCheck color="#fff" width={rpxToPx(32)} height={rpxToPx(32)} />
|
|
|
+ </View>
|
|
|
+ <View className="h50 bold" style={{ color: '#fff', marginTop: rpxToPx(24), marginBottom: rpxToPx(12) }}>{result.title}</View>
|
|
|
+ <View className="h30" style={{ color: '#fff' }}>{result.description}</View>
|
|
|
+ <View style={{ flex: 1 }} />
|
|
|
+ <View className="h28" style={{ color: '#fff', marginBottom: rpxToPx(120) }}>{result.moment_description}</View>
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ <ShareBtn>
|
|
|
+ <NewButton
|
|
|
+ type={NewButtonType.fill}
|
|
|
+ color={MainColorType.success}
|
|
|
+ width={rpxToPx(698)}
|
|
|
+ height={rpxToPx(108)}
|
|
|
+ title="Send to friends"
|
|
|
+ />
|
|
|
+ </ShareBtn>
|
|
|
+
|
|
|
+ </View>
|
|
|
+ }
|
|
|
</View>
|
|
|
}
|