time_record.tsx 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928
  1. import { View, Image, PickerView, PickerViewColumn, Text } from "@tarojs/components";
  2. import './time_record.scss'
  3. import Taro, { useRouter, useShareAppMessage } from "@tarojs/taro";
  4. import { rpxToPx } from "@/utils/tools";
  5. import { MainColorType } from "@/context/themes/color";
  6. import NewButton, { NewButtonType } from "@/_health/base/new_button";
  7. import { useEffect, useRef, useState } from "react";
  8. import NewDateTimePicker from "@/_health/base/new_date_time_picker";
  9. import dayjs from "dayjs";
  10. import RingProgress from "../components/ring_progress";
  11. import NewDurationPicker, { DurationPickerType } from "@/_health/base/new_durationpicker";
  12. import { IconArrow, IconClose, IconMore2 } from "@/components/basic/Icons";
  13. import { useSelector } from "react-redux";
  14. import { TimeFormatter } from "@/utils/time_format";
  15. import { addEvents, delWindowId } from "@/services/health";
  16. import Modal from "@/components/layout/Modal.weapp";
  17. import { getDurationArc, getStartArc } from "@/features/health/hooks/health_hooks";
  18. import ShareBtn from "@/components/basic/ShareBtn";
  19. import PickerCard from "../components/picker_card";
  20. import showActionSheet from "@/components/basic/ActionSheet";
  21. import { useTranslation } from "react-i18next";
  22. import FollowInfo from "@/_moment/components/follow_info";
  23. import MomentDetailShare from "@/pages/moment/moment_detail_share";
  24. import { BASE_IMG_URL } from "@/services/http/api";
  25. let timer
  26. let useRoute;
  27. let useNavigation, LinearGradient;
  28. if (process.env.TARO_ENV == 'rn') {
  29. useRoute = require("@react-navigation/native").useRoute
  30. useNavigation = require("@react-navigation/native").useNavigation
  31. LinearGradient = require('react-native-linear-gradient').default
  32. }
  33. export default function TimeRecord() {
  34. const systemInfo: any = Taro.getWindowInfo ? Taro.getWindowInfo() : Taro.getSystemInfoSync();
  35. const navigationBarHeight = systemInfo.statusBarHeight + 44;
  36. const screenHeight = systemInfo.screenHeight
  37. const record = useSelector((state: any) => state.record);
  38. const long = useSelector((state: any) => state.long);
  39. const user = useSelector((state: any) => state.user);
  40. const [enterTime] = useState(new Date().getTime())
  41. const [showDatePicker, setShowDatePicker] = useState(false)
  42. const [showDurationPicker, setShowDurationPicker] = useState(false)
  43. const [showEndDatePicker, setShowEndDatePicker] = useState(false)
  44. const [count, setCount] = useState(0)
  45. const [status, setStatus] = useState('WFS')
  46. const [info, setInfo] = useState<any>(null)
  47. const [loaded, setLoaded] = useState(false)
  48. const [showHighlight, setShowHighlight] = useState(false)
  49. const [showShare, setShowShare] = useState(false)
  50. const [shareUrl, setShareUrl] = useState('')
  51. const [showResult, setShowResult] = useState(false)
  52. const statusRef = useRef(status)
  53. const picker1Ref = useRef(showDatePicker)
  54. const picker2Ref = useRef(showEndDatePicker)
  55. const picker3Ref = useRef(showDurationPicker)
  56. const [posting, setPosting] = useState(false)
  57. const [postError, setPostError] = useState('')
  58. const [pickerTitle, setPickerTitle] = useState('')
  59. const [themeColor, setThemeColor] = useState(MainColorType.orange)
  60. const { t } = useTranslation()
  61. let router
  62. let navigation;
  63. if (useNavigation) {
  64. navigation = useNavigation()
  65. }
  66. if (process.env.TARO_ENV == 'rn') {
  67. router = useRoute()
  68. }
  69. else {
  70. router = useRouter()
  71. }
  72. const { scenario, join_id } = router.params
  73. if (process.env.TARO_ENV == 'weapp') {
  74. useShareAppMessage((e) => {
  75. var path;
  76. if (info && info.id) {
  77. var sharePath = `/_health/pages/timeline_detail?type=recent&fast_type=IF&window_id=${info.id}&uid=${user.id}&isfastsleep=${0}&disable_edit=1&enter_type=share`
  78. if (user.isLogin) {
  79. sharePath += `&share_uid=${user.id}`
  80. }
  81. path = sharePath
  82. }
  83. else {
  84. path = 'pages/clock/Clock'
  85. }
  86. var title = ''
  87. var shareDate = global.language == 'en' ? 'Today\'s' : '今日'
  88. if (scenario == 'FAST') {
  89. title = t('health.share_check_in', { date: shareDate, type: t('health.fasting') })
  90. }
  91. else {
  92. title = t('health.share_check_in', { date: shareDate, type: t('health.sleep') })
  93. }
  94. return {
  95. title: title,
  96. path: path,
  97. imageUrl: global.momentdetail_share_url//shareUrl
  98. }
  99. })
  100. }
  101. useEffect(() => {
  102. statusRef.current = status;
  103. picker1Ref.current = showDatePicker
  104. picker2Ref.current = showEndDatePicker
  105. picker3Ref.current = showDurationPicker
  106. if (!showDatePicker && !showEndDatePicker) {
  107. setPostError('')
  108. }
  109. if (showDatePicker) {
  110. setPickerTitle(scenario == 'FAST' ? t('health.adjust_fast_start_time') : t('health.adjust_bed_time'))
  111. }
  112. else if (showEndDatePicker) {
  113. setPickerTitle(scenario == 'FAST' ? t('health.adjust_fast_end_time') : t('health.adjust_wake_up2'))
  114. }
  115. else if (showDurationPicker) {
  116. setPickerTitle(scenario == 'FAST' ? t('health.adjust_fast_goal') : t('health.adjust_sleep_goal'))
  117. }
  118. }, [status, showDatePicker, showEndDatePicker, showDurationPicker])
  119. useEffect(() => {
  120. const { list } = record
  121. list.map((item) => {
  122. if (item.scenario == scenario) {
  123. setInfo(item.event)
  124. setStatus(item.event.status)
  125. setLoaded(true)
  126. setThemeColor(item.theme_color)
  127. }
  128. })
  129. downloadFile()
  130. timer = setInterval(() => {
  131. if (picker1Ref.current || picker2Ref.current || picker3Ref.current) return
  132. if (statusRef.current == 'DONE') return
  133. setCount(count => count + 1)
  134. }, 1000)
  135. return () => {
  136. clearInterval(timer)
  137. }
  138. }, [])
  139. function downloadFile() {
  140. Taro.downloadFile({
  141. url: BASE_IMG_URL + 'cp_check_f.png',
  142. success: (res) => {
  143. if (res.statusCode === 200) {
  144. global.checkFastImg = res.tempFilePath
  145. } else {
  146. }
  147. },
  148. fail: (err) => {
  149. }
  150. });
  151. Taro.downloadFile({
  152. url: BASE_IMG_URL + 'cp_check_s.png',
  153. success: (res) => {
  154. if (res.statusCode === 200) {
  155. global.checkSleepImg = res.tempFilePath
  156. } else {
  157. }
  158. },
  159. fail: (err) => {
  160. }
  161. });
  162. }
  163. function tapClock() {
  164. if (status == 'WFS')
  165. setShowDurationPicker(true)
  166. }
  167. function start() {
  168. // var date = TimeFormatter.stringToDate(selDate, time)
  169. // date.setMilliseconds(new Date(enterTimestmap).getMilliseconds())
  170. var params: any = {
  171. scenario: scenario, //ACTIVITY
  172. type: 'INTERVAL',
  173. sub_type: scenario,
  174. time: {
  175. start_timestamp: new Date().getTime(),
  176. duration: info.time.duration
  177. }
  178. }
  179. if (router.params.join_id) {
  180. params.join_key = router.params.join_id
  181. }
  182. // if (event_id && event_id != 'undefined') {
  183. // params.event_id = event_id
  184. // }
  185. // if (is_temp) {
  186. // params.event = window == 'EAT' ? 'EAT_CUSTOM' : 'ACTIVE_CUSTOM'
  187. // }
  188. // params.op_page = window == 'EAT' ? 'HOME_EAT' : 'HOME_ACTIVE'
  189. params.extra = {
  190. set_time: global.set_time ? global.set_time : new Date().getTime(),
  191. confirm_time: new Date().getTime()
  192. }
  193. // console.log('打卡提交数据', params)
  194. if (posting) return
  195. setPosting(true)
  196. addEvents(params).then(res => {
  197. Taro.eventCenter.trigger('refreshClockIndex')
  198. Taro.eventCenter.trigger('refreshMoments', '')
  199. setShowHighlight(true)
  200. setTimeout(() => {
  201. setShowHighlight(false)
  202. }, 3300)
  203. setInfo((res as any).data)
  204. setStatus((res as any).data.status)
  205. // Taro.showToast({
  206. // title: '成功',
  207. // icon: 'success'
  208. // })
  209. setPosting(false)
  210. }).catch(e => {
  211. setPosting(false)
  212. })
  213. }
  214. function end() {
  215. var params: any = {
  216. scenario: scenario, //ACTIVITY
  217. type: 'INTERVAL',
  218. sub_type: scenario,
  219. time: {
  220. end_timestamp: new Date().getTime()
  221. }
  222. }
  223. if (router.params.join_id) {
  224. params.join_key = router.params.join_id
  225. }
  226. params.extra = {
  227. set_time: global.set_time ? global.set_time : new Date().getTime(),
  228. confirm_time: new Date().getTime()
  229. }
  230. if (posting) return
  231. setPosting(true)
  232. addEvents(params).then(res => {
  233. setShowHighlight(true)
  234. setTimeout(() => {
  235. setShowHighlight(false)
  236. }, 8000)
  237. setTimeout(() => {
  238. setShowResult(true)
  239. }, 2000)
  240. Taro.eventCenter.trigger('refreshClockIndex')
  241. Taro.eventCenter.trigger('refreshMoments', '')
  242. setInfo((res as any).data)
  243. setStatus((res as any).data.status)
  244. setShareUrl('')
  245. // Taro.showToast({
  246. // title: '成功',
  247. // icon: 'success'
  248. // })
  249. setPosting(false)
  250. }).catch(e => {
  251. setPosting(false)
  252. })
  253. }
  254. function update(params) {
  255. var data: any = {
  256. id: info.id,
  257. time: {
  258. ...params
  259. }
  260. }
  261. if (posting) return
  262. setPosting(true)
  263. addEvents(data).then(res => {
  264. if ((res as any).result == false) {
  265. setPostError((res as any).error_messages[0])
  266. return
  267. }
  268. Taro.eventCenter.trigger('refreshClockIndex')
  269. Taro.eventCenter.trigger('refreshMoments', '')
  270. setInfo((res as any).data)
  271. setShowDatePicker(false)
  272. setShowDurationPicker(false)
  273. setShowEndDatePicker(false)
  274. setCount((count) => count + 1)
  275. setPosting(false)
  276. }).catch(e => {
  277. setPosting(false)
  278. })
  279. }
  280. function more() {
  281. showActionSheet({
  282. // title: '操作',
  283. itemList: [t('health.discard'), t('health.discard_restart')],
  284. success: (res) => {
  285. switch (res) {
  286. case 0:
  287. delWindowId(info.id).then(res => {
  288. setInfo((res as any).data)
  289. setStatus((res as any).data.status)
  290. })
  291. break
  292. case 1:
  293. delWindowId(info.id).then(res => {
  294. start()
  295. })
  296. break
  297. }
  298. }
  299. })
  300. }
  301. function tapStart() {
  302. setShowDatePicker(true)
  303. }
  304. function tapGoal() {
  305. setShowDurationPicker(true)
  306. }
  307. function ringExtra() {
  308. if (status == 'DONE') {
  309. return {
  310. value: '',
  311. footer: '',
  312. color: themeColor,
  313. result: TimeFormatter.formateDurationBySeconds(info.time.end_timestamp / 1000 - info.time.start_timestamp / 1000),
  314. }
  315. }
  316. if (status == 'WFS') {
  317. const count = info.time.duration / 1000
  318. var str = TimeFormatter.formateDurationBySeconds(count)
  319. return {
  320. target: str,
  321. goal: t('health.adjust_goal'),
  322. color: themeColor
  323. }
  324. }
  325. var percent = 100 * (new Date().getTime() - info.time.start_timestamp) / info.time.duration
  326. percent = parseInt(percent + '')
  327. return {
  328. progress: TimeFormatter.countdown(info.time.start_timestamp),
  329. footer: t('health.elapsed', { percent: percent + '%' }),//`ELAPSED ${percent}%`,
  330. color: MainColorType.g02
  331. }
  332. }
  333. function getBackground() {
  334. var time = record.time
  335. if (!time) return '#fff'
  336. const { background_colors } = time
  337. if (!background_colors) {
  338. return '#fff'
  339. }
  340. else if (background_colors.length == 1) {
  341. return background_colors[0]
  342. }
  343. return `linear-gradient(to bottom, ${background_colors[0]}, ${background_colors[1]})`
  344. }
  345. if (!loaded) {
  346. return <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
  347. <View className="main_bg" style={{ background: getBackground() }} />
  348. </View>
  349. }
  350. function doneComponent() {
  351. if (status == 'DONE') {
  352. return <View className="share_bg" style={{ justifyContent: 'flex-start' }}>
  353. <View className="navi_bar" style={{ height: navigationBarHeight }}>
  354. <View style={{
  355. position: 'absolute',
  356. left: 0,
  357. right: 0,
  358. bottom: 0,
  359. height: 44,
  360. display: 'flex',
  361. alignItems: 'center',
  362. justifyContent: 'center'
  363. }}>
  364. <View style={{
  365. position: 'absolute',
  366. width: rpxToPx(92),
  367. height: rpxToPx(64),
  368. left: 22,
  369. top: 22 - rpxToPx(32)
  370. }}
  371. onClick={() => {
  372. process.env.TARO_ENV == 'weapp' ? Taro.navigateBack() : navigation.goBack()
  373. }}>
  374. <IconClose color="#fff" width={rpxToPx(64)} height={rpxToPx(64)} />
  375. </View>
  376. </View>
  377. </View>
  378. <View className="share_card2" style={{ background: themeColor, marginTop: rpxToPx(26) + navigationBarHeight }}>
  379. {/* {
  380. shareUrl.length > 0 ? <Image src={shareUrl} style={{ width: rpxToPx(900), height: rpxToPx(720) }} /> :
  381. <View style={{ width: rpxToPx(900), height: rpxToPx(720), backgroundColor: MainColorType.g02 }} />
  382. } */}
  383. <RingProgress
  384. radius={rpxToPx(250)} canvasId="helloworld_share2"
  385. //scale={0.75}
  386. count={count}
  387. bgRing={{
  388. color: 'rgba(255,255,255,1)',
  389. width: rpxToPx(88)
  390. }}
  391. real={{
  392. color: themeColor,
  393. width: rpxToPx(16),
  394. start: getStartArc(info.time.start_timestamp),
  395. duration: getDurationArc(info.time.start_timestamp, info.time.end_timestamp)
  396. }}
  397. extra={ringExtra()}
  398. shareBg={[themeColor]}
  399. checkImgUrl={scenario == 'FAST' ? global.checkFastImg : global.checkSleepImg}
  400. isCompleted
  401. shareCover={
  402. url => {
  403. setShareUrl(url)
  404. }
  405. }
  406. />
  407. {
  408. <View className="share_operate_content">
  409. {
  410. showResult ? <View style={{ display: 'flex', flex: 1, flexDirection: 'row' }}>
  411. <NewButton type={NewButtonType.custom} onClick={() => {
  412. setShowDatePicker(true)
  413. }}>
  414. <View className="operate_item" >
  415. <View className="g02 h24 white_50">{scenario == 'FAST' ? t('health.started') : t('health.bedtime1')}</View>
  416. <View className="h44 bold white" style={{ marginTop: rpxToPx(8), marginBottom: rpxToPx(8) }}>{TimeFormatter.dateTimeFormate(info.time.start_timestamp, true)}</View>
  417. <View className="h30 bold white_50">{scenario == 'FAST' ? t('health.adjust_start') : t('health.adjust_bedtime')}</View>
  418. </View>
  419. </NewButton>
  420. <NewButton type={NewButtonType.custom} onClick={() => {
  421. setShowEndDatePicker(true)
  422. }}>
  423. <View className="operate_item" >
  424. <View className={showHighlight ? 'card_highlight end_card_show' : ''} />
  425. <View className="g02 h24 white_50">{scenario == 'FAST' ? t('health.finished') : t('health.wokeup')}</View>
  426. <View className="h44 bold white" style={{ marginTop: rpxToPx(8), marginBottom: rpxToPx(8) }}>{TimeFormatter.dateTimeFormate(info.time.end_timestamp, true)}</View>
  427. <View className="h30 bold white_50">{scenario == 'FAST' ? t('health.adjust_end') : t('health.adjust_wake_up')}</View>
  428. </View>
  429. </NewButton>
  430. </View> :
  431. <View className="white bold" style={{ fontSize: rpxToPx(72), display: 'flex', alignItems: 'center', justifyContent: 'center', flex: 1 }}>{scenario == 'FAST' ? t('health.fast_finished') : t('health.sleep_finished')}</View>
  432. }
  433. </View>
  434. }
  435. </View>
  436. {/* {
  437. showResult && <View style={{ opacity: 0 }}><View className="shareBtnAni" >
  438. <ShareBtn hideShare={true}>
  439. <NewButton type={NewButtonType.custom}>
  440. <View className="share_btn1" style={{ backgroundColor: MainColorType.success }}>
  441. <Image src={require('@assets/_health/wechat.png')} style={{ width: rpxToPx(48), height: rpxToPx(48) }} />
  442. <View className="white bold h34">Send to friends</View>
  443. </View>
  444. </NewButton>
  445. </ShareBtn>
  446. </View>
  447. </View>
  448. } */}
  449. {
  450. showResult && <NewButton type={NewButtonType.custom}
  451. onClick={() => {
  452. Taro.reLaunch({
  453. url: '/pages/moment/moment'
  454. })
  455. }}
  456. ><View
  457. className="bold h30 momentBtnAni" style={{ marginTop: rpxToPx(26) }}>{t('health.view_in_moments')}</View>
  458. </NewButton>
  459. }
  460. {
  461. showResult && <NewButton type={NewButtonType.custom} onClick={() => {
  462. Taro.redirectTo({
  463. url: `./log_record?scenario=MEAL`
  464. })
  465. }}><View
  466. className="h30 bold white_75 eatBtnAni" style={{
  467. backgroundColor: MainColorType.black_05,
  468. marginTop: rpxToPx(26),
  469. width: rpxToPx(698),
  470. height: rpxToPx(108),
  471. borderRadius: rpxToPx(28),
  472. display: 'flex',
  473. alignItems: 'center',
  474. justifyContent: 'center'
  475. }}>
  476. {t('health.what_eating')}
  477. </View>
  478. </NewButton>
  479. }
  480. </View>
  481. }
  482. }
  483. function naviTitle() {
  484. switch (status) {
  485. case 'WFS':
  486. return scenario == 'FAST' ? t('health.upcoming_fast') : t('health.upcoming_sleep')
  487. case 'OG':
  488. return scenario == 'FAST' ? t('health.you_are_fasting') : t('health.your_are_sleeping')
  489. case 'DONE':
  490. return scenario == 'FAST' ? 'Fast completed' : 'Sleep completed'
  491. }
  492. }
  493. function bgView() {
  494. if (process.env.TARO_ENV == 'weapp') {
  495. return <View className="main_bg" style={{ background: getBackground() }} />
  496. }
  497. var time = record.time
  498. if (!time) return <View />
  499. const { background_colors } = time
  500. if (!background_colors) {
  501. return <View />
  502. }
  503. else if (background_colors.length == 1) {
  504. return <View />
  505. }
  506. return <LinearGradient style={{
  507. position: 'absolute',
  508. left: 0,
  509. top: 0,
  510. width: rpxToPx(750),
  511. height: screenHeight,
  512. zIndex: 0,
  513. pointerEvents: 'none'
  514. }}
  515. colors={[background_colors[0], background_colors[1]]}
  516. start={{ x: 0, y: 0 }}
  517. end={{ x: 0, y: 1 }} pointerEvents="none" />
  518. }
  519. function render() {
  520. return <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
  521. {/* <View className="main_bg" style={{ background: getBackground() }} /> */}
  522. {
  523. bgView()
  524. }
  525. <View className="navi_bar" style={{ height: navigationBarHeight }}>
  526. <View style={{
  527. position: 'absolute',
  528. left: 0,
  529. right: 0,
  530. bottom: 0,
  531. height: 44,
  532. display: 'flex',
  533. alignItems: 'center',
  534. justifyContent: 'center'
  535. }}>
  536. <Image src={require('@assets/_health/navi_back.png')} style={{
  537. position: 'absolute',
  538. width: rpxToPx(92),
  539. height: rpxToPx(64),
  540. left: 0,
  541. top: 22 - rpxToPx(32)
  542. }}
  543. onClick={() => {
  544. process.env.TARO_ENV == 'weapp' ? Taro.navigateBack() : navigation.goBack()
  545. }}
  546. />
  547. <View className="h36 bold">{naviTitle()}</View>
  548. </View>
  549. </View>
  550. <View style={{ height: rpxToPx(26) + navigationBarHeight }} />
  551. <View className="progress_card">
  552. <View onClick={() => {
  553. tapClock()
  554. // setShowDurationPicker(true)
  555. }}>
  556. <RingProgress
  557. radius={rpxToPx(250)} canvasId="helloworld"
  558. //scale={0.75}
  559. count={count}
  560. bgRing={{
  561. color: 'rgba(255,255,255,0.25)',
  562. width: rpxToPx(88)
  563. }}
  564. target={{
  565. color: 'rgba(255,255,255,0.5)',
  566. width: rpxToPx(88),
  567. start: status == 'WFS' ? getStartArc(new Date().getTime()) : getStartArc(info.time.start_timestamp),
  568. duration: status == 'WFS' ? getDurationArc(new Date().getTime(), new Date().getTime() + info.time.duration) : getDurationArc(info.time.start_timestamp, info.time.start_timestamp + info.time.duration)
  569. }}
  570. real={status == 'WFS' ? null : {
  571. color: themeColor,
  572. width: rpxToPx(88),
  573. start: getStartArc(info.time.start_timestamp),
  574. duration: getDurationArc(info.time.start_timestamp, new Date().getTime())
  575. }}
  576. extra={ringExtra()}
  577. />
  578. </View>
  579. {
  580. status == 'OG' && <View className="operate_content" style={{ marginTop: -rpxToPx(20) }}>
  581. <NewButton type={NewButtonType.custom} onClick={() => {
  582. setShowDatePicker(true)
  583. }}>
  584. <View className="operate_item">
  585. <View className={showHighlight ? 'card_highlight start_card_show' : ''} />
  586. <View className="black_50 h24">{scenario == 'FAST' ? t('health.started') : t('health.bedtime1')}</View>
  587. <View className="h44 bold" style={{ marginTop: rpxToPx(8), marginBottom: rpxToPx(8) }}>{TimeFormatter.abbrTimestampFormat(info.time.start_timestamp)}</View>
  588. <View className="h30 bold" style={{ color: themeColor }}>{scenario == 'FAST' ? t('health.adjust_start') : t('health.adjust_bedtime')}</View>
  589. </View>
  590. </NewButton>
  591. <NewButton type={NewButtonType.custom} onClick={() => {
  592. setShowDurationPicker(true)
  593. }}>
  594. <View className="operate_item">
  595. <View className="black_50 h24">{t('health.time_goal', { time: TimeFormatter.formateDurationBySeconds(info.time.duration / 1000) })}</View>
  596. <View className="h44 bold" style={{ marginTop: rpxToPx(8), marginBottom: rpxToPx(8) }}>{TimeFormatter.abbrTimestampFormat(info.time.target_end_timestamp)}</View>
  597. <View className="h30 bold" style={{ color: themeColor }}>{t('health.adjust_goal')}</View>
  598. </View>
  599. </NewButton>
  600. </View>
  601. }
  602. {
  603. status == 'WFS' && <NewButton
  604. type={NewButtonType.fill}
  605. title={scenario == 'FAST' ? record.actions.FAST_START : record.actions.SLEEP_BEDTIME}
  606. width={rpxToPx(490)}
  607. height={rpxToPx(108)}
  608. color={themeColor}
  609. onClick={start}
  610. />
  611. }
  612. {
  613. status == 'OG' && <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}><NewButton
  614. type={NewButtonType.fill}
  615. title={scenario == 'FAST' ? record.actions.FAST_END : record.actions.SLEEP_WAKE_UP}
  616. width={rpxToPx(490)}
  617. height={rpxToPx(108)}
  618. color={themeColor}
  619. onClick={end}
  620. />
  621. {/* <NewButton
  622. type={NewButtonType.more}
  623. onClick={more}
  624. /> */}
  625. <NewButton
  626. type={NewButtonType.img}
  627. btnStyle={{ marginRight: -rpxToPx(72) }}
  628. onClick={more}
  629. >
  630. <View style={{ width: rpxToPx(72), height: rpxToPx(72), display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
  631. <IconMore2 width={rpxToPx(36)} color="#000" />
  632. </View>
  633. </NewButton>
  634. {/* <View onClick={more}>More</View> */}
  635. </View>
  636. }
  637. {
  638. status == 'OG' && <View className="share_icon">
  639. <ShareBtn>
  640. <Image onClick={() => {
  641. // setShareUrl('')
  642. // setShowShare(true)
  643. }} src={require('@assets/_health/wechat.png')} style={{
  644. width: rpxToPx(72),
  645. height: rpxToPx(72)
  646. }} />
  647. </ShareBtn>
  648. </View>
  649. }
  650. </View>
  651. {/* {
  652. status == 'WFS' && <View className="eat_card" onClick={() => {
  653. Taro.redirectTo({
  654. url: `./log_record?scenario=${scenario == 'FAST' ? 'MEAL' : 'ACTIVITY'}`
  655. })
  656. }}>
  657. <View className="h30 bold">Or share your meals</View>
  658. <View className="h24 g02" style={{ marginTop: rpxToPx(12) }}>if you haven't started fasting yet</View>
  659. <View className="eat_card_arrow">
  660. <IconArrow width={rpxToPx(34)} color={MainColorType.black_25} />
  661. </View>
  662. </View>
  663. } */}
  664. {
  665. router.params.join_id && <FollowInfo user={long.follow} timeMode={true} />
  666. }
  667. {/* {
  668. status == 'OG' && <View className="eat_card" style={{ height: rpxToPx(120) }} onClick={() => {
  669. Taro.redirectTo({
  670. url: `./log_record?scenario=${scenario == 'FAST' ? 'MEAL' : 'ACTIVITY'}`
  671. })
  672. }}>
  673. <View className="h24 g02" style={{ marginTop: rpxToPx(12) }}>How are you feeling?</View>
  674. <View className="eat_card_arrow">
  675. <IconArrow width={rpxToPx(34)} color={MainColorType.g02} />
  676. </View>
  677. </View>
  678. } */}
  679. {/* {
  680. showDurationPicker && <Modal
  681. testInfo={null}
  682. dismiss={() => {
  683. setShowDurationPicker(false)
  684. }}
  685. confirm={() => { }}>
  686. {
  687. <NewDurationPicker type={DurationPickerType.normal} value={info.time.duration} onChange={(e) => {
  688. console.log(e)
  689. var obj = JSON.parse(JSON.stringify(info))
  690. obj.time.duration = e
  691. setInfo(obj)
  692. }} />
  693. }
  694. </Modal>
  695. } */}
  696. {
  697. showShare && <View className="share_bg">
  698. {
  699. shareUrl == '' && <View className="share_canvas">
  700. <RingProgress
  701. radius={rpxToPx(250)} canvasId="helloworld_share"
  702. //scale={0.75}
  703. count={count}
  704. bgRing={{
  705. color: 'rgba(255,255,255,0.25)',
  706. width: rpxToPx(88)
  707. }}
  708. target={{
  709. color: 'rgba(255,255,255,0.5)',
  710. width: rpxToPx(88),
  711. start: status == 'WFS' ? getStartArc(new Date().getTime()) : getStartArc(info.time.start_timestamp),
  712. duration: status == 'WFS' ? getDurationArc(new Date().getTime(), new Date().getTime() + info.time.duration) : getDurationArc(info.time.start_timestamp, info.time.start_timestamp + info.time.duration)
  713. }}
  714. real={status == 'WFS' ? null : {
  715. color: themeColor,
  716. width: rpxToPx(88),
  717. start: getStartArc(info.time.start_timestamp),
  718. duration: getDurationArc(info.time.start_timestamp, new Date().getTime())
  719. }}
  720. extra={ringExtra()}
  721. shareBg={[record.time.background_colors[0], record.time.background_colors[1]]}
  722. shareCover={
  723. url => {
  724. setShareUrl(url)
  725. }
  726. }
  727. />
  728. </View>
  729. }
  730. <View className="navi_bar" style={{ height: navigationBarHeight }}>
  731. <View style={{
  732. position: 'absolute',
  733. left: 0,
  734. right: 0,
  735. bottom: 0,
  736. height: 44,
  737. display: 'flex',
  738. alignItems: 'center',
  739. justifyContent: 'center'
  740. }}>
  741. <View style={{
  742. position: 'absolute',
  743. width: rpxToPx(92),
  744. height: rpxToPx(64),
  745. left: 22,
  746. top: 22 - rpxToPx(32)
  747. }}
  748. onClick={() => {
  749. setShowShare(false)
  750. }}>
  751. <IconClose color="#fff" width={rpxToPx(64)} height={rpxToPx(64)} />
  752. </View>
  753. </View>
  754. </View>
  755. <View className="share_card" style={{ background: record.time.background_colors[1] }}>
  756. {
  757. shareUrl.length > 0 ? <Image src={shareUrl} style={{ width: rpxToPx(900), height: rpxToPx(720), flexShrink: 0 }} /> :
  758. <View style={{ width: rpxToPx(900), height: rpxToPx(720), backgroundColor: MainColorType.g02, flexShrink: 0 }} />
  759. }
  760. {
  761. status == 'OG' && <View className="operate_content" style={{ marginTop: -rpxToPx(20) }}>
  762. <View className="operate_item">
  763. <View className="black_50 h24">STARTED</View>
  764. <View className="h44 bold" style={{ marginTop: rpxToPx(8), marginBottom: rpxToPx(8) }}>{TimeFormatter.dateTimeFormate(info.time.start_timestamp, true)}</View>
  765. </View>
  766. <View className="operate_item">
  767. <View className="black_50 h24">{TimeFormatter.formateDurationBySeconds(info.time.duration / 1000)} Goal</View>
  768. <View className="h44 bold" style={{ marginTop: rpxToPx(8), marginBottom: rpxToPx(8) }}>{TimeFormatter.dateTimeFormate(info.time.target_end_timestamp, true)}</View>
  769. </View>
  770. </View>
  771. }
  772. </View>
  773. <ShareBtn hideShare={true}>
  774. <NewButton type={NewButtonType.custom} btnStyle={{ opacity: 0 }}>
  775. <View className="share_btn1" style={{ backgroundColor: MainColorType.success }}>
  776. <Image src={require('@assets/_health/wechat.png')} style={{ width: rpxToPx(48), height: rpxToPx(48) }} />
  777. <View className="white bold h34">Send to friends</View>
  778. </View>
  779. </NewButton>
  780. </ShareBtn>
  781. </View>
  782. }
  783. </View>
  784. }
  785. return <View>
  786. {
  787. status == 'DONE' ? doneComponent() : render()
  788. }
  789. {
  790. showDatePicker && <PickerCard onClose={() => { setShowDatePicker(false) }}
  791. value={info.time.start_timestamp}
  792. type="datetime"
  793. title={pickerTitle}
  794. error={postError}
  795. onConfirm={(e) => {
  796. update({
  797. start_timestamp: e
  798. })
  799. console.log(e)
  800. // var obj = JSON.parse(JSON.stringify(info))
  801. // obj.time.duration = e
  802. // setInfo(obj)
  803. }}
  804. />
  805. }
  806. {
  807. showEndDatePicker && <PickerCard onClose={() => { setShowEndDatePicker(false) }}
  808. value={info.time.end_timestamp}
  809. type="datetime"
  810. title={pickerTitle}
  811. error={postError}
  812. onConfirm={(e) => {
  813. update({
  814. end_timestamp: e
  815. })
  816. console.log(e)
  817. // var obj = JSON.parse(JSON.stringify(info))
  818. // obj.time.duration = e
  819. // setInfo(obj)
  820. }}
  821. />
  822. }
  823. {
  824. showDurationPicker && <PickerCard onClose={() => { setShowDurationPicker(false) }}
  825. value={info.time.duration}
  826. type="duration"
  827. title={pickerTitle}
  828. onConfirm={(e) => {
  829. var obj = JSON.parse(JSON.stringify(info))
  830. obj.time.duration = e
  831. setInfo(obj)
  832. if (status == 'WFS') {
  833. setShowDurationPicker(false)
  834. return
  835. }
  836. update({
  837. duration: e
  838. })
  839. }}
  840. />
  841. }
  842. <MomentDetailShare
  843. user={user}
  844. canvas_id="time_record"
  845. btnColor={themeColor} />
  846. </View>
  847. }