fast_sleep_console.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. import { View, Text, Image } from "@tarojs/components";
  2. import './fast_sleep_console.scss'
  3. import { rpxToPx } from "@/utils/tools";
  4. import NewButton, { NewButtonType } from "../base/new_button";
  5. import { getThemeColor } from "@/features/health/hooks/health_hooks";
  6. import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
  7. import dayjs from "dayjs";
  8. import { MainColorType } from "@/context/themes/color";
  9. import showAlert from "@/components/basic/Alert";
  10. import { IconCellArrow, IconNotification, IconNotificationOff } from "@/components/basic/Icons";
  11. import { useSelector } from "react-redux";
  12. import { delRecord } from "@/services/health";
  13. export default function FastSleepConsole(props: { step: number, data: any, del: any }) {
  14. const health = useSelector((state: any) => state.health);
  15. function tapLogBtn(index: number) {
  16. const { fast, sleep, status } = props.data
  17. var single = 0;
  18. var is_start = 0;
  19. var window = 'FAST'
  20. switch (index) {
  21. case 0:
  22. {
  23. single = 1;
  24. is_start = 1;
  25. }
  26. break;
  27. case 1:
  28. {
  29. if (status == 'OG1') {
  30. single = 1;
  31. is_start = 1;
  32. window = 'SLEEP'
  33. }
  34. else {
  35. single = 0;
  36. }
  37. }
  38. break;
  39. case 2:
  40. {
  41. if (status == 'OG2') {
  42. single = 1;
  43. is_start = 0;
  44. window = 'SLEEP'
  45. }
  46. else {
  47. single = 0;
  48. }
  49. }
  50. break;
  51. case 3:
  52. {
  53. if (status == 'OG3') {
  54. single = 1;
  55. is_start = 0;
  56. window = 'FAST'
  57. }
  58. else {
  59. single = 0;
  60. }
  61. }
  62. break;
  63. }
  64. jumpPage(`/_health/pages/log_time?is_fast_with_sleep=1&index=${index}&initCheck=${health.fast_with_sleep.status == 'OG2_MISALIGNED' ? 1 : 0}&single=${index == 0 ? 1 : 0}&is_start=${is_start}&window=${window}&data=${JSON.stringify(props.data)}`)
  65. /*
  66. const isSingle = router.params.single == '1'
  67. const isFast = router.params.window == 'FAST'
  68. const isStart = router.params.is_start == '1'
  69. */
  70. }
  71. function goDetail(index) {
  72. if (index == 0 && props.data.fast.status == 'OG') {
  73. const { event_id, schedule_id } = props.data.fast.timeline[0]
  74. jumpPage(`/_health/pages/timeline_detail?event_id=${event_id}&schedule_id=${schedule_id}`)
  75. }
  76. else if (index == 1 && (props.data.sleep.status == 'OG' || props.data.status == 'OG3')) {
  77. const { event_id, schedule_id } = props.data.sleep.timeline[0]
  78. jumpPage(`/_health/pages/timeline_detail?event_id=${event_id}&schedule_id=${schedule_id}`)
  79. }
  80. }
  81. function delConfirm() {
  82. const { fast, sleep } = props.data
  83. let array: any = []
  84. if (fast.window_id) {
  85. array.push(fast.window_id)
  86. }
  87. if (sleep.window_id) {
  88. array.push(sleep.window_id)
  89. }
  90. showAlert({
  91. title: 'del',
  92. content: '确认删除此记录?',
  93. showCancel: true,
  94. confirm: () => {
  95. delRecord(array[0], { ids: array.join(',') }).then(res => {
  96. global.refreshWindow()
  97. props.del()
  98. })
  99. }
  100. })
  101. }
  102. function getIconColor(index: number, finish: boolean) {
  103. var color = MainColorType.g03
  104. if (index == 1 || index == 2) {
  105. color = MainColorType.sleep
  106. }
  107. else {
  108. color = MainColorType.fast
  109. }
  110. if (finish) {
  111. color = MainColorType.g03
  112. }
  113. return color;
  114. }
  115. function processIcon(item, finish, isError) {
  116. if (isError) {
  117. return <Image style={{ width: rpxToPx(20), height: rpxToPx(20) }} src={require('@assets/_health/tip_error.png')} />
  118. }
  119. if (finish) {
  120. return <Image style={{ width: rpxToPx(20), height: rpxToPx(20) }} src={require('@assets/_health/checked.png')} />
  121. }
  122. if (item.timeline.reminder) {
  123. return <IconNotification color="#fff" width={rpxToPx(20)} />
  124. }
  125. return <IconNotificationOff color="#fff" width={rpxToPx(20)} />
  126. }
  127. function timelineItem(item: any, index: number, count: number) {
  128. const { fast, sleep, status } = props.data
  129. var showBtn = true;
  130. var time = ''
  131. var hasDescription = item.moment && item.moment.description
  132. var finish = false;
  133. switch (index) {
  134. case 0:
  135. {
  136. if (status == 'OG2_NO1' || status == 'WFS') {
  137. showBtn = true
  138. }
  139. else {
  140. showBtn = false;
  141. finish = true;
  142. }
  143. time = dayjs(fast.target.start_timestamp).format('MM-DD HH:mm')
  144. }
  145. break;
  146. case 1:
  147. {
  148. if (status == 'WFS' || status == 'OG1') {
  149. showBtn = true
  150. }
  151. else {
  152. showBtn = false
  153. finish = true;
  154. }
  155. if (status == 'OG3') {
  156. time = dayjs(sleep.real.start_timestamp).format('MM-DD HH:mm')
  157. }
  158. else {
  159. time = dayjs(sleep.target.start_timestamp).format('MM-DD HH:mm')
  160. }
  161. }
  162. break;
  163. case 2:
  164. {
  165. if (status == 'OG3') {
  166. showBtn = false
  167. finish = true;
  168. time = dayjs(sleep.real.end_timestamp).format('MM-DD HH:mm')
  169. }
  170. else {
  171. showBtn = true
  172. time = dayjs(sleep.target.end_timestamp).format('MM-DD HH:mm')
  173. }
  174. }
  175. break;
  176. case 3:
  177. {
  178. showBtn = true
  179. time = dayjs(fast.target.end_timestamp).format('MM-DD HH:mm')
  180. }
  181. break;
  182. }
  183. var isError = false;
  184. if (health.fast_with_sleep.status == 'OG2_MISALIGNED' && (index == 0 || index == 1)) {
  185. isError = true;
  186. }
  187. return <View key={index}
  188. className="timeline_item"
  189. // hoverClass='cell_hover' hoverStayTime={50}
  190. onClick={() => {
  191. goDetail(index)
  192. }}>
  193. <View className="timeline_left">
  194. <View style={{
  195. height: hasDescription ? rpxToPx(28) : rpxToPx(36), flexShrink: 0
  196. }} />
  197. <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
  198. <View style={{
  199. flexShrink: 0,
  200. width: rpxToPx(26),
  201. height: rpxToPx(26),
  202. borderRadius: rpxToPx(13),
  203. marginRight: rpxToPx(8),
  204. display: 'flex',
  205. alignItems: 'center',
  206. justifyContent: 'center',
  207. backgroundColor: isError ? MainColorType.error : getIconColor(index, finish)
  208. }}>
  209. {
  210. processIcon(item, finish, isError)
  211. }
  212. </View>
  213. <Text className="timeline_time" style={{ color: isError ? MainColorType.error : MainColorType.g01 }}>{time}</Text>
  214. </View>
  215. <Text className="timeline_title"
  216. onClick={() => { }}>{(item.moment && item.moment.title) ? item.moment.title : item.title}</Text>
  217. {
  218. hasDescription && <Text className="timeline_desc">{item.moment.description}</Text>
  219. }
  220. <View style={{
  221. height: hasDescription ? rpxToPx(28) : rpxToPx(54), flexShrink: 0,
  222. }} />
  223. </View>
  224. <View style={{ flex: 1 }} />
  225. {
  226. !isError && item.moment && item.moment.media && item.moment.media.length > 0 && <Image
  227. src={item.moment.media[0].url}
  228. mode="aspectFill"
  229. className="console_item_img" />
  230. }
  231. {
  232. !isError && showBtn && <NewButton
  233. color={getThemeColor(item.mode)}
  234. type={NewButtonType.alpha}
  235. title={'Log'}
  236. width={rpxToPx(128)}
  237. height={rpxToPx(72)}
  238. bold={true}
  239. onClick={() => {
  240. tapLogBtn(index)
  241. }} />
  242. }
  243. {
  244. isError && <View style={{
  245. borderColor: MainColorType.error,
  246. borderWidth: rpxToPx(2),
  247. borderRadius: rpxToPx(76 / 4),
  248. borderStyle: 'solid'
  249. }}>
  250. <NewButton
  251. type={NewButtonType.gray}
  252. title='Correct'
  253. fontSize={rpxToPx(34)}
  254. width={rpxToPx(128)}
  255. height={rpxToPx(72)}
  256. onClick={() => {
  257. jumpPage(`/_health/pages/log_time?is_fast_with_sleep=1&index=${1}&single=0&initCheck=1`)
  258. }}
  259. />
  260. </View>
  261. }
  262. {
  263. !isError && item.action == 'POST_MOMENT' && item.timeline.real && <IconCellArrow color='#B2B2B2' width={rpxToPx(34)} />
  264. }
  265. <View className="seperate_line" style={{ left: count - 1 == index ? -rpxToPx(52) : rpxToPx(52) }} />
  266. </View>
  267. }
  268. return <View style={{ backgroundColor: '#fff' }}>
  269. {
  270. health.fast_with_sleep.status == 'OG2_MISALIGNED' && <View className="error_bg" >
  271. <View className="error_icon_bg">
  272. <Image src={require('@assets/_health/tip_error.png')} style={{ width: rpxToPx(26), height: rpxToPx(26) }} />
  273. </View>
  274. <Text className="h24" style={{ lineHeight: rpxToPx(36) + 'px' }}>Logged times are not in their proper order</Text>
  275. </View>
  276. }
  277. {
  278. props.step != 2 && props.step != 3 && timelineItem({
  279. title: 'Start Fast',
  280. mode: 'FAST',
  281. is_start: true,
  282. action: props.data.fast.timeline[0].action,
  283. moment: props.data.fast.timeline[0].moment,
  284. timeline: props.data.fast.timeline[0]
  285. }, 0, 4)
  286. }
  287. {
  288. props.step != 3 && timelineItem({
  289. title: 'Go to bed',
  290. mode: 'SLEEP',
  291. is_start: true,
  292. action: props.data.fast.timeline[0].action,
  293. moment: props.data.sleep.timeline[0].moment,
  294. timeline: props.data.sleep.timeline[0]
  295. }, 1, 4)
  296. }
  297. {
  298. props.step != 1 && timelineItem({
  299. title: 'Wake up',
  300. mode: 'SLEEP',
  301. is_start: false,
  302. moment: props.data.sleep.timeline[1].moment,
  303. timeline: props.data.sleep.timeline[1]
  304. }, 2, 4)
  305. }
  306. {
  307. props.step != 1 && props.step != 2 && timelineItem({
  308. title: 'End Fast',
  309. mode: 'FAST',
  310. is_start: false,
  311. moment: props.data.fast.timeline[1].moment,
  312. timeline: props.data.fast.timeline[1]
  313. }, 3, 4)
  314. }
  315. {
  316. props.data.status != 'WFS' && <View className="main_footer">
  317. <NewButton
  318. btnStyle={{
  319. position: 'absolute',
  320. top: rpxToPx(42),
  321. right: rpxToPx(40)
  322. }}
  323. type={NewButtonType.more}
  324. onClick={delConfirm}
  325. />
  326. </View>
  327. }
  328. </View>
  329. }