fast_sleep_detail_card.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { View, Text } from '@tarojs/components'
  2. import './fast_sleep_detail_card.scss'
  3. import { MainColorType } from '@/context/themes/color'
  4. import { TimeFormatter } from '@/utils/time_format'
  5. import { rpxToPx } from '@/utils/tools'
  6. export default function FastSleepDetailCard(props: { data: any }) {
  7. function total() {
  8. const { fast } = props.data
  9. return diffentTime(fast.period.start_time, fast.period.end_time)
  10. }
  11. function process() {
  12. const { fast, status } = props.data
  13. if (status == 'OG2_NO1' || status == 'WFS') {
  14. return '-'
  15. }
  16. return TimeFormatter.countdown(fast.real.start_timestamp)
  17. }
  18. function step1() {
  19. const { fast, sleep, status } = props.data
  20. if (status == 'WFS') {
  21. return ('-')
  22. }
  23. else if (status == 'OG1') {
  24. return TimeFormatter.countdown(fast.real.start_timestamp)
  25. }
  26. else if (status == 'OG2_NO1') {
  27. return ('-')
  28. }
  29. return TimeFormatter.calculateTimeDifference(fast.real.start_timestamp, sleep.real.start_timestamp)
  30. }
  31. function step2() {
  32. const { fast, sleep, status } = props.data
  33. if (status == 'WFS' || status == 'OG1') {
  34. return '-'
  35. }
  36. if (status == 'OG2_NO1' || status == 'OG2') {
  37. return TimeFormatter.countdown(sleep.real.start_timestamp)
  38. }
  39. else if (status == 'OG3') {
  40. return TimeFormatter.calculateTimeDifference(sleep.real.start_timestamp, sleep.real.end_timestamp)
  41. }
  42. return TimeFormatter.calculateTimeDifference(sleep.target.start_timestamp, sleep.target.end_timestamp)
  43. }
  44. function step3() {
  45. const { fast, sleep, status } = props.data
  46. if (status == 'WFS' || status == 'OG1' || status == 'OG2_NO1' || status == 'OG2') {
  47. return '-'
  48. }
  49. if (status == 'OG3') {
  50. return TimeFormatter.countdown(sleep.real.end_timestamp)
  51. }
  52. return TimeFormatter.calculateTimeDifference(sleep.target.end_timestamp, fast.target.end_timestamp)
  53. }
  54. function diffentTime(time2, time1) {
  55. var duration = 0
  56. var t1 = parseInt(time1.split(':')[0]) * 60 + parseInt(time1.split(':')[1])
  57. var t2 = parseInt(time2.split(':')[0]) * 60 + parseInt(time2.split(':')[1])
  58. duration = t1 - t2 > 0 ? (t1 - t2) * 60 * 1000 : (t1 - t2) * 60 * 1000 + 24 * 3600 * 1000
  59. var now = new Date().getTime()
  60. return TimeFormatter.calculateTimeDifference(now, now + duration)
  61. }
  62. function total1() {
  63. const { fast, sleep } = props.data
  64. return diffentTime(fast.period.start_time, sleep.period.start_time)
  65. }
  66. function total2() {
  67. const { sleep } = props.data
  68. return diffentTime(sleep.period.start_time, sleep.period.end_time)
  69. }
  70. function total3() {
  71. const { fast, sleep } = props.data
  72. return diffentTime(sleep.period.end_time, fast.period.end_time)
  73. }
  74. return <View style={{ background: '#fff', marginBottom: 20 }}>
  75. <Text>详情</Text>
  76. <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
  77. <View className='h22' style={{ color: MainColorType.g02 }}>断食</View>
  78. <View>{process()}/{total()}</View>
  79. <View style={{ display: 'flex', marginTop: 10, width: rpxToPx(750), flexDirection: 'row', alignItems: 'center', justifyContent: 'space-around' }}>
  80. <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
  81. <View className='h22' style={{ color: MainColorType.g02 }}>睡前断食</View>
  82. <View style={{ color: props.data.status == 'OG1' ? MainColorType.fast : '#000' }}>{step1()}/{total1()}</View>
  83. </View>
  84. <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
  85. <View className='h22' style={{ color: MainColorType.g02 }}>睡眠期间断食</View>
  86. <View style={{ color: props.data.status == 'OG2'||props.data.status == 'OG2_NO1' ? MainColorType.sleep : '#000' }}>{step2()}/{total2()}</View>
  87. </View>
  88. <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
  89. <View className='h22' style={{ color: MainColorType.g02 }}>起床后断食</View>
  90. <View style={{ color: props.data.status == 'OG3' ? MainColorType.fast : '#000' }}>{step3()}/{total3()}</View>
  91. </View>
  92. </View>
  93. </View>
  94. </View>
  95. }