RecordFastSleep.tsx 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. import Box from "@/components/layout/Box";
  2. import Header from "@/components/layout/Header";
  3. import Modal from "@/components/layout/Modal.weapp";
  4. import RecordItem from "@/features/common/RecordItem";
  5. import { delRecord } from "@/services/trackTimeDuration";
  6. import { ModalType } from "@/utils/types";
  7. import { View, Text, Image, PageContainer } from "@tarojs/components";
  8. import Taro, { usePageScroll } from "@tarojs/taro";
  9. import { useEffect, useState, memo } from "react";
  10. import TimelineFastSleep from "./TimelineFastSleep";
  11. import { TimeFormatter } from "@/utils/time_format";
  12. import './RecordFastSleep.scss'
  13. import { bigRingRadius, getBgRing, getCommon, getDot, getReal, getTarget, ringWidth, smallRingRadius } from "../hooks/RingData";
  14. import Rings from "./Rings";
  15. import Segment from "@/components/navigation/Segment";
  16. import Stage from "./Stage";
  17. import CenterContentTitleModal from "@/features/common/CenterContentTitleModal";
  18. import { useTranslation } from "react-i18next";
  19. import { ColorType } from "@/context/themes/color";
  20. import TimelineStage from "./TimelineStage";
  21. import { jumpPage } from "../hooks/Common";
  22. import { RealRing, CurrentDot } from "@/features/trackTimeDuration/components/Rings";
  23. import { getTimezone, getTimezoneId, kIsIOS, rpxToPx } from "@/utils/tools";
  24. import { useDispatch, useSelector } from "react-redux";
  25. import { setSelID } from "@/store/common";
  26. import CircadianDetailPopup from "./CircadianDetailPopup";
  27. import dayjs from 'dayjs'
  28. import '@/utils/ring_card.scss';
  29. import showAlert from "@/components/basic/Alert";
  30. // import { sqrt } from 'mathjs'
  31. let AppState;
  32. if (process.env.TARO_ENV == 'rn') {
  33. AppState = require("react-native").AppState
  34. }
  35. let stageCanvasId = new Date().getTime()
  36. let startX = 0
  37. let startY = 0
  38. const utc = require('dayjs/plugin/utc')
  39. const timezone = require('dayjs/plugin/timezone')
  40. var advanced = require("dayjs/plugin/advancedFormat")
  41. dayjs.extend(utc)
  42. dayjs.extend(timezone)
  43. dayjs.extend(advanced)
  44. // let disableDismiss = false
  45. //https://www.php.cn/faq/629819.html
  46. // export default function RecordFastSleep(props: { data: any, type: string, delSuccess?: Function, index: any }) {
  47. const RecordFastSleep = memo((props: { data: any, type: string, index: number, disableDelete?: boolean }) => {
  48. const [count, setCount] = useState(0)
  49. const [showDetailModal, setShowDetailModal] = useState(false)
  50. const [segmentIndex, setSegmentIndex] = useState(0)
  51. const [diffTimeZone, setDiffTimeZone] = useState(false)
  52. const [multiTimeZone, setMultiTimeZone] = useState(false)
  53. const [showMore, setShowMore] = useState(false)
  54. const [selIndex, setSelIndex] = useState(0)
  55. const [showMoreModal, setShowMoreModal] = useState(false)
  56. const [showDel, setShowDel] = useState(false)
  57. const [disableDismiss, setDisableDismiss] = useState(false)
  58. const { t } = useTranslation()
  59. var canvasId = props.data.id
  60. const record = props.data;
  61. const common = useSelector((state: any) => state.common);
  62. const dispatch = useDispatch();
  63. const handleAppStateChange = (nextAppState) => {
  64. checkTimezone()
  65. };
  66. useEffect(() => {
  67. checkTimezone()
  68. if (process.env.TARO_ENV == 'rn') {
  69. AppState.addEventListener('change', handleAppStateChange);
  70. }
  71. if (record.scenario != 'FAST_SLEEP') {
  72. setShowMore(false)
  73. setSelIndex(0)
  74. }
  75. if (props.index == -20000) {
  76. global.refreshRecent = () => {
  77. setCount((index) => index + 1)
  78. }
  79. setTimeout(() => {
  80. setCount((index) => index + 1)
  81. }, 100)
  82. }
  83. // console.log(sqrt(-4).toString())
  84. }, [props.data])
  85. useEffect(() => {
  86. if (common.recordSelID != props.data.id) {
  87. setShowDel(false)
  88. }
  89. }, [common.recordSelID])
  90. function checkTimezone() {
  91. var currentTZ = getTimezone()
  92. var isDiff = false;
  93. var isMulti = false;
  94. var tempTZ = '';
  95. if (props.data.fast) {
  96. if (props.data.fast.real_start_timezone && props.data.fast.real_start_timezone.gmt) {
  97. tempTZ = props.data.fast.real_start_timezone.gmt
  98. if (props.data.fast.real_start_timezone.gmt != currentTZ) {
  99. isDiff = true
  100. }
  101. }
  102. if (props.data.fast.real_end_timezone && props.data.fast.real_end_timezone.gmt) {
  103. if (tempTZ != props.data.fast.real_end_timezone.gmt) {
  104. isMulti = true
  105. }
  106. if (props.data.fast.real_end_timezone.gmt != currentTZ) {
  107. isDiff = true
  108. }
  109. }
  110. }
  111. if (props.data.sleep) {
  112. if (props.data.sleep.real_start_timezone && props.data.sleep.real_start_timezone.gmt) {
  113. if (tempTZ == '') {
  114. tempTZ = props.data.sleep.real_start_timezone.gmt
  115. }
  116. else if (tempTZ != props.data.sleep.real_start_timezone.gmt) {
  117. isMulti = true
  118. }
  119. if (props.data.sleep.real_start_timezone.gmt != currentTZ) {
  120. isDiff = true
  121. }
  122. }
  123. if (props.data.sleep.real_end_timezone && props.data.sleep.real_end_timezone.gmt) {
  124. if (tempTZ != props.data.sleep.real_end_timezone.gmt) {
  125. isMulti = true
  126. }
  127. if (props.data.sleep.real_end_timezone.gmt != currentTZ) {
  128. isDiff = true
  129. }
  130. }
  131. }
  132. setDiffTimeZone(isDiff)
  133. setMultiTimeZone(isMulti)
  134. }
  135. function tapDel() {
  136. showAlert({
  137. title: t('feature.common.modal.delete_item_title'),
  138. content: t('feature.common.modal.delete_item_content'),
  139. showCancel: true,
  140. confirm: () => {
  141. del();
  142. },
  143. cancel: () => {
  144. setShowDel(false)
  145. }
  146. })
  147. }
  148. function del() {
  149. var id = props.data.id
  150. delRecord(id
  151. ).then(res => {
  152. // global.refreshTime()
  153. global.refreshStreaks()
  154. global.indexPageRefresh()
  155. Taro.showToast({
  156. title: t('page.records_history.del_success')
  157. })
  158. dispatch(setSelID(-1))
  159. if (global.checkAccess) {
  160. const currentStatus = (res as any).access.current.qualification.status
  161. const preStatus = (res as any).access.previous.qualification.status
  162. if (currentStatus == 'NOT_QUALIFIED' && preStatus == 'NOT_QUALIFIED'){
  163. }
  164. else {
  165. global.checkAccess((res as any).access)
  166. }
  167. }
  168. if (global.delFastSleep)
  169. global.delFastSleep(props.data)
  170. if (global.delFastSleep2)
  171. global.delFastSleep2(props.data)
  172. // props.delSuccess && props.delSuccess(props.data)
  173. // Taro.navigateBack()
  174. })
  175. }
  176. function subTitle(timestamp) {
  177. if (multiTimeZone) {
  178. return t('feature.common.multi_timezones')
  179. }
  180. if (diffTimeZone) {
  181. return t('feature.common.different_timezone')
  182. }
  183. return TimeFormatter.getDateAndWeek(timestamp)
  184. }
  185. function schedules() {
  186. var timestamp = props.data.first_real_check_time
  187. return <View style={{ display: 'flex', flexDirection: 'column' }}>
  188. <TimelineStage data={props.data} title={t('feature.track_time_duration.record_fast_sleep.pop_title')}
  189. subTitle={subTitle(timestamp)} first_real_check_time={timestamp} diffTimeZone={diffTimeZone} multiTimeZone={multiTimeZone} />
  190. </View>
  191. }
  192. function showDetail(e) {
  193. if (showDel) {
  194. setShowDel(false);
  195. return
  196. }
  197. dispatch(setSelID(-1))
  198. if (props.type == 'latest') {
  199. setSegmentIndex(0)
  200. global.segmentIndex = 0
  201. setShowDetailModal(true)
  202. return;
  203. }
  204. setShowDetailModal(true)
  205. }
  206. function getDuration(obj) {
  207. if (obj.status == 'NOT_STARTED' || obj.status == 'NOT_COMPLETED') {
  208. return ''
  209. }
  210. var start = obj.real_start_time
  211. var end = obj.real_end_time
  212. if (!end) {
  213. end = (new Date()).getTime()
  214. }
  215. return TimeFormatter.durationFormate(start, end)
  216. // return TimeFormatter.calculateTimeDifference(start, end)
  217. }
  218. function getStageDuration() {
  219. var start, end;
  220. switch (selIndex) {
  221. case 0:
  222. start = record.fast.real_start_time
  223. end = record.sleep.real_start_time
  224. break
  225. case 1:
  226. start = record.sleep.real_start_time
  227. end = record.sleep.real_end_time
  228. break
  229. case 2:
  230. start = record.sleep.real_end_time
  231. end = record.fast.real_end_time
  232. break
  233. }
  234. return TimeFormatter.durationFormate(start, end)
  235. }
  236. function durationArc(start_time: number, end_time: number) {
  237. var duration = (end_time - start_time) / 1000;
  238. return duration / (24 * 3600) * 2 * Math.PI;
  239. }
  240. function bigRing() {
  241. var common = getCommon(null, true)
  242. common.radius = bigRingRadius;
  243. common.lineWidth = ringWidth;
  244. var bgRing = getBgRing()
  245. if (props.type == 'record' || props.type == 'latest') {
  246. var realRing = getReal(record, true, true)
  247. if (props.data.status == 'ONGOING3') {
  248. realRing.color = 'rgba(0,0,0,0)'
  249. }
  250. if ((props.data.scenario == 'FAST' && props.data.fast.status == "NOT_COMPLETED") ||
  251. (props.data.scenario == 'SLEEP' && props.data.sleep.status == "NOT_COMPLETED")) {
  252. realRing.durationArc = 0.01
  253. }
  254. if (props.data.scenario == 'FAST_SLEEP' && props.data.fast.status == "NOT_COMPLETED") {
  255. realRing.durationArc = 0.01
  256. }
  257. return <Rings common={common} bgRing={bgRing} canvasId={canvasId} realRing={realRing} />
  258. }
  259. else {
  260. var currentDot1 = getDot(record, true)
  261. var targetBigRing1 = getTarget(record, true)
  262. if (record.status == 'ONGOING') {
  263. var realRing1 = getReal(record, true, false)
  264. return <Rings common={common} bgRing={bgRing} currentDot={currentDot1} realRing={realRing1} targetRing={targetBigRing1} canvasId={canvasId} />
  265. }
  266. if (record.status == 'WAIT_FOR_START') {
  267. return <Rings common={common} bgRing={bgRing} currentDot={currentDot1} canvasId={canvasId} />
  268. }
  269. if (record.status == 'NOT_COMPLETED') {
  270. return <Rings common={common} bgRing={bgRing} currentDot={currentDot1} canvasId={canvasId} />
  271. }
  272. var realRing1 = getReal(record, true, false)
  273. return <Rings common={common} bgRing={bgRing} realRing={realRing1} currentDot={currentDot1} targetRing={targetBigRing1} canvasId={canvasId} />
  274. }
  275. }
  276. function bigMoreRing() {
  277. var common = getCommon(null, true)
  278. common.radius = bigRingRadius;
  279. common.lineWidth = ringWidth;
  280. var bgRing = getBgRing()
  281. var realRing = getReal(record, true, true)
  282. realRing.color = ColorType.fast + '66'
  283. var list: any = []
  284. if (record.scenario == 'FAST_SLEEP') {
  285. if (selIndex == 0) {
  286. const realRingBig: RealRing = {
  287. color: global.fastColor ? global.fastColor : ColorType.fast,
  288. startArc: startArc(record.fast.real_start_time),
  289. durationArc: durationArc(record.fast.real_start_time, record.sleep.real_start_time)
  290. }
  291. list.push(realRingBig)
  292. }
  293. if (selIndex == 1) {
  294. const realRingBig: RealRing = {
  295. color: global.fastColor ? global.fastColor : ColorType.fast,
  296. startArc: startArc(record.sleep.real_start_time),
  297. durationArc: durationArc(record.sleep.real_start_time, record.sleep.real_end_time)
  298. }
  299. list.push(realRingBig)
  300. }
  301. if (selIndex == 2) {
  302. const realRingBig: RealRing = {
  303. color: global.fastColor ? global.fastColor : ColorType.fast,
  304. startArc: startArc(record.sleep.real_end_time),
  305. durationArc: durationArc(record.sleep.real_end_time, record.fast.real_end_time)
  306. }
  307. list.push(realRingBig)
  308. }
  309. }
  310. return <Rings common={common} bgRing={bgRing} canvasId={stageCanvasId} stageList={list} realRing={realRing} />
  311. }
  312. const startArc = (time: number) => {
  313. var date = new Date(time);
  314. var hour = date.getHours();
  315. var minute = date.getMinutes();
  316. var second = date.getSeconds();
  317. return (hour * 3600 + minute * 60 + second) / (24 * 3600) * 2 * Math.PI - Math.PI / 2.0;
  318. }
  319. function smallRing() {
  320. if (record.scenario == 'FAST_SLEEP') {
  321. var common = getCommon(null, false)
  322. common.radius = smallRingRadius;
  323. common.lineWidth = ringWidth;
  324. var bgRing = getBgRing()
  325. var realRing = getReal(record, false, false)
  326. if (props.type == 'record' || props.type == 'latest') {
  327. var showReal = false;
  328. if (record.sleep.status == 'WAIT_FOR_END') {
  329. realRing.durationArc = durationArc(record.sleep.target_start_time, (new Date()).getTime())
  330. showReal = true
  331. // return <Rings common={common} bgRing={bgRing} canvasId={canvasId + 'small'} realRing={realRing} />
  332. }
  333. else if (record.sleep.status == 'NOT_COMPLETED') {
  334. realRing.durationArc = 0.01
  335. showReal = true
  336. // return <Rings common={common} bgRing={bgRing} canvasId={canvasId + 'small'} realRing={realRing} />
  337. }
  338. else if (record.sleep.status == 'COMPLETED') {
  339. realRing = getReal(record, false, true)
  340. showReal = true
  341. // return <Rings common={common} bgRing={bgRing} canvasId={canvasId + 'small'} realRing={realRing} />
  342. }
  343. return <Rings common={common} bgRing={bgRing} canvasId={canvasId + 'small'} realRing={showReal ? realRing : null} />
  344. // if (record.sleep.status == 'WAIT_FOR_END') {
  345. // realRing.durationArc = durationArc(record.sleep.target_start_time, (new Date()).getTime())
  346. // return <Rings common={common} bgRing={bgRing} canvasId={canvasId + 'small'} realRing={realRing} />
  347. // }
  348. // else if (record.sleep.status == 'NOT_COMPLETED') {
  349. // realRing.durationArc = 0.01
  350. // return <Rings common={common} bgRing={bgRing} canvasId={canvasId + 'small'} realRing={realRing} />
  351. // }
  352. // else if (record.sleep.status == 'COMPLETED') {
  353. // realRing = getReal(record, false, true)
  354. // return <Rings common={common} bgRing={bgRing} canvasId={canvasId + 'small'} realRing={realRing} />
  355. // }
  356. // return <Rings common={common} bgRing={bgRing} canvasId={canvasId + 'small'} />
  357. }
  358. else {
  359. var currentDot = getDot(record, false)
  360. var targetRing = getTarget(record, false)
  361. if (record.status == 'ONGOING2') {
  362. var realRing = getReal(record, false, false)
  363. return <Rings common={common} bgRing={bgRing} realRing={realRing} currentDot={currentDot} targetRing={targetRing} canvasId={canvasId + 'small'} />
  364. }
  365. if (record.status == 'ONGOING3') {
  366. currentDot.color = 'rgba(0, 255, 255, 0.5)'
  367. }
  368. return <Rings common={common} bgRing={bgRing} currentDot={currentDot} canvasId={canvasId + 'small'} />
  369. }
  370. }
  371. return null
  372. }
  373. function rings() {
  374. return <View style={{ position: 'relative', zIndex: 1 }}>
  375. {
  376. bigRing()
  377. }
  378. <View style={{ display: 'flex', position: 'absolute', left: 0, right: 0, top: 0, bottom: 0, alignItems: 'center', justifyContent: 'center' }}>
  379. {
  380. smallRing()
  381. }
  382. </View>
  383. </View>
  384. }
  385. function recordTime() {
  386. var timestamp = props.data.first_real_check_time
  387. if (props.data.first_timezone && props.data.first_timezone.gmt) {
  388. timestamp = TimeFormatter.transferTimestamp(timestamp, props.data.first_timezone.gmt)
  389. }
  390. return TimeFormatter.dateDescription(timestamp, true)
  391. }
  392. function getArrowText() {
  393. var timeZoneFormatted = getTimezone()
  394. if (multiTimeZone) {
  395. if (props.data.first_timezone && props.data.first_timezone.id) {
  396. if (kIsIOS) {
  397. if (props.data.first_timezone.id == getTimezoneId()) {
  398. return recordTime()
  399. }
  400. }
  401. else {
  402. if (props.data.first_timezone.gmt == timeZoneFormatted) {
  403. return recordTime()
  404. }
  405. }
  406. if (global.language == 'en') {
  407. return TimeFormatter.tzTimeFormateLocalTime(props.data.first_real_check_time, props.data.first_timezone.id, 'MMM D z')
  408. // return dayjs(props.data.first_real_check_time).tz(props.data.first_timezone.id).format('MMM D z')
  409. }
  410. else {
  411. return TimeFormatter.tzTimeFormateLocalTime(props.data.first_real_check_time, props.data.first_timezone.id, 'M月D日 z')
  412. // return dayjs(props.data.first_real_check_time).tz(props.data.first_timezone.id).format('M月D日 z')
  413. }
  414. }
  415. if (props.data.first_timezone.gmt == timeZoneFormatted) {
  416. return recordTime()
  417. }
  418. return recordTime() + ' ' + props.data.first_timezone.gmt
  419. // return t('feature.common.multi_timezones')
  420. }
  421. if (diffTimeZone) {
  422. if (props.data.first_timezone.id) {
  423. if (kIsIOS) {
  424. if (props.data.first_timezone.id == getTimezoneId()) {
  425. return recordTime()
  426. }
  427. }
  428. else {
  429. if (props.data.first_timezone.gmt == timeZoneFormatted) {
  430. return recordTime()
  431. }
  432. }
  433. if (global.language == 'en') {
  434. return TimeFormatter.tzTimeFormateLocalTime(props.data.first_real_check_time, props.data.first_timezone.id, 'MMM D z')
  435. // return dayjs(props.data.first_real_check_time).tz(props.data.first_timezone.id).format('MMM D z')
  436. }
  437. else {
  438. return TimeFormatter.tzTimeFormateLocalTime(props.data.first_real_check_time, props.data.first_timezone.id, 'M月D日 z')
  439. // return dayjs(props.data.first_real_check_time).tz(props.data.first_timezone.id).format('M月D日 z')
  440. }
  441. }
  442. if (props.data.first_timezone.gmt == timeZoneFormatted) {
  443. return recordTime()
  444. }
  445. return recordTime() + ' ' + props.data.first_timezone.gmt
  446. // return t('feature.common.different_timezone')
  447. }
  448. return recordTime()
  449. }
  450. function tapStage(e, index) {
  451. stageCanvasId = new Date().getTime()
  452. setSelIndex(index);
  453. // setCount(pre=>pre+1);
  454. e.stopPropagation()
  455. }
  456. function moreStage() {
  457. var common = getCommon(null, false)
  458. common.radius = smallRingRadius;
  459. common.lineWidth = ringWidth;
  460. var bgRing = getBgRing()
  461. var realRing = getReal(record, false, true)
  462. return <View style={{ zIndex: 10000 }}>
  463. <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', position: 'relative' }}>
  464. {bigMoreRing()}
  465. <View style={{ display: 'flex', position: 'absolute', left: 0, width: 99, top: 0, height: 99, alignItems: 'center', justifyContent: 'center', zIndex: 10000 }}>
  466. <Rings common={common} bgRing={bgRing} canvasId={stageCanvasId + 'small'} realRing={realRing} />
  467. </View>
  468. <View className="duration_bg">
  469. {
  470. <Text className="duration_title">{t('feature.track_time_duration.record_fast_sleep.item.fast')}</Text>
  471. }
  472. {
  473. <Text className="duration_value" style={{ color: global.fastColor ? global.fastColor : ColorType.fast }}>{getStageDuration()}</Text>
  474. }
  475. {
  476. <Text className="duration_title">{t('feature.track_time_duration.record_fast_sleep.item.sleep')}</Text>
  477. }
  478. {
  479. <Text className="duration_value" style={{ color: global.sleepColor ? global.sleepColor : ColorType.sleep }}>{getDuration(record.sleep)}</Text>
  480. }
  481. </View>
  482. </View>
  483. <View style={{ flex: 1, marginLeft: -rpxToPx(46), marginRight: -rpxToPx(46), marginTop: 20 }}>
  484. <View className={selIndex == 0 ? "single_check_sel" : "single_check_nor"} onClick={(e) => { tapStage(e, 0) }}>
  485. <Text className={selIndex == 0 ? "single_check_text_sel" : "single_check_text_nor"}>{t('feature.track_time_duration.stage.a')}</Text>
  486. {
  487. selIndex == 0 && <Image src={require('@assets/images/check_black.png')} className="single_checked" />
  488. }
  489. </View>
  490. <View className={selIndex == 1 ? "single_check_sel" : "single_check_nor"} onClick={(e) => { tapStage(e, 1) }}>
  491. <Text className={selIndex == 1 ? "single_check_text_sel" : "single_check_text_nor"}>{t('feature.track_time_duration.stage.b')}</Text>
  492. {
  493. selIndex == 1 && <Image src={require('@assets/images/check_black.png')} className="single_checked" />
  494. }
  495. </View>
  496. <View className={selIndex == 2 ? "single_check_sel" : "single_check_nor"} onClick={(e) => { tapStage(e, 2) }}>
  497. <Text className={selIndex == 2 ? "single_check_text_sel" : "single_check_text_nor"}>{t('feature.track_time_duration.stage.c')}</Text>
  498. {
  499. selIndex == 2 && <Image src={require('@assets/images/check_black.png')} className="single_checked" />
  500. }
  501. </View>
  502. </View>
  503. </View>
  504. }
  505. function recordDetail() {
  506. var fastDuration = ''
  507. var sleepDuration = ''
  508. var showFast = false;
  509. var showSleep = false;
  510. if (record.scenario == 'FAST_SLEEP') {
  511. fastDuration = getDuration(record.fast)
  512. sleepDuration = getDuration(record.sleep)
  513. if (record.status == 'ONGOING3') {
  514. fastDuration = t('feature.common.wait_for_end')
  515. }
  516. if (record.status == 'COMPLETED' && record.fast.status == 'NOT_COMPLETED') {
  517. fastDuration = t('feature.common.not_completed')
  518. }
  519. if (record.sleep.status == "NOT_STARTED") {
  520. sleepDuration = t('feature.common.not_started')
  521. }
  522. else if (record.sleep.status == 'NOT_COMPLETED') {
  523. sleepDuration = t('feature.common.not_completed')
  524. }
  525. showFast = true
  526. showSleep = true
  527. }
  528. else if (record.scenario == 'FAST') {
  529. fastDuration = getDuration(record.fast)
  530. if (record.fast.status == 'NOT_COMPLETED') {
  531. fastDuration = t('feature.common.not_completed')
  532. }
  533. showFast = true
  534. }
  535. else {
  536. sleepDuration = getDuration(record.sleep)
  537. if (record.sleep.status == 'NOT_COMPLETED') {
  538. sleepDuration = t('feature.common.not_completed')
  539. }
  540. showSleep = true
  541. }
  542. return <View style={{ display: 'flex', flexDirection: 'column', margin: rpxToPx(8), boxSizing: 'border-box' }}>
  543. <View className="fast_sleep_item1">
  544. {
  545. rings()
  546. }
  547. <View className="duration_bg">
  548. {
  549. showFast && <Text className="duration_title">{t('feature.track_time_duration.record_fast_sleep.item.fast')}</Text>
  550. }
  551. {
  552. showFast && <Text className="duration_value" style={{ color: global.fastColor ? global.fastColor : ColorType.fast }}>{fastDuration}</Text>
  553. }
  554. {
  555. showSleep && <Text className="duration_title">{t('feature.track_time_duration.record_fast_sleep.item.sleep')}</Text>
  556. }
  557. {
  558. showSleep && <Text className="duration_value" style={{ color: global.sleepColor ? global.sleepColor : ColorType.sleep }}>{sleepDuration}</Text>
  559. }
  560. </View>
  561. <View className="record_arrow_bg" style={{ backgroundColor: global.isDebug ? 'red' : 'transparent' }}>
  562. <View style={{ flex: 1 }} />
  563. <Text className='recordTime'>{getArrowText()}</Text>
  564. <Image className="arrow2" src={require('@/assets/images/arrow3.png')} />
  565. </View>
  566. </View>
  567. </View>
  568. }
  569. function touchStart(e) {
  570. if (process.env.TARO_ENV == 'rn' || props.disableDelete) {
  571. return
  572. }
  573. startX = e.touches[0].clientX
  574. startY = e.touches[0].clientY
  575. setDisableDismiss(true)
  576. // disableDismiss = true
  577. }
  578. function touchMove(e) {
  579. if (process.env.TARO_ENV == 'rn' || props.disableDelete) {
  580. return
  581. }
  582. let x = startX
  583. let y = startY
  584. let deltaX = e.touches[0].clientX - x
  585. let deltaY = e.touches[0].clientY - y
  586. if (Math.abs(deltaX) > Math.abs(deltaY)) {
  587. if (deltaX < -80) {
  588. setShowDel(true)
  589. dispatch(setSelID(props.data.id))
  590. global.selId = props.data.id
  591. }
  592. else if (deltaX > 80) {
  593. setShowDel(false)
  594. // global.selId = -1
  595. }
  596. }
  597. }
  598. function touchEnd(e) {
  599. if (process.env.TARO_ENV == 'rn' || props.disableDelete) {
  600. return
  601. }
  602. startX = 0
  603. setDisableDismiss(false)
  604. }
  605. usePageScroll((e) => {
  606. if (showDel && !disableDismiss) {
  607. console.log(disableDismiss)
  608. // setShowDel(false)
  609. }
  610. })
  611. function modalContent() {
  612. return <Modal
  613. testInfo={null}
  614. dismiss={() => {
  615. setShowDetailModal(false)
  616. }}
  617. confirm={() => { }}>
  618. {
  619. <CircadianDetailPopup
  620. record={record}
  621. onClose={() => setShowDetailModal(false)} />
  622. }
  623. </Modal>
  624. }
  625. return <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
  626. <View style={{ position: 'absolute', left: 0, top: 0, width: 0, height: 0, opacity: 0 }}>{count}</View>
  627. <View className='time_operate_item'
  628. onTouchStart={touchStart}
  629. onTouchMove={touchMove}
  630. onTouchEnd={touchEnd}
  631. >
  632. <RecordItem canDel={record.status == 'COMPLETED'}
  633. delete={del}
  634. disableDelete={props.disableDelete}
  635. onClick={showDetail}
  636. >{recordDetail()}
  637. </RecordItem>
  638. {
  639. process.env.TARO_ENV == 'weapp' && <View className={showDel ? 'btnDelete btnDeleteAni' : 'btnDelete'} onClick={tapDel}>{t('feature.track_time_duration.record_fast_sleep.delete')}</View>
  640. }
  641. </View>
  642. {/* {
  643. (props.type == 'record' || props.type == 'latest') &&
  644. record.scenario == 'FAST_SLEEP' &&
  645. record.sleep.status == 'COMPLETED' &&
  646. <View className="more_stage" onClick={(e) => {
  647. e.stopPropagation()
  648. setShowMoreModal(true)
  649. }}>
  650. <Text className="more_stage_text">{showMore ? '隐藏更多' : '显示更多'}</Text>
  651. </View>
  652. } */}
  653. {
  654. showDetailModal && modalContent()
  655. // showDetailModal && <Modal children={schedules()}
  656. // modalType={ModalType.center}
  657. // dismiss={() => setShowDetailModal(false)}
  658. // confirm={() => { }} />
  659. }
  660. {
  661. showMoreModal && <Modal children={moreStage()}
  662. modalType={ModalType.center}
  663. dismiss={() => setShowMoreModal(false)}
  664. confirm={() => { }} />
  665. }
  666. </View>
  667. })
  668. export default RecordFastSleep;