Suggest.tsx 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. import { ColorType } from "@/context/themes/color";
  2. import { ChooseScenarioBtn } from "@/features/common/SpecBtns";
  3. import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
  4. import { View, Text, Picker, ScrollView } from "@tarojs/components";
  5. import { useDidShow, useRouter } from "@tarojs/taro";
  6. import { useEffect, useRef, useState } from "react";
  7. import './ChooseScenario.scss';
  8. import PickerViews from "@/components/input/PickerViews";
  9. import { useDispatch, useSelector } from "react-redux";
  10. import { rpxToPx } from "@/utils/tools";
  11. import { updateFast, updateSleep, updateStep } from "@/store/set_target";
  12. import { TimeFormatter } from "@/utils/time_format";
  13. import Footer from "@/components/layout/Footer";
  14. import { IconCheck } from "@/components/basic/Icons";
  15. import Rings2, { BgRing, RingCommon, TargetRing } from '@/features/trackTimeDuration/components/Rings';
  16. import { useTranslation } from "react-i18next";
  17. let ScrollViewRN
  18. if (process.env.TARO_ENV === 'rn') {
  19. ScrollViewRN = require('react-native').ScrollView
  20. }
  21. export default function Suggest() {
  22. let router: any = null
  23. var navigation: any = null
  24. if (process.env.TARO_ENV === 'rn') {
  25. var useNavigation = require("@react-navigation/native").useNavigation
  26. navigation = useNavigation()
  27. const useRoute = require("@react-navigation/native").useRoute
  28. router = useRoute()
  29. }
  30. else {
  31. router = useRouter()
  32. }
  33. const common = useSelector((state: any) => state.common);
  34. const target = useSelector((state: any) => state.target);
  35. const [pageStep] = useState(target.step);
  36. const dispatch = useDispatch();
  37. const [suggestIndex, setSuggestIndex] = useState(-1)
  38. const [suggestItems, setSuggestItem] = useState<any>([])
  39. const [scrollTop, setScrollTop] = useState(0)
  40. const [fastRecommendIndex, setFastRecommendIndex] = useState(-1)
  41. const [fastLastIndex, setFastLastIndex] = useState(-1)
  42. const { t } = useTranslation()
  43. const scrollViewRef = useRef(null);
  44. useEffect(() => {
  45. if (pageStep == 1) {
  46. var obj = target.fast.schedule.fast
  47. var array: any = []
  48. var currentIndex = -1;
  49. var recommendIndex = -1;
  50. var lastIndex = -1;
  51. for (var i = 0; i < obj.duration.options.length; i++) {
  52. if (obj.duration.options[i] == obj.duration.last_value) {
  53. lastIndex = i
  54. }
  55. if (obj.duration.options[i] == obj.duration.default_value) {
  56. recommendIndex = i
  57. }
  58. var fast = JSON.parse(JSON.stringify(target.fast))
  59. var startCount = fast.schedule.fast.end_time.split(':')[0] * 60 + fast.schedule.fast.end_time.split(':')[1] * 1 - obj.duration.options[i]
  60. if (startCount < 0) {
  61. startCount += 24 * 60
  62. }
  63. var start = TimeFormatter.padZero(Math.floor(startCount / 60)) + ':' + TimeFormatter.padZero(startCount % 60)
  64. array.push({
  65. hours: obj.duration.options[i] / 60,
  66. left: 24 - obj.duration.options[i] / 60,
  67. // minutes: obj.duration.minutes[i],
  68. // number: obj.duration.numbers[i],
  69. time: start
  70. })
  71. if (obj.duration.options[i] == obj.duration.init_value) {
  72. currentIndex = i
  73. }
  74. }
  75. // var duration = obj.end_time.split(':')[0] * 60 + obj.end_time.split(':')[1] * 1 - (obj.start_time.split(':')[0] * 60 + obj.start_time.split(':')[1] * 1)
  76. // if (duration <= 0) {
  77. // duration += 24 * 60
  78. // }
  79. // var durationHours = Math.floor(duration / 60)
  80. // var durationMinutes = duration % 60
  81. // var currentIndex = -1;
  82. // var array: any = []
  83. // for (var i = 12; i <= 23; i++) {
  84. // if (i != 23 || durationMinutes == 0) {
  85. // array.push({
  86. // hours: i,
  87. // minutes: durationMinutes
  88. // });
  89. // }
  90. // }
  91. // for (var i = 0; i < array.length; i++) {
  92. // if (array[i].hours == durationHours && array[i].minutes == durationMinutes) {
  93. // currentIndex = i
  94. // break
  95. // }
  96. // }
  97. setFastRecommendIndex(recommendIndex)
  98. setFastLastIndex(lastIndex)
  99. setSuggestItem(array)
  100. setSuggestIndex(currentIndex)
  101. setScrollTop(currentIndex * rpxToPx(244) + 50)
  102. if (process.env.TARO_ENV=='rn'){
  103. setTimeout(()=>{
  104. (scrollViewRef.current as any).scrollTo({x:0,y:currentIndex * rpxToPx(244)+20,animated:true})
  105. },500)
  106. }
  107. }
  108. else if (pageStep == 3) {
  109. var obj = target.sleep.schedule.sleep
  110. var sleep_cycle = obj.cycle
  111. var sleep_latency = obj.latency.init_value
  112. var array: any = []
  113. var index: number = 0;
  114. for (var i = 0; i < sleep_cycle.num.options.length; i++) {
  115. var count = sleep_cycle.num.options[i] * sleep_cycle.duration.init_value + sleep_latency
  116. //sleep.schedule.sleep.cycle.num.init_value = sleep.schedule.sleep.cycle.num.options[suggestIndex]
  117. if (sleep_cycle.num.options[i] == sleep_cycle.num.init_value) {
  118. index = i
  119. }
  120. var sleep = JSON.parse(JSON.stringify(target.sleep))
  121. var startCount = sleep.schedule.sleep.end_time.split(':')[0] * 60 + sleep.schedule.sleep.end_time.split(':')[1] * 1 - count
  122. if (startCount < 0) {
  123. startCount += 24 * 60
  124. }
  125. var start = TimeFormatter.padZero(Math.floor(startCount / 60)) + ':' + TimeFormatter.padZero(startCount % 60)
  126. array.push({
  127. hours: Math.floor(count / 60),
  128. minutes: count % 60,
  129. number: sleep_cycle.num.options[i],
  130. time: start
  131. })
  132. }
  133. setSuggestItem(array)
  134. setSuggestIndex(index)
  135. }
  136. }, [])
  137. useDidShow(() => {
  138. dispatch(updateStep({ step: pageStep }))
  139. })
  140. function next() {
  141. if (pageStep == 1) {
  142. var item = suggestItems[suggestIndex]
  143. var fast = JSON.parse(JSON.stringify(target.fast))
  144. // var startCount = fast.schedule.fast.end_time.split(':')[0] * 60 + fast.schedule.fast.end_time.split(':')[1] * 1 - (item.hours * 60 + item.minutes)
  145. // if (startCount < 0) {
  146. // startCount += 24 * 60
  147. // }
  148. // var start = TimeFormatter.padZero(Math.floor(startCount / 60)) + ':' + TimeFormatter.padZero(startCount % 60)
  149. fast.schedule.fast.start_time = item.time
  150. fast.schedule.fast.duration.init_value = fast.schedule.fast.duration.options[suggestIndex]
  151. dispatch(updateFast({ fast: fast }))
  152. }
  153. else if (pageStep == 3) {
  154. var item = suggestItems[suggestIndex]
  155. var sleep = JSON.parse(JSON.stringify(target.sleep))
  156. var startCount = sleep.schedule.sleep.end_time.split(':')[0] * 60 + sleep.schedule.sleep.end_time.split(':')[1] * 1 - (item.hours * 60 + item.minutes)
  157. if (startCount < 0) {
  158. startCount += 24 * 60
  159. }
  160. var start = TimeFormatter.padZero(Math.floor(startCount / 60)) + ':' + TimeFormatter.padZero(startCount % 60)
  161. sleep.schedule.sleep.start_time = start
  162. sleep.schedule.sleep.cycle.num.init_value = sleep.schedule.sleep.cycle.num.options[suggestIndex]
  163. dispatch(updateSleep({ sleep: sleep }))
  164. }
  165. var step: number = target.step + 1
  166. dispatch(updateStep({ step: step }))
  167. var url = '/pages/clock/Suggest?trigger_event=' + router.params.trigger_event
  168. var pageName = 'Suggest'
  169. if (!target.isMixed) {
  170. if (step == 2) {
  171. url = '/pages/clock/SetGoal?trigger_event=' + router.params.trigger_event
  172. pageName = 'SetGoal'
  173. }
  174. }
  175. else {
  176. if (step == 4) {
  177. url = '/pages/clock/SetGoal?trigger_event=' + router.params.trigger_event
  178. pageName = 'SetGoal'
  179. }
  180. }
  181. jumpPage(url, pageName, navigation, {
  182. trigger_event: router.params.trigger_event
  183. })
  184. }
  185. function myself() {
  186. jumpPage(`/pages/clock/SetGoal?isSelf=1&trigger_event=` + router.params.trigger_event, 'SetGoal', navigation, {
  187. isSelf: 1,
  188. trigger_event: router.params.trigger_event
  189. })
  190. }
  191. function suggestTitle() {
  192. switch (pageStep) {
  193. case 0:
  194. return t('feature.suggest.step_0_title')
  195. case 1:
  196. return t('feature.suggest.step_1_title')
  197. case 2:
  198. return t('feature.suggest.step_2_title')
  199. case 3:
  200. return t('feature.suggest.step_3_title')
  201. default:
  202. return ''
  203. }
  204. }
  205. function suggestDesc() {
  206. switch (pageStep) {
  207. case 0:
  208. return t('feature.suggest.end_fast_picker_header')
  209. case 1:
  210. return t('feature.suggest.fast_suggest_header', { time: target.fast.schedule.fast.end_time })
  211. case 2:
  212. return t('feature.suggest.end_sleep_picker_header')
  213. case 3:
  214. return t('feature.suggest.sleep_suggest_header', { time: target.sleep.schedule.sleep.end_time })
  215. default:
  216. return ''
  217. }
  218. }
  219. function durationDatas() {
  220. var min: number = 0
  221. var max: number = 23
  222. var step: number = 5
  223. var minutes: string[] = []
  224. for (let i = 0; i < 60; i += step) {
  225. minutes.push(TimeFormatter.padZero(i))
  226. }
  227. var hours: string[] = []
  228. for (let i = min; i <= max; i++) {
  229. hours.push(TimeFormatter.padZero(i))
  230. }
  231. return [hours, minutes]
  232. }
  233. function durationValues() {
  234. var eatTime = target.fast.schedule.fast.end_time
  235. if (pageStep == 2) {
  236. eatTime = target.sleep.schedule.sleep.end_time
  237. }
  238. var eatHour = eatTime.split(':')[0]
  239. var eatMin = eatTime.split(':')[1]
  240. var list = durationDatas()
  241. var hourIndex = 0
  242. var minIndex = 0
  243. for (let i = 0; i < list[0].length; i++) {
  244. if (list[0][i] == eatHour) {
  245. hourIndex = i
  246. break
  247. }
  248. }
  249. for (let i = 0; i < list[1].length; i++) {
  250. if (list[1][i] == eatMin) {
  251. minIndex = i
  252. break
  253. }
  254. }
  255. return [hourIndex, minIndex]
  256. }
  257. function sleepLatency() {
  258. var obj = target.sleep.schedule.sleep.latency
  259. var min: number = obj.min
  260. var max: number = obj.max
  261. var step: number = obj.step
  262. var minutes: string[] = []
  263. for (let i = min; i <= max; i += step) {
  264. minutes.push(i + ' '+t('feature.suggest.mins'))
  265. }
  266. return [minutes]
  267. }
  268. function sleepLatencyValue() {
  269. var obj = target.sleep.schedule.sleep.latency
  270. var value: number = obj.init_value
  271. var min: number = obj.min
  272. var step: number = obj.step
  273. var index = (value - min) / step
  274. return [index]
  275. }
  276. function timePickerChanged(e: any) {
  277. var obj = target.fast.schedule.fast
  278. if (pageStep == 2) {
  279. obj = target.sleep.schedule.sleep
  280. }
  281. var duration = obj.end_time.split(':')[0] * 60 + obj.end_time.split(':')[1] * 1 - (obj.start_time.split(':')[0] * 60 + obj.start_time.split(':')[1] * 1)
  282. if (duration <= 0) {
  283. duration += 24 * 60
  284. }
  285. var endCount = duration - (e[0] * 60 + e[1] * 5)
  286. if (endCount < 0) {
  287. endCount += 24 * 60
  288. }
  289. var time = TimeFormatter.padZero(e[0]) + ':' + TimeFormatter.padZero(e[1] * 5)
  290. var start = TimeFormatter.padZero(Math.floor(endCount / 60)) + ':' + TimeFormatter.padZero(endCount % 60)
  291. if (pageStep == 0) {
  292. var fast = JSON.parse(JSON.stringify(target.fast))
  293. fast.schedule.fast.end_time = time
  294. fast.schedule.fast.start_time = start
  295. dispatch(updateFast({ fast: fast }))
  296. }
  297. else {
  298. var sleep = JSON.parse(JSON.stringify(target.sleep))
  299. sleep.schedule.sleep.end_time = time
  300. sleep.schedule.sleep.start_time = start
  301. dispatch(updateSleep({ sleep: sleep }))
  302. }
  303. }
  304. function timePicker() {
  305. return <View>
  306. <View style={{
  307. marginBottom: rpxToPx(40), marginLeft: rpxToPx(46),
  308. marginRight: rpxToPx(46), borderRadius: 10,
  309. overflow: 'hidden', backgroundColor: '#1c1c1c', paddingTop: 10, paddingBottom: 10
  310. }}>
  311. <PickerViews ref={null}
  312. onChange={timePickerChanged}
  313. items={durationDatas()}
  314. value={durationValues()} height={200}
  315. title=''
  316. themeColor={target.isMixed ? global.fastColor ? global.fastColor : ColorType.fast : global.sleepColor ? global.sleepColor : ColorType.sleep}
  317. showBtns={false}
  318. hideTitle={true}
  319. onCancel={() => { }} />
  320. </View>
  321. {
  322. pageStep == 0 && <Text className="suggest_footer_note">{t('feature.suggest.end_fast_picker_footer')}</Text>
  323. }
  324. {
  325. pageStep == 1 && <Text className="suggest_footer_note">If you plan to skip breakfast, pick a time for your first meal of the day.</Text>
  326. }
  327. </View>
  328. }
  329. function fallSleepChanged(e: any) {
  330. var value = target.sleep.schedule.sleep.latency
  331. var time = e[0] * value.step + value.min
  332. var sleep = JSON.parse(JSON.stringify(target.sleep))
  333. sleep.schedule.sleep.latency.init_value = time
  334. dispatch(updateSleep({ sleep: sleep }))
  335. }
  336. function fallSleepPicker() {
  337. return <View>
  338. <View className="target_desc">{t('feature.suggest.fall_sleep_picker_header')}</View>
  339. <View style={{
  340. marginLeft: rpxToPx(46), marginRight: rpxToPx(46),
  341. borderRadius: 10,
  342. overflow: 'hidden', backgroundColor: '#1c1c1c', paddingTop: 10, paddingBottom: 10
  343. }}>
  344. <PickerViews ref={null}
  345. onChange={fallSleepChanged}
  346. items={sleepLatency()}
  347. value={sleepLatencyValue()} height={200}
  348. title=''
  349. themeColor={target.isMixed ? global.fastColor ? global.fastColor : ColorType.fast : global.sleepColor ? global.sleepColor : ColorType.sleep}
  350. showBtns={false}
  351. hideTitle={true}
  352. onCancel={() => { }} />
  353. </View>
  354. <Text className="suggest_footer_note">{t('feature.suggest.fall_sleep_picker_footer')}</Text>
  355. </View>
  356. }
  357. // const common: RingCommon = {
  358. // useCase: 'ChooseScenario',
  359. // radius: 33,
  360. // lineWidth: 8,
  361. // isFast: true,
  362. // status: 'WAIT_FOR_START'
  363. // }
  364. const bgRing: BgRing = {
  365. color: '#262626'
  366. }
  367. // const targetRing: TargetRing = {
  368. // color: ColorType.fast,
  369. // startArc: timeToArc(ring.schedule.fast.start_time),
  370. // durationArc: durationToArc(ring.schedule.fast.start_time, ring.schedule.fast.end_time)
  371. // }
  372. function ringCommon() {
  373. return {
  374. useCase: 'ChooseScenario',
  375. radius: 30,
  376. lineWidth: 12,
  377. isFast: true,
  378. status: 'WAIT_FOR_START'
  379. }
  380. }
  381. function targetRing(start, end, isFast, isHighLight) {
  382. var color: any = isFast ? ColorType.fast + '66' : ColorType.sleep + '66'
  383. if (!isHighLight) {
  384. color = isFast ? ColorType.fast + '0D' : ColorType.sleep + '0D'
  385. }
  386. return {
  387. color: color,
  388. startArc: timeToArc(start),
  389. durationArc: durationToArc(start, end)
  390. }
  391. }
  392. function point(isFast: boolean, isShow: boolean) {
  393. if (!isShow) return null;
  394. var now = new Date()
  395. var t = suggestItems[suggestIndex].time
  396. now.setHours(parseInt(t.split(':')[0]))
  397. now.setMinutes(parseInt(t.split(':')[1]))
  398. return [{
  399. color: isFast ? ColorType.fast : ColorType.sleep,
  400. borderColor: 'transparent',
  401. timestamp: now.getTime()
  402. }]
  403. }
  404. function timeToArc(time: string) {
  405. var count: number = parseInt(time.split(':')[1]) + parseInt(time.split(':')[0]) * 60
  406. // count = count>720?count-720:count
  407. return (count as any) / 1440 * 2 * Math.PI - Math.PI / 2
  408. }
  409. function durationToArc(startTime: string, endTime: string) {
  410. var start: number = parseInt(startTime.split(':')[1]) + parseInt(startTime.split(':')[0]) * 60
  411. var end: number = parseInt(endTime.split(':')[1]) + parseInt(endTime.split(':')[0]) * 60
  412. if (end <= start) {
  413. end += 1440
  414. }
  415. return (end - start) / 1440 * 2 * Math.PI
  416. }
  417. function scrollContent() {
  418. return <View style={{ flexDirection: 'column', display: 'flex' }}>
  419. {
  420. suggestItems.map((item: any, index: number) => {
  421. return <View key={index} className={suggestIndex == index ? 'item1 item_sel1' : 'item1'} onClick={() => setSuggestIndex(index)}>
  422. <View style={{ flexShrink: 0, display: 'flex', width: 74, height: 74, marginRight: rpxToPx(24) }}>
  423. <Rings2 common={ringCommon()}
  424. bgRing={bgRing}
  425. targetRing={targetRing(item.time, target.fast.schedule.fast.end_time, true, suggestIndex == index)}
  426. dotList={point(true, index == suggestIndex)}
  427. canvasId={new Date().getTime() + index * 5} />
  428. </View>
  429. <View style={{ flex: 1 }}>
  430. <View className="suggest_item_title">{item.hours}{t('feature.suggest.hour')}</View>
  431. <View className="suggest_item_desc">{index == suggestIndex ?
  432. t('feature.suggest.fast_desc', { start_time: item.hours, end_time: item.left }) :
  433. t('feature.suggest.intermittent_fast', { data: `${item.hours}/${item.left}` })
  434. }</View>
  435. {
  436. index == suggestIndex &&
  437. <View className="suggest_choose">
  438. <View className="suggest_choose_text" style={{ color: ColorType.fast }}>{t('feature.suggest.start_fast_time', { time: item.time })}</View>
  439. </View>
  440. }
  441. </View>
  442. {
  443. index == suggestIndex && <View className="choose_item_check_bg">
  444. <IconCheck color={ColorType.fast} width={24} height={24} />
  445. </View>
  446. }
  447. <View className='suggest_fast_tag_bg'>
  448. {
  449. index == fastRecommendIndex &&
  450. <View className='suggest_fast_tag'>{t('feature.suggest.popular')}</View>
  451. }
  452. {
  453. index == fastLastIndex &&
  454. <View className='suggest_fast_tag'>{t('feature.suggest.recent')}</View>
  455. }
  456. </View>
  457. </View>
  458. // return <View onClick={() => {
  459. // setSuggestIndex(index)
  460. // }} key={index} className={index == suggestIndex ? 'item_choose_selected' : 'item_choose'}>
  461. // <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
  462. // <View className="suggest_item_title">{item.hours} hours</View>
  463. // <View style={{ flex: 1 }} />
  464. // {
  465. // index == fastRecommendIndex &&
  466. // <View style={{ color: '#fff' }}>Popular</View>
  467. // }
  468. // {
  469. // index == fastLastIndex &&
  470. // <View style={{ color: '#fff', marginLeft: 5 }}>Recent</View>
  471. // }
  472. // </View>
  473. // <View className="suggest_item_desc">{index == suggestIndex ? `${item.hours} hours fasting / ${item.left} hours eating` : `${item.hours}/${item.left} Intermittent Fasting`}</View>
  474. // {
  475. // index == suggestIndex &&
  476. // <View className="suggest_choose">
  477. // <View style={{ color: ColorType.fast }}>Start fasting at {item.time}</View>
  478. // <IconCheck color={ColorType.fast} width={38} height={26} />
  479. // </View>
  480. // }
  481. // </View>
  482. })
  483. }
  484. </View>
  485. }
  486. function suggestList() {
  487. if (pageStep == 1 && process.env.TARO_ENV === 'weapp') {
  488. return <ScrollView scrollY style={{ height: 450 }} scrollTop={scrollTop}>
  489. {
  490. scrollContent()
  491. }
  492. </ScrollView>
  493. }
  494. if (pageStep == 1 && process.env.TARO_ENV === 'rn') {
  495. return <ScrollViewRN style={{ height: rpxToPx(868) }} ref={scrollViewRef}>
  496. {
  497. scrollContent()
  498. }
  499. </ScrollViewRN>
  500. }
  501. return <View style={{ flex: 1, overflow: 'scroll' }}>
  502. {
  503. suggestItems.map((item: any, index: number) => {
  504. return <View key={index} className={suggestIndex == index ? 'item1 item_sel1' : 'item1'} style={{ borderColor: suggestIndex == index ? ColorType.sleep : '#00000000' }} onClick={() => setSuggestIndex(index)}>
  505. <View style={{ flexShrink: 0, display: 'flex', width: 74, height: 74, marginRight: rpxToPx(24) }}>
  506. <Rings2 common={ringCommon()}
  507. bgRing={bgRing}
  508. dotList={point(false, index == suggestIndex)}
  509. targetRing={targetRing(item.time, target.sleep.schedule.sleep.end_time, false, suggestIndex == index)}
  510. canvasId={new Date().getTime() + index * 5} />
  511. </View>
  512. <View>
  513. <View className="suggest_item_title">{item.hours}{t('feature.suggest.hours2')}{item.minutes>0&&item.minutes+t('feature.suggest.minute')}</View>
  514. <View className="suggest_item_desc">{t('feature.suggest.cycles',{times:item.number})}</View>
  515. {
  516. index == suggestIndex && <View className="suggest_choose">
  517. <View className="suggest_choose_text" style={{ color: ColorType.sleep }}>{t('feature.suggest.go_to_bed_at', { time: item.time })}</View>
  518. </View>
  519. }
  520. </View>
  521. {
  522. index == 0 && <View className='suggest_tag' style={{ backgroundColor: ColorType.sleep }}>{t('feature.suggest.popular')}</View>
  523. }
  524. {
  525. index == 1 && <View className='suggest_tag' style={{ backgroundColor: ColorType.sleep }}>{t('feature.suggest.restorative')}</View>
  526. }
  527. {
  528. index == suggestIndex && <View className="choose_item_check_bg">
  529. <IconCheck color={ColorType.sleep} width={24} height={24} />
  530. </View>
  531. }
  532. </View>
  533. })
  534. }
  535. </View>
  536. }
  537. function content() {
  538. return <View style={{ flex: 1, display: 'flex', flexDirection: 'column' }}>
  539. {
  540. (pageStep == 0 || pageStep == 2) && timePicker()
  541. }
  542. {
  543. (pageStep == 1 || pageStep == 3) && suggestList()
  544. }
  545. {
  546. pageStep==3 && <Text className="suggest_footer_note">{t('feature.suggest.sleep_suggest_footer')}</Text>
  547. }
  548. {
  549. pageStep == 2 && fallSleepPicker()
  550. }
  551. {
  552. pageStep == 2 && <View style={{ height: 200 }} />
  553. }
  554. </View>
  555. }
  556. function btnText(){
  557. // if (pageStep == 3){
  558. // return t('feature.suggest.done')
  559. // }
  560. // if (pageStep == 1 && !target.isMixed){
  561. // return t('feature.suggest.done')
  562. // }
  563. return t('feature.suggest.btn')
  564. }
  565. return <View style={{ display: 'flex', flexDirection: 'column', flex: 1 }}>
  566. <Text className="target_title">{suggestTitle()}</Text>
  567. <Text className="target_desc">{suggestDesc()}</Text>
  568. {
  569. content()
  570. }
  571. <Footer>
  572. <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center' }}>
  573. <ChooseScenarioBtn
  574. onClick={next}
  575. title={btnText()}
  576. background={pageStep < 2 ? ColorType.fast : ColorType.sleep}
  577. />
  578. <Text className="suggest_footer_btn" onClick={myself}>{t('feature.suggest.set_myself')}</Text>
  579. </View>
  580. </Footer>
  581. {
  582. process.env.TARO_ENV == 'rn' && <View style={{ marginBottom: 40 }} />
  583. }
  584. </View>
  585. }