Suggest.tsx 29 KB

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