log_time.tsx 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  1. import { View, Text, Image } from "@tarojs/components";
  2. import './log_time.scss'
  3. import './fast_sleep.scss'
  4. import { useSelector } from "react-redux";
  5. import { useEffect, useRef, useState } from "react";
  6. import NewButton, { NewButtonType } from "../base/new_button";
  7. import { rpxToPx } from "@/utils/tools";
  8. import { getThemeColor } from "@/features/health/hooks/health_hooks";
  9. import NewTimePicker from "../base/new_timepicker";
  10. import { IconCalendar } from "@/components/basic/Icons";
  11. import dayjs from "dayjs";
  12. import { useRouter } from "@tarojs/taro";
  13. import Card from "../components/card";
  14. import { MainColorType } from "@/context/themes/color";
  15. import Taro from "@tarojs/taro";
  16. import { clockTimes, fastWithSleep } from "@/services/health";
  17. import NewDurationPicker, { DurationPickerType } from "../base/new_durationpicker";
  18. import showAlert from "@/components/basic/Alert";
  19. let useRoute;
  20. let useNavigation;
  21. let scenario = '';
  22. if (process.env.TARO_ENV == 'rn') {
  23. useRoute = require("@react-navigation/native").useRoute
  24. useNavigation = require("@react-navigation/native").useNavigation
  25. }
  26. export default function LogTime() {
  27. let router
  28. let navigation;
  29. if (useNavigation) {
  30. navigation = useNavigation()
  31. }
  32. if (process.env.TARO_ENV == 'rn') {
  33. router = useRoute()
  34. }
  35. else {
  36. router = useRouter()
  37. }
  38. const [enterTime, setEnterTime] = useState(new Date().getTime())
  39. const isSingle = router.params.single == '1'
  40. const isFast = router.params.window == 'FAST'
  41. const isStart = router.params.is_start == '1'
  42. const isFastWithSleep = router.params.is_fast_with_sleep == '1'
  43. const type = router.params.type
  44. const [data, setData] = useState<any>(null)
  45. const health = useSelector((state: any) => state.health);
  46. const [showGoal, setShowGoal] = useState(false)
  47. const tapIndex = router.params.index ?? 0
  48. const [expandIndex, setExpandIndex] = useState(router.params.initIndex ? router.params.initIndex : tapIndex)
  49. const [array, setArray] = useState<any>([])
  50. const [errors, setErrors] = useState<any>([])
  51. const [showSuccess, setShowSuccess] = useState(false)
  52. const [conflicts, setConflicts] = useState<any>([])
  53. const [loaded, setLoaded] = useState(false)
  54. const [autoCheck, setAutoCheck] = useState(false)
  55. const [initCheck, setInitCheck] = useState(router.params.initCheck == '1')
  56. const [ignoreCheck, setIgnoreCheck] = useState(false)
  57. useEffect(() => {
  58. if (isSingle) {
  59. if (isFast) {
  60. Taro.setNavigationBarTitle({
  61. title: isStart ? '开始断食' : '结束断食'
  62. });
  63. }
  64. else {
  65. Taro.setNavigationBarTitle({
  66. title: isStart ? '就寝' : '起床'
  67. });
  68. }
  69. }
  70. loadData()
  71. var now = new Date()
  72. var t = now.getTime()
  73. now.setHours(0)
  74. now.setMilliseconds(0)
  75. now.setSeconds(0)
  76. now.setMinutes(0)
  77. var t2 = now.getTime()
  78. t2 += 24 * 3600 * 1000
  79. var left = t2 - t + 500
  80. setTimeout(() => {
  81. setArray(array => {
  82. array.map((item) => {
  83. item.today = false
  84. })
  85. return array;
  86. })
  87. }, left)
  88. }, [])
  89. useEffect(() => {
  90. if (autoCheck) {
  91. if (ignoreCheck) {
  92. setIgnoreCheck(false)
  93. }
  94. else {
  95. tapCommit(true)
  96. }
  97. }
  98. if (initCheck && array.length > 0) {
  99. tapCommit(true, true)
  100. setInitCheck(false)
  101. }
  102. }, [array])
  103. function loadData() {
  104. fastWithSleep().then(res => {
  105. setData(res)
  106. initDatas(res)
  107. setAutoCheck(true)
  108. })
  109. }
  110. function initDatas(res = data) {
  111. const { fast, sleep } = res
  112. var list: any = []
  113. if (isSingle) {
  114. var timeline: any;
  115. if (isFast) {
  116. timeline = isStart ? fast.timeline[0] : fast.timeline[1]
  117. }
  118. else {
  119. timeline = isStart ? sleep.timeline[0] : sleep.timeline[1]
  120. }
  121. list.push({
  122. event_id: timeline.event_id,
  123. schedule_id: timeline.schedule_id,
  124. time: dayjs().format('HH:mm'),
  125. today: true,
  126. extra: {
  127. set_time: enterTime,
  128. confirm_time: enterTime
  129. }
  130. })
  131. setExpandIndex(0)
  132. }
  133. else {
  134. for (var i = 0; i <= tapIndex; i++) {
  135. // if (type == 'home'){
  136. // if (tapIndex == 2){
  137. // if (i == 0 || i==3){
  138. // continue;
  139. // }
  140. // }
  141. // else if (tapIndex ==3){
  142. // if (i==1||i==2){
  143. // continue;
  144. // }
  145. // }
  146. // }
  147. var timeline: any;
  148. if (i == 0 || i == 3) {
  149. timeline = i == 0 ? fast.timeline[0] : fast.timeline[1]
  150. }
  151. else {
  152. timeline = i == 1 ? sleep.timeline[0] : sleep.timeline[1]
  153. }
  154. list.push({
  155. event_id: timeline.event_id,
  156. schedule_id: timeline.schedule_id,
  157. time: dayjs().format('HH:mm'),
  158. today: true,
  159. extra: {
  160. set_time: enterTime,
  161. confirm_time: enterTime
  162. }
  163. })
  164. }
  165. //逆推初始化时间
  166. var fastStartTime = new Date().getTime()
  167. var fastEndTime = new Date().getTime()
  168. var sleepStartTime = new Date().getTime()
  169. var sleepEndTime = new Date().getTime()
  170. fastStartTime = fastEndTime - fast.target.duration
  171. var fastEndtoWakeDuration = 0
  172. var time1 = fast.period.end_time
  173. var time2 = sleep.period.end_time
  174. var t1 = parseInt(time1.split(':')[0]) * 60 + parseInt(time1.split(':')[1])
  175. var t2 = parseInt(time2.split(':')[0]) * 60 + parseInt(time2.split(':')[1])
  176. fastEndtoWakeDuration = t1 - t2 > 0 ? (t1 - t2) * 60 * 1000 : (t1 - t2) * 60 * 1000 + 24 * 3600 * 1000
  177. sleepEndTime = fastEndTime - fastEndtoWakeDuration//(fast.target.end_timestamp-sleep.target.end_timestamp)
  178. sleepStartTime = sleepEndTime - sleep.target.duration
  179. var isConflict = false;
  180. if (fast.real && fast.real.start_timestamp && fast.real.start_timestamp > fastStartTime) {
  181. isConflict = true;
  182. }
  183. else if (sleep.real && sleep.real.start_timestamp && sleep.real.start_timestamp > sleepStartTime) {
  184. isConflict = true;
  185. }
  186. else if (sleep.real && sleep.real.end_timestamp && sleep.real.end_timestamp > sleepEndTime) {
  187. isConflict = true;
  188. }
  189. if (!isConflict) {
  190. var fastStartToday = new Date().getDate() == new Date(fastStartTime).getDate()
  191. list[0].today = fastStartToday
  192. list[0].time = dayjs(fastStartTime).format('HH:mm')
  193. var sleepStartToday = new Date().getDate() == new Date(sleepStartTime).getDate()
  194. list[1].today = sleepStartToday
  195. list[1].time = dayjs(sleepStartTime).format('HH:mm')
  196. if (list.length > 2) {
  197. var sleepEndToday = new Date().getDate() == new Date(sleepEndTime).getDate()
  198. list[2].today = sleepEndToday
  199. list[2].time = dayjs(sleepEndTime).format('HH:mm')
  200. }
  201. }
  202. if (fast.real && fast.real.start_timestamp) {
  203. var fastStartToday = new Date().getDate() == new Date(fast.real.start_timestamp).getDate()
  204. list[0].today = fastStartToday
  205. list[0].disable = true
  206. list[0].time = dayjs(fast.real.start_timestamp).format('HH:mm')
  207. }
  208. if (sleep.real && sleep.real.start_timestamp) {
  209. var sleepStartToday = new Date().getDate() == new Date(sleep.real.start_timestamp).getDate()
  210. list[1].today = sleepStartToday
  211. list[1].disable = true
  212. list[1].time = dayjs(sleep.real.start_timestamp).format('HH:mm')
  213. }
  214. if (list.length > 2 && sleep.real && sleep.real.end_timestamp) {
  215. var sleepEndToday = new Date().getDate() == new Date(sleep.real.end_timestamp).getDate()
  216. list[2].today = sleepEndToday
  217. list[2].disable = true
  218. list[2].time = dayjs(sleep.real.end_timestamp).format('HH:mm')
  219. }
  220. }
  221. setArray(list)
  222. setLoaded(true)
  223. }
  224. function footerBtnColor() {
  225. if (isSingle) {
  226. return isFast ? MainColorType.fast : MainColorType.sleep
  227. }
  228. return MainColorType.fast
  229. }
  230. function getTimestamp(obj) {
  231. var time = obj.time
  232. var hour = parseInt(time.split(':')[0])
  233. var minute = parseInt(time.split(':')[1])
  234. var today = obj.today
  235. var now = new Date()
  236. now.setHours(hour)
  237. now.setMinutes(minute)
  238. now.setSeconds(0)
  239. now.setMilliseconds(0)
  240. var timestamp = now.getTime()
  241. if (!today) {
  242. timestamp -= 24 * 3600 * 1000
  243. }
  244. return timestamp
  245. }
  246. function tapCommit(onlyCheck, firstCheck = false) {
  247. var list: any = []
  248. if (isSingle) {
  249. var obj = array[0]
  250. var timestamp = getTimestamp(obj)
  251. var params: any = {
  252. schedule_id: obj.schedule_id,
  253. event_id: obj.event_id ? obj.event_id : null,
  254. extra: obj.extra,
  255. date: dayjs(timestamp).format('YYYYMMDD'),
  256. timestamp: timestamp,
  257. }
  258. if (isStart) {
  259. params.duration = isFast ? data.fast.target.duration : data.sleep.target.duration
  260. }
  261. list.push(params)
  262. }
  263. else {
  264. if (type == 'home') {
  265. if (parseInt(tapIndex + '') == 2) {
  266. var obj = array[1]
  267. var timestamp = getTimestamp(obj)
  268. list.push({
  269. schedule_id: obj.schedule_id,
  270. event_id: obj.event_id ? obj.event_id : null,
  271. extra: obj.extra,
  272. date: dayjs(timestamp).format('YYYYMMDD'),
  273. timestamp: timestamp,
  274. })
  275. var obj2 = array[2]
  276. var timestamp2 = getTimestamp(obj2)
  277. list.push({
  278. schedule_id: obj2.schedule_id,
  279. event_id: obj.event_id ? obj.event_id : null,
  280. extra: obj2.extra,
  281. date: dayjs(timestamp2).format('YYYYMMDD'),
  282. timestamp: timestamp2,
  283. })
  284. }
  285. if (parseInt(tapIndex + '') == 3) {
  286. var obj = array[0]
  287. var timestamp = getTimestamp(obj)
  288. list.push({
  289. schedule_id: obj.schedule_id,
  290. event_id: obj.event_id ? obj.event_id : null,
  291. extra: obj.extra,
  292. date: dayjs(timestamp).format('YYYYMMDD'),
  293. timestamp: timestamp,
  294. })
  295. var obj2 = array[3]
  296. var timestamp2 = getTimestamp(obj2)
  297. list.push({
  298. schedule_id: obj2.schedule_id,
  299. event_id: obj.event_id ? obj.event_id : null,
  300. extra: obj2.extra,
  301. date: dayjs(timestamp2).format('YYYYMMDD'),
  302. timestamp: timestamp2,
  303. })
  304. }
  305. }
  306. else {
  307. // const { status } = data
  308. for (var i = 0; i <= tapIndex; i++) {
  309. if (firstCheck && i > 1) {
  310. }
  311. else {
  312. var obj = array[i]
  313. var timestamp = getTimestamp(obj)
  314. list.push({
  315. schedule_id: obj.schedule_id,
  316. event_id: obj.event_id ? obj.event_id : null,
  317. extra: obj.extra,
  318. date: dayjs(timestamp).format('YYYYMMDD'),
  319. timestamp: timestamp,
  320. })
  321. }
  322. }
  323. }
  324. }
  325. if (firstCheck && parseInt(router.params.initIndex) == 1) {
  326. var temps = [list[1], list[0]]
  327. commit(temps, onlyCheck)
  328. }
  329. else {
  330. commit(list, onlyCheck)
  331. }
  332. }
  333. function commit(list, onlyCheck) {
  334. console.log(list)
  335. const sortedData = list.sort((a, b) => {
  336. return b.extra.confirm_time - a.extra.confirm_time; // 降序
  337. });
  338. console.log(sortedData)
  339. clockTimes({
  340. check_items: sortedData,
  341. op_page: isFastWithSleep ? 'FAST_WITH_SLEEP' : null,
  342. only_check: onlyCheck,
  343. extra: {
  344. set_time: enterTime,
  345. confirm_time: new Date().getTime()
  346. }
  347. }).then(res => {
  348. if ((res as any).result) {
  349. setErrors([])
  350. setConflicts([])
  351. if (!onlyCheck) {
  352. global.refreshWindow()
  353. if (global.refreshFastSleep)
  354. global.refreshFastSleep()
  355. Taro.redirectTo({
  356. url: './post_result?data=' + JSON.stringify(res)
  357. })
  358. }
  359. }
  360. else {
  361. setErrors((res as any).error_messages)
  362. setConflicts((res as any).conflict_schedule_ids)
  363. setShowSuccess(true)
  364. setAutoCheck(true)
  365. var tempList = JSON.parse(JSON.stringify(array))
  366. tempList.map(item => {
  367. if ((res as any).conflict_schedule_ids.includes(item.schedule_id)) {
  368. item.disable = false
  369. }
  370. })
  371. setIgnoreCheck(true)
  372. setArray(tempList)
  373. }
  374. // Taro.navigateBack({
  375. // delta: 1
  376. // })
  377. })
  378. }
  379. function changeToScheduleTime(schedule_time, index) {
  380. var nowTime = parseInt(dayjs().format('HHmm'))
  381. var scheduleTime = parseInt(schedule_time.replace(':', ''))
  382. var isToday = true
  383. if (scheduleTime > nowTime) {
  384. isToday = false
  385. }
  386. var list = JSON.parse(JSON.stringify(array))
  387. list[index].today = isToday
  388. list[index].time = schedule_time
  389. list[index].extra.confirm_time = new Date().getTime()
  390. setArray(list)
  391. }
  392. function durationTime() {
  393. const { fast, sleep } = data
  394. var seconds = isFast ? fast.target.duration / 1000 : sleep.target.duration / 1000
  395. var hour = Math.floor(seconds / 3600)
  396. var minutes = Math.floor((seconds % 3600) / 60)
  397. var str = ''
  398. if (hour > 0) {
  399. str = hour + '小时'
  400. }
  401. if (minutes > 0) {
  402. str += minutes + '分钟'
  403. }
  404. return str
  405. }
  406. function changeTimeText(schedule_time, time) {
  407. if (time == schedule_time) {
  408. return `Check in:Today ${dayjs(enterTime).format('HH:mm')}`
  409. }
  410. return `Scheduled for ${schedule_time}`
  411. }
  412. function tapChangeTime(schedule_time, time, index) {
  413. if (time == schedule_time) {
  414. changeToScheduleTime(dayjs(enterTime).format('HH:mm'), index)
  415. }
  416. else {
  417. changeToScheduleTime(schedule_time, index)
  418. }
  419. }
  420. function logItem(index: number, iFast: boolean, iStart: boolean, showLine: boolean) {
  421. const { fast, sleep } = data
  422. var schedule_time = ''
  423. var title = ''
  424. var date = array[index].today ? "Today" : "Yesterday"
  425. var time = array[index].time
  426. const today = dayjs();
  427. var schedule_id = ''
  428. if (iFast) {
  429. schedule_time = iStart ? fast.period.start_time : fast.period.end_time
  430. schedule_id = iStart ? fast.timeline[0].schedule_id : fast.timeline[1].schedule_id
  431. if (!iStart && fast.status == 'OG') {
  432. schedule_time = dayjs(fast.target.end_timestamp).format('HH:mm')
  433. }
  434. title = iStart ? 'Fast starts' : 'Fast ends'
  435. if (array[index].disable) {
  436. var timestamp = iStart ? fast.real.start_timestamp : fast.real.end_timestamp
  437. const dt = dayjs(timestamp);
  438. const yesterday = today.subtract(1, 'day');
  439. time = dayjs(timestamp).format('HH:mm')
  440. if (dt.isSame(today, 'day')) {
  441. date = 'Today';
  442. } else if (dt.isSame(yesterday, 'day')) {
  443. date = 'Yesterday';
  444. } else {
  445. date = dt.format('MM-DD');
  446. }
  447. }
  448. }
  449. else {
  450. schedule_time = iStart ? sleep.period.start_time : sleep.period.end_time
  451. schedule_id = iStart ? sleep.timeline[0].schedule_id : sleep.timeline[1].schedule_id
  452. if (!iStart && sleep.status == 'OG') {
  453. schedule_time = dayjs(sleep.target.end_timestamp).format('HH:mm')
  454. }
  455. title = iStart ? 'Bedtime' : 'Wake up'
  456. if (array[index].disable) {
  457. var timestamp = iStart ? sleep.real.start_timestamp : sleep.real.end_timestamp
  458. const dt = dayjs(timestamp);
  459. const yesterday = today.subtract(1, 'day');
  460. time = dayjs(timestamp).format('HH:mm')
  461. if (dt.isSame(today, 'day')) {
  462. date = 'Today';
  463. } else if (dt.isSame(yesterday, 'day')) {
  464. date = 'Yesterday';
  465. } else {
  466. date = dt.format('MM-DD');
  467. }
  468. }
  469. }
  470. var showError = false;
  471. if (conflicts.includes(schedule_id)) {
  472. showError = true
  473. }
  474. return <View style={{ position: 'relative' }}>
  475. <View className="card_header">
  476. {
  477. showError && <View className="error_icon_bg">
  478. <Image src={require('@assets/_health/tip_error.png')} style={{ width: rpxToPx(26), height: rpxToPx(26) }} />
  479. </View>
  480. }
  481. {
  482. isSingle ? <View style={{ flex: 1 }} /> :
  483. <View className="h34" style={{ flex: 1 }}>{title}</View>
  484. }
  485. <View style={{
  486. borderColor: showError ? 'red' : 'transparent',
  487. borderWidth: rpxToPx(2),
  488. borderRadius: rpxToPx(88 / 4),
  489. borderStyle: 'solid'
  490. }}>
  491. <NewButton
  492. type={NewButtonType.gray}
  493. title={date}
  494. fontSize={rpxToPx(34)}
  495. width={rpxToPx(196)}
  496. height={rpxToPx(84)}
  497. disable={array[index].disable}
  498. onClick={() => {
  499. var list = JSON.parse(JSON.stringify(array))
  500. list[index].today = !list[index].today
  501. list[index].extra.confirm_time = new Date().getTime()
  502. setArray(list)
  503. }}
  504. />
  505. </View>
  506. <View style={{ width: rpxToPx(12) }} />
  507. <View style={{
  508. borderColor: showError ? 'red' : 'transparent',
  509. borderWidth: rpxToPx(2),
  510. borderRadius: rpxToPx(88 / 4),
  511. borderStyle: 'solid'
  512. }}>
  513. <NewButton
  514. type={expandIndex == index ? NewButtonType.alpha : NewButtonType.gray}
  515. color={iFast ? MainColorType.fast : MainColorType.sleep}
  516. title={time}
  517. fontSize={rpxToPx(34)}
  518. width={rpxToPx(136)}
  519. height={rpxToPx(84)}
  520. disable={array[index].disable}
  521. onClick={() => {
  522. setExpandIndex(index)
  523. }}
  524. />
  525. </View>
  526. {
  527. isSingle && <View style={{ flex: 1 }} />
  528. }
  529. <View className='border_footer_line' style={{ left: rpxToPx(66) }} />
  530. </View>
  531. {
  532. expandIndex == index && <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', width: rpxToPx(698) }}>
  533. <NewTimePicker time={array[index].time} onChange={(e) => {
  534. var list = JSON.parse(JSON.stringify(array))
  535. list[index].time = e
  536. list[index].extra.confirm_time = new Date().getTime()
  537. debugger
  538. setArray(list)
  539. }} color={iFast ? MainColorType.fast : MainColorType.sleep} />
  540. </View>
  541. }
  542. {/* {
  543. expandIndex == index && <View className='card_footer' onClick={() => tapChangeTime(schedule_time, time, index)}>
  544. <Text style={{ color: '#5C7099', marginLeft: rpxToPx(12), fontSize: rpxToPx(26) }}>{changeTimeText(schedule_time, time)}</Text>
  545. </View>
  546. } */}
  547. {
  548. expandIndex == index && <View className='card_footer'>
  549. <NewButton type={NewButtonType.link}
  550. title={changeTimeText(schedule_time, time)}
  551. onClick={() => tapChangeTime(schedule_time, time, index)}
  552. >
  553. <View style={{ marginRight: rpxToPx(12), display: 'flex' }}>
  554. <IconCalendar width={rpxToPx(24)} color='#5C7099' />
  555. </View>
  556. </NewButton>
  557. </View>
  558. }
  559. {
  560. showLine && <View className="border_footer_line" style={{ left: rpxToPx(66) }} />
  561. }
  562. </View>
  563. }
  564. function multiContent() {
  565. if (type == 'home') {
  566. switch (parseInt(tapIndex + '')) {
  567. case 2:
  568. return <View style={{ position: 'relative' }}>
  569. {
  570. logItem(1, false, true, false)
  571. }
  572. {
  573. logItem(2, false, false, false)
  574. }
  575. </View>
  576. case 3:
  577. return <View style={{ position: 'relative' }}>
  578. {
  579. logItem(0, true, true, false)
  580. }
  581. {
  582. logItem(3, true, false, false)
  583. }
  584. </View>
  585. }
  586. }
  587. const { status } = data
  588. switch (parseInt(tapIndex + '')) {
  589. case 1:
  590. return <View style={{ position: 'relative' }}>
  591. {
  592. logItem(0, true, true, true)
  593. }
  594. {
  595. logItem(1, false, true, false)
  596. }
  597. </View>
  598. case 2:
  599. return <View style={{ position: 'relative' }}>
  600. {
  601. logItem(0, true, true, true)
  602. }
  603. {
  604. logItem(1, false, true, true)
  605. }
  606. {
  607. logItem(2, false, false, false)
  608. }
  609. </View>
  610. case 3:
  611. return <View style={{ position: 'relative' }}>
  612. {
  613. logItem(0, true, true, true)
  614. }
  615. {
  616. logItem(1, false, true, true)
  617. }
  618. {
  619. logItem(2, false, false, true)
  620. }
  621. {
  622. logItem(3, true, false, false)
  623. }
  624. </View>
  625. }
  626. return <View style={{ position: 'relative' }}></View>
  627. }
  628. function tapFooterBtn(onlyCheck, firstCheck = false) {
  629. var list: any = []
  630. if (isSingle) {
  631. var obj = array[0]
  632. var timestamp = getTimestamp(obj)
  633. var params: any = {
  634. schedule_id: obj.schedule_id,
  635. event_id: obj.event_id ? obj.event_id : null,
  636. extra: obj.extra,
  637. date: dayjs(timestamp).format('YYYYMMDD'),
  638. timestamp: timestamp,
  639. }
  640. if (isStart) {
  641. params.duration = isFast ? data.fast.target.duration : data.sleep.target.duration
  642. }
  643. list.push(params)
  644. }
  645. else {
  646. if (type == 'home') {
  647. if (parseInt(tapIndex + '') == 2) {
  648. var obj = array[1]
  649. var timestamp = getTimestamp(obj)
  650. list.push({
  651. schedule_id: obj.schedule_id,
  652. event_id: obj.event_id ? obj.event_id : null,
  653. extra: obj.extra,
  654. date: dayjs(timestamp).format('YYYYMMDD'),
  655. timestamp: timestamp,
  656. })
  657. var obj2 = array[2]
  658. var timestamp2 = getTimestamp(obj2)
  659. list.push({
  660. schedule_id: obj2.schedule_id,
  661. event_id: obj.event_id ? obj.event_id : null,
  662. extra: obj2.extra,
  663. date: dayjs(timestamp2).format('YYYYMMDD'),
  664. timestamp: timestamp2,
  665. })
  666. }
  667. if (parseInt(tapIndex + '') == 3) {
  668. var obj = array[0]
  669. var timestamp = getTimestamp(obj)
  670. list.push({
  671. schedule_id: obj.schedule_id,
  672. event_id: obj.event_id ? obj.event_id : null,
  673. extra: obj.extra,
  674. date: dayjs(timestamp).format('YYYYMMDD'),
  675. timestamp: timestamp,
  676. })
  677. var obj2 = array[3]
  678. var timestamp2 = getTimestamp(obj2)
  679. list.push({
  680. schedule_id: obj2.schedule_id,
  681. event_id: obj.event_id ? obj.event_id : null,
  682. extra: obj2.extra,
  683. date: dayjs(timestamp2).format('YYYYMMDD'),
  684. timestamp: timestamp2,
  685. })
  686. }
  687. }
  688. else {
  689. // const { status } = data
  690. for (var i = 0; i <= tapIndex; i++) {
  691. if (firstCheck && i > 1) {
  692. }
  693. else {
  694. var obj = array[i]
  695. var timestamp = getTimestamp(obj)
  696. list.push({
  697. schedule_id: obj.schedule_id,
  698. event_id: obj.event_id ? obj.event_id : null,
  699. extra: obj.extra,
  700. date: dayjs(timestamp).format('YYYYMMDD'),
  701. timestamp: timestamp,
  702. })
  703. }
  704. }
  705. }
  706. }
  707. //检查断食时间是否超过24小时
  708. const { fast } = data
  709. if (fast.real) {
  710. var t = fast.real.start_timestamp
  711. var schedule_id = fast.timeline[1].schedule_id
  712. if (list[list.length - 1].schedule_id == schedule_id && list[list.length - 1].timestamp - t > 24 * 3600 * 1000) {
  713. showAlert({
  714. title: 'Saving as Long Fast',
  715. content: 'Fasting that lasts more than 24 hours will be saved as Long Fast. ',
  716. showCancel: true,
  717. cancelText: '取消',
  718. confirmText: '保存',
  719. cancel: () => {
  720. },
  721. confirm: () => {
  722. tapCommit(false)
  723. }
  724. })
  725. return;
  726. }
  727. }
  728. tapCommit(false)
  729. }
  730. if (!loaded) return <View />
  731. return <View className="page_container">
  732. <View style={{ height: rpxToPx(36) }} />
  733. <Card>
  734. <View style={{ display: 'flex', flexDirection: 'column' }}>
  735. {
  736. errors.map((item, index) => {
  737. return <View className="error_bg" key={index}>
  738. <View className="error_icon_bg">
  739. <Image src={require('@assets/_health/tip_error.png')} style={{ width: rpxToPx(26), height: rpxToPx(26) }} />
  740. </View>
  741. <Text className="h24" style={{ lineHeight: rpxToPx(36) + 'px' }}>{item}</Text>
  742. </View>
  743. })
  744. }
  745. {
  746. autoCheck && showSuccess && errors.length == 0 && <View className="error_bg" style={{ backgroundColor: MainColorType.success + '1A' }}>
  747. <View className="error_icon_bg" style={{ backgroundColor: MainColorType.success }}>
  748. <Image src={require('@assets/_health/tip_check.png')} style={{ width: rpxToPx(26), height: rpxToPx(26) }} />
  749. </View>
  750. <Text className="h24" style={{ lineHeight: rpxToPx(36) + 'px' }}>成功提示</Text>
  751. </View>
  752. }
  753. {
  754. isSingle ? <View style={{ position: 'relative' }}>
  755. {
  756. logItem(0, isFast, isStart, false)
  757. }
  758. </View> : multiContent()
  759. }
  760. </View>
  761. </Card>
  762. <View style={{ height: rpxToPx(36) }} />
  763. {
  764. isSingle && isStart && !showGoal && <View style={{ height: rpxToPx(72), marginTop: rpxToPx(18) }}>
  765. <NewButton
  766. type={NewButtonType.link}
  767. title="Show More"
  768. onClick={() => {
  769. setShowGoal(true)
  770. }}
  771. />
  772. </View>
  773. }
  774. {
  775. isSingle && isStart && showGoal && <Card>
  776. <View style={{ position: 'relative' }}>
  777. <View className="card_header" style={{ justifyContent: 'space-between' }}>
  778. <View className="h34">{isFast ? 'Fast Goal' : 'Sleep Goal'}</View>
  779. <NewButton
  780. type={NewButtonType.gray}
  781. height={rpxToPx(84)}
  782. title={durationTime()}
  783. onClick={() => { setExpandIndex(-1) }}
  784. />
  785. </View>
  786. {
  787. expandIndex == -1 && <NewDurationPicker
  788. type={DurationPickerType.normal}
  789. value={isFast ? data.fast.target.duration : data.sleep.target.duration}
  790. onChange={e => {
  791. var temp = JSON.parse(JSON.stringify(data))
  792. if (isFast) {
  793. temp.fast.target.duration = e
  794. }
  795. else {
  796. temp.sleep.target.duration = e
  797. }
  798. setData(temp)
  799. }}
  800. color={isFast ? MainColorType.fast : MainColorType.sleep} />
  801. }
  802. </View>
  803. </Card>
  804. }
  805. <View style={{ flex: 1 }} />
  806. <View style={{ marginBottom: rpxToPx(128), display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
  807. <NewButton
  808. color={footerBtnColor()}
  809. type={NewButtonType.fill}
  810. title={'Log'}
  811. width={rpxToPx(646)}
  812. height={rpxToPx(96)}
  813. bold={true}
  814. onClick={() => tapFooterBtn(false)} />
  815. </View>
  816. </View>
  817. }