fast_sleep_popup.tsx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. import { View, Image, Text } from "@tarojs/components";
  2. import './fast_sleep_popup.scss'
  3. import Card from "./card";
  4. import NewButton, { NewButtonType } from "../base/new_button";
  5. import { rpxToPx } from "@/utils/tools";
  6. import { useTranslation } from "react-i18next";
  7. import { useSelector } from "react-redux";
  8. import { MainColorType } from "@/context/themes/color";
  9. import { TimeFormatter } from "@/utils/time_format";
  10. import StatusIndicator, { StatusType } from "../base/status_indicator";
  11. import { IconCheck } from "@/components/basic/Icons";
  12. import FastSleepPopupContent from "./fast_sleep_popup_content";
  13. export default function FastSleepPopup(props: { close: any, data: any,top?:number }) {
  14. const health = useSelector((state: any) => state.health);
  15. const { t } = useTranslation()
  16. function total() {
  17. const { fast } = props.data
  18. return diffentTime(fast.period.start_time, fast.period.end_time)
  19. }
  20. function total1() {
  21. const { fast, sleep, status } = props.data
  22. if (status == 'WFS') return ''
  23. var str = ' / ' + diffentTime(fast.period.start_time, sleep.period.start_time)
  24. if (status == 'OG2_NO1') {
  25. return <View className="h24 bold pop_step_right" style={{ color: MainColorType.error }}>{str}</View>
  26. }
  27. return <View className="h24 bold pop_step_right" style={{ color: MainColorType.fast }}>{str}</View>
  28. }
  29. function total2() {
  30. const { sleep, status } = props.data
  31. if (status == 'WFS') return ''
  32. var str = ' / ' + diffentTime(sleep.period.start_time, sleep.period.end_time)
  33. if (status == 'OG2' || status == 'OG2_NO1' || status == 'OG3') {
  34. return <View className="h24 bold pop_step_right" style={{ color: MainColorType.sleep }}>{str}</View>
  35. }
  36. return <View className="h24 bold pop_step_right" style={{ color: MainColorType.g02 }}>{str}</View>
  37. }
  38. function total3() {
  39. const { fast, sleep, status } = props.data
  40. if (status == 'WFS') return ''
  41. var str = ' / ' + diffentTime(sleep.period.end_time, fast.period.end_time)
  42. if (status == 'OG3') {
  43. return <View className="h24 bold pop_step_right" style={{ color: MainColorType.fast }}>{str}</View>
  44. }
  45. return <View className="h24 bold pop_step_right" style={{ color: MainColorType.g02 }}>{str}</View>
  46. }
  47. function step1() {
  48. const { fast, sleep, status } = props.data
  49. if (status == 'OG2_NO1') {
  50. return <View className="time_count h30 bold" style={{ backgroundColor: MainColorType.error }}>00:00:00</View>
  51. }
  52. if (status == 'WFS') {
  53. return <View className="g02 h24 bold" style={{ color: MainColorType.fast }}>{TimeFormatter.calculateTimeDifference(fast.target.start_timestamp, sleep.target.start_timestamp,false,true)}</View>
  54. }
  55. else if (status == 'OG1') {
  56. return <View className="time_count h30 bold" style={{ backgroundColor: MainColorType.fast }}>{TimeFormatter.countdown(fast.real.start_timestamp)}</View>
  57. }
  58. else if (status == 'OG2_NO1') {
  59. return ('')
  60. }
  61. return <View className="line_height_48 h30 bold" style={{ color: MainColorType.fast }}>{TimeFormatter.calculateTimeDifference(fast.real.start_timestamp, sleep.real.start_timestamp,false,true)}</View>
  62. }
  63. function step2() {
  64. const { fast, sleep, status } = props.data
  65. if (status == 'WFS' ) {
  66. return <View className="g02 h24 bold" style={{ color: MainColorType.sleep }}>{TimeFormatter.calculateTimeDifference(sleep.target.start_timestamp, sleep.target.end_timestamp,false,true)}</View>
  67. }
  68. if (status == 'OG1') {
  69. return <View className="time_count h30 bold" style={{ backgroundColor: MainColorType.g03 }}>00:00:00</View>
  70. }
  71. if (status == 'OG2_NO1' || status == 'OG2') {
  72. return <View className="time_count h30 bold" style={{ backgroundColor: MainColorType.sleep }}>{TimeFormatter.countdown(sleep.real.start_timestamp)}</View>
  73. }
  74. else if (status == 'OG3') {
  75. return <View className="h30 bold" style={{ color: MainColorType.sleep }}>{TimeFormatter.calculateTimeDifference(sleep.real.start_timestamp, sleep.real.end_timestamp,false,true)}</View>
  76. }
  77. return <View className="h30 bold" style={{ color: MainColorType.sleep }}>{TimeFormatter.calculateTimeDifference(sleep.target.start_timestamp, sleep.target.end_timestamp,false,true)}</View>
  78. }
  79. function step3() {
  80. const { fast, sleep, status } = props.data
  81. if (status == 'WFS') {
  82. return <View className="g02 h24 bold" style={{ color: MainColorType.fast }}>{TimeFormatter.calculateTimeDifference(sleep.target.end_timestamp, fast.target.end_timestamp,false,true)}</View>
  83. }
  84. if (status == 'OG1' || status == 'OG2_NO1' || status == 'OG2') {
  85. return <View className="time_count h30 bold" style={{ backgroundColor: MainColorType.g03 }}>00:00:00</View>
  86. }
  87. if (status == 'OG3') {
  88. return <View className="time_count h30 bold" style={{ backgroundColor: MainColorType.fast }}>{TimeFormatter.countdown(sleep.real.end_timestamp)}</View>
  89. }
  90. return TimeFormatter.calculateTimeDifference(sleep.target.end_timestamp, fast.target.end_timestamp,false,true)
  91. }
  92. function diffentTime(time2, time1) {
  93. var duration = 0
  94. var t1 = parseInt(time1.split(':')[0]) * 60 + parseInt(time1.split(':')[1])
  95. var t2 = parseInt(time2.split(':')[0]) * 60 + parseInt(time2.split(':')[1])
  96. duration = t1 - t2 >= 0 ? (t1 - t2) * 60 * 1000 : (t1 - t2) * 60 * 1000 + 24 * 3600 * 1000
  97. var now = new Date().getTime()
  98. return TimeFormatter.calculateTimeDifference(now, now + duration,false,true)
  99. }
  100. function beforeStatus() {
  101. const { status } = props.data
  102. var type = StatusType.normal
  103. if (status == 'WFS' || status == 'OG1' || status == 'OG2_NO1') {
  104. type = StatusType.normal
  105. }
  106. else {
  107. type = StatusType.img
  108. }
  109. return type
  110. }
  111. function ingStatus() {
  112. const { status } = props.data
  113. var type = StatusType.normal
  114. if (status == 'WFS' || status == 'OG1' || status == 'OG2_NO1') {
  115. type = StatusType.normal
  116. }
  117. else if (status == 'OG2') {
  118. type = StatusType.normal
  119. }
  120. else {
  121. type = StatusType.img
  122. }
  123. return type;
  124. }
  125. function afterStatus() {
  126. const { status } = props.data
  127. var type = StatusType.normal
  128. if (status == 'WFS' || status == 'OG1' || status == 'OG2' || status == 'OG2_NO1') {
  129. type = StatusType.normal
  130. }
  131. else if (status == 'OG3') {
  132. type = StatusType.normal
  133. }
  134. else {
  135. type = StatusType.img
  136. }
  137. return type;
  138. }
  139. return <FastSleepPopupContent
  140. top={props.top??0}
  141. close={props.close}
  142. status={props.data.status}
  143. beforeStatus={beforeStatus()}
  144. sleepStatus={ingStatus()}
  145. afterStatus={afterStatus()}
  146. showStep={props.data.status == 'WFS' ? false : true}
  147. total={total()}
  148. total1={total1()}
  149. total2={total2()}
  150. total3={total3()}
  151. step1={step1()}
  152. step2={step2()}
  153. step3={step3()}
  154. title={props.data.status == 'WFS' ? t('health.three_stages') : t('health.current_progress')}
  155. />
  156. }