Schedule.tsx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. import { View, Text } from "@tarojs/components";
  2. import trackTimeService, { machine } from "@/store/trackTimeMachine"
  3. import { useEffect, useState } from "react";
  4. import Taro from "@tarojs/taro";
  5. import Box from "@/components/layout/Box";
  6. import './Schedule.scss'
  7. import { useTranslation } from "react-i18next";
  8. import TimelineFastSleep from "./TimelineFastSleep";
  9. import Switch from "@/components/input/Switch";
  10. import { useDispatch, useSelector } from "react-redux";
  11. import { TimeFormatter } from "@/utils/time_format";
  12. import Buttons from "@/components/basic/Buttons";
  13. import { ButtonType } from "@/utils/types";
  14. import { setStep } from "@/store/scenario";
  15. import Segment from "@/components/navigation/Segment";
  16. export default function Component(props: { type?: string, data?: any, delSuccess?: Function }) {
  17. const { t } = useTranslation()
  18. const permission = useSelector((state: any) => state.permission);
  19. const common = useSelector((state: any) => state.common);
  20. const time = useSelector((state: any) => state.time);
  21. const dispatch = useDispatch();
  22. function all() {
  23. if (props.type == 'latest') {
  24. Taro.navigateTo({
  25. url: '/pages/common/RecordsHistory?type=time&title=Time'
  26. })
  27. }
  28. }
  29. function showStage() {
  30. }
  31. function followWxPub() {
  32. const resource = common.resources.filter((item: any) => {
  33. return item.code == 'follow_wx_pub'
  34. })
  35. Taro.showModal({
  36. title: '提示',
  37. content: '关注公众号后可接收提醒\n点击确定,前往关注',
  38. showCancel: true,
  39. success(result) {
  40. if (result.confirm) {
  41. Taro.navigateTo({
  42. url: '/pages/common/H5?title=fast16cc 关注服务号&url=' + resource[0].url,
  43. })
  44. }
  45. },
  46. })
  47. }
  48. function detailHeader() {
  49. var btnStyle;
  50. if (props.data.scenario == 'SLEEP') {
  51. btnStyle = {
  52. fontSize: 14,
  53. lineHeight: 18,
  54. color: '#00FFFF'
  55. }
  56. }
  57. else if (props.data.scenario == 'FAST') {
  58. btnStyle = {
  59. fontSize: 14,
  60. lineHeight: 18,
  61. color: '#AAFF00'
  62. }
  63. }
  64. else if (props.data.scenario == 'FAST_SLEEP') {
  65. btnStyle = {
  66. fontSize: 14,
  67. lineHeight: 18,
  68. // background: 'linear-gradient(90deg, #AAFF00 0%, #00FFFF 100%)',
  69. // WebkitBackgroundClip: 'text',
  70. // backgroundClip: 'text',
  71. // color: 'transparent'
  72. }
  73. }
  74. return <View style={{
  75. height: 18,
  76. display: 'flex', flexDirection: 'row', width: '100%',
  77. justifyContent: 'space-between', alignItems: 'center',
  78. marginBottom:6,paddingRight:10,boxSizing:'border-box'
  79. }}>
  80. <Text style={{fontSize:18,lineHeight:18,fontWeight:500}}>{permission.wxPubFollow ? TimeFormatter.getDateAndWeek() : '日程提醒'}</Text>
  81. {
  82. !permission.wxPubFollow && <View >
  83. <Switch isOn={permission.wxPubFollow} onClick={() => followWxPub()} />
  84. </View>
  85. }
  86. {
  87. permission.wxPubFollow && props.data.status == 'WAIT_FOR_START' && <Buttons disabled={props.data.status != 'WAIT_FOR_START'}
  88. className={props.data.scenario == 'FAST_SLEEP' ? 'mixed' : ''}
  89. btnStyle={btnStyle} type={ButtonType.text} title="调整日程" onClick={() => {
  90. if (props.data.name == 'FAST_SLEEP') {
  91. dispatch(setStep('fast'))
  92. }
  93. else if (props.data.name == 'SLEEP') {
  94. dispatch(setStep('sleep'))
  95. }
  96. else {
  97. dispatch(setStep('fast'))
  98. }
  99. Taro.navigateTo({
  100. url: '/pages/clock/SetSchedule'
  101. })
  102. }} />
  103. }
  104. </View>
  105. }
  106. function detailCenter() {
  107. if (!permission.wxPubFollow) {
  108. return <View className="tip_bg2">
  109. <Text className="tip_text2">开启后,将显示今天的日程。</Text>
  110. </View>
  111. }
  112. var nextCheckTimestamp = 0;
  113. if (time.status != 'WAIT_FOR_START') {
  114. if (time.status == 'ONGOING') {
  115. nextCheckTimestamp = time.scenario == 'FAST' ?
  116. time.fast.target_end_time : time.sleep.target_end_time
  117. }
  118. else {
  119. switch (time.status) {
  120. case 'ONGOING1':
  121. nextCheckTimestamp = time.sleep.target_start_time
  122. break;
  123. case 'ONGOING2':
  124. nextCheckTimestamp = time.sleep.target_end_time
  125. break
  126. case 'ONGOING3':
  127. nextCheckTimestamp = time.fast.target_end_time
  128. break
  129. }
  130. }
  131. }
  132. var today = new Date();
  133. today.setHours(0)
  134. today.setMinutes(0)
  135. today.setSeconds(0)
  136. if (nextCheckTimestamp!=0 && today.getTime()>nextCheckTimestamp){
  137. return <View className="tip_bg2">
  138. <Text className="tip_text2">完成当前记录,恢复今天的日程。</Text>
  139. </View >
  140. }
  141. return <View style={{marginTop:10}}>
  142. <TimelineFastSleep data={props.data} />
  143. <View>
  144. <Text>show detail</Text>
  145. </View>
  146. </View>
  147. }
  148. function detailFooter() {
  149. }
  150. function detail() {
  151. return <View style={{ flexDirection: 'column', display: 'flex', alignItems: 'center', position: 'relative' }} onClick={all}>
  152. {
  153. detailHeader()
  154. }
  155. {
  156. detailCenter()
  157. }
  158. {
  159. props.data.scenario == 'FAST_SLEEP' && (props.data.status == 'WAIT_FOR_START' ? <Text onClick={showStage}>Duration goals by stage</Text> : <Text onClick={showStage}>Current stage</Text>)
  160. }
  161. </View >
  162. }
  163. return <Box>
  164. {
  165. detail()
  166. }
  167. </Box>
  168. }