MainConsole.tsx 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  1. import { WindowStatusType, WindowType } from "@/utils/types";
  2. import { View, Text, Image } from "@tarojs/components";
  3. import dayjs from "dayjs";
  4. import { useEffect, useRef, useState } from "react";
  5. import { useDispatch, useSelector } from "react-redux";
  6. import './MainConsole.scss'
  7. import { jumpPage } from "../trackTimeDuration/hooks/Common";
  8. import Modal from "@/components/layout/Modal.weapp";
  9. import { MainColorType } from "@/context/themes/color";
  10. import ConsolePicker from "../trackTimeDuration/components/ConsolePicker";
  11. import { clockTimes, makeDone, updateEventDuration, updateSchedule, updateTarget } from "@/services/health";
  12. import TimePicker from "../common/TimePicker";
  13. import showActionSheet from "@/components/basic/ActionSheet";
  14. import { rpxToPx } from "@/utils/tools";
  15. import { setMode, setShowActionTip } from "@/store/health";
  16. import { getCountownTime, getDuration, getScenario, getThemeColor, getWindowStatus } from "./hooks/health_hooks";
  17. import { IconCellArrow, IconMore } from "@/components/basic/Icons";
  18. import DurationPicker from "@/_health/components/duration_picker";
  19. import Taro from "@tarojs/taro";
  20. import { systemLocation } from "@/services/common";
  21. import { TimeFormatter } from "@/utils/time_format";
  22. import { clearLocation } from "@/services/user";
  23. import OnBoard from "@/_health/components/onboard";
  24. let useNavigation;
  25. let min = 0
  26. let max = 0
  27. let defaultTimestamp = 0
  28. if (process.env.TARO_ENV == 'rn') {
  29. useNavigation = require("@react-navigation/native").useNavigation
  30. }
  31. export default function MainConsole(props: { type: WindowType }) {
  32. const health = useSelector((state: any) => state.health);
  33. const user = useSelector((state: any) => state.user);
  34. const [showPicker, setShowPicker] = useState(false)
  35. const [showTimePicker, setShowTimePicker] = useState(false)
  36. const [durationPicker, setDurationPicker] = useState(false)
  37. const [operateType, setOperateType] = useState('')
  38. const [btnDisable, setBtnDisable] = useState(false)
  39. const [selItem, setSelItem] = useState<any>(null)
  40. const limitPickerRef = useRef(null)
  41. const dispatch = useDispatch()
  42. let navigation, showActionSheetWithOptions;
  43. if (useNavigation) {
  44. navigation = useNavigation()
  45. }
  46. useEffect(() => {
  47. }, [props.type])
  48. function edit(item) {
  49. if (item.scenario != 'FAST' && item.scenario != 'SLEEP') {
  50. return
  51. }
  52. if (item.action == 'NA' || item.action == 'POST_MOMENT' || 'SLEEP_WAKE_UP' == item.action) {
  53. return;
  54. }
  55. if (!user.isLogin) {
  56. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  57. return
  58. }
  59. console.log(item)
  60. setSelItem(item)
  61. setShowPicker(true)
  62. }
  63. function record(item) {
  64. if (!user.isLogin) {
  65. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  66. return
  67. }
  68. setSelItem(item)
  69. switch (item.action) {
  70. case 'START':
  71. {
  72. defaultTimestamp = new Date().getTime()
  73. min = defaultTimestamp - 1 * 24 * 3600 * 1000
  74. max = defaultTimestamp
  75. setOperateType('startFast')
  76. setShowTimePicker(true)
  77. }
  78. return;
  79. case 'END':
  80. {
  81. defaultTimestamp = new Date().getTime()
  82. // defaultTimestamp = e ? new Date().getTime() : logEventTimestamp
  83. min = defaultTimestamp - 1 * 24 * 3600 * 1000
  84. max = defaultTimestamp
  85. setOperateType('endFast')
  86. setShowTimePicker(true)
  87. }
  88. return;
  89. case 'MARK_DONE':
  90. {
  91. setBtnDisable(true)
  92. clockTimes({
  93. check_items: [{
  94. schedule_id: item.schedule_id,
  95. date: dayjs().format('YYYYMMDD'),
  96. timestamp: new Date().getTime()
  97. }]
  98. }).then(res => {
  99. // dispatch(setShowActionTip({
  100. // isShow: true,
  101. // isCompleted: (selItem.event == 'FAST_END' || selItem.event == 'SLEEP_WAKE_UP')
  102. // }))
  103. // setBtnDisable(false)
  104. // setShowTimePicker(false)
  105. global.refreshWindow()
  106. global.refreshHistory()
  107. }).catch(e => {
  108. })
  109. }
  110. return;
  111. }
  112. jumpPage(`/_health/pages/add_moment?moment=${JSON.stringify(item)}&title=${item.title}&schedule_id=${item.schedule_id}&event_id=${item.event_id}`)
  113. }
  114. function operateTitle(item) {
  115. switch (item.action) {
  116. case 'START':
  117. case 'END':
  118. return '打卡'
  119. case 'MARK_DONE':
  120. return 'Action'
  121. }
  122. return '记录'
  123. }
  124. function itemTitle(item: any) {
  125. // if (health.mode == 'DAY' || health.mode == 'NIGHT') {
  126. // return item.title
  127. // }
  128. if (item.real) {
  129. return dayjs(item.real.timestamp).format('HH:mm')
  130. }
  131. if (!item.target || !item.target.timestamp) {
  132. return item.time_label
  133. }
  134. return dayjs(item.target.timestamp).format('HH:mm')
  135. }
  136. function itemValue(item: any) {
  137. let themeColor: any = getThemeColor(health.mode)
  138. const scenario = getScenario(health.windows, health.mode)
  139. if (item.action == 'END' && !scenario.real) {
  140. themeColor = '#B2B2B2'
  141. }
  142. if (health.mode == 'DAY' || health.mode == 'NIGHT') {
  143. return null
  144. }
  145. if (item.action && item.action != 'NA') {
  146. if (health.mode == 'FAST' || health.mode == 'SLEEP') {
  147. if (item.action == 'POST_MOMENT') {
  148. return <IconCellArrow color='#B2B2B2' width={rpxToPx(34)} />
  149. }
  150. }
  151. else if (health.mode == 'ACTIVE' && item.action == 'POST_MOMENT') {
  152. return <View className="timeline_operate" style={{ color: themeColor, backgroundColor: '#fff', borderColor: themeColor, borderWidth: 1, borderStyle: 'solid' }} onClick={() => record(item)}>{operateTitle(item)}</View>
  153. }
  154. return <View className="timeline_operate" style={{ color: themeColor, backgroundColor: themeColor + '1A' }} onClick={() => record(item)}>{operateTitle(item)}</View>
  155. }
  156. return <View />
  157. }
  158. function tapTimeline(item, inex) {
  159. if (health.mode == 'DAY' || health.mode == 'NIGHT') {
  160. return;
  161. }
  162. if (!user.isLogin) {
  163. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  164. return
  165. }
  166. if (!item.event_id) {
  167. return
  168. }
  169. jumpPage(`/_health/pages/timeline_detail?event_id=${item.event_id}&schedule_id=${item.schedule_id}`)
  170. }
  171. function timelineItem(item: any, index: number, count: number) {
  172. return <View key={index} className="timeline_item" onClick={() => tapTimeline(item, index)}>
  173. <View className="timeline_left">
  174. <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', height: rpxToPx(28) }}>
  175. {
  176. !item.reminder && <Image src={require('@assets/images/notification_off.png')} className='notification_icon' />
  177. }
  178. <Text className="timeline_title">{itemTitle(item)}</Text>
  179. </View>
  180. <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', marginTop: rpxToPx(5) }}>
  181. <Text className="timeline_time" onClick={() => edit(item)}>{item.title}</Text>
  182. </View>
  183. {
  184. (item.moment && item.moment.description) ? <Text className="timeline_desc">{item.moment.description}</Text> : <View className="timeline_thirdspace" />
  185. }
  186. </View>
  187. <View style={{ flex: 1 }} />
  188. {
  189. item.moment && item.moment.media && item.moment.media.length > 0 && <Image
  190. src={item.moment.media[0].url}
  191. mode="aspectFill"
  192. className="console_item_img" />
  193. }
  194. {
  195. itemValue(item)
  196. }
  197. {/* {
  198. item.action && item.action != 'NA' &&
  199. } */}
  200. <View className="border_footer_line" style={{ left: count - 1 == index ? -rpxToPx(64) : rpxToPx(64) }} />
  201. </View>
  202. }
  203. function timeContent() {
  204. return <Modal
  205. testInfo={null}
  206. dismiss={() => {
  207. setShowPicker(false)
  208. }}
  209. confirm={() => { }}>
  210. {
  211. pickerContent()
  212. }
  213. </Modal>
  214. }
  215. function pickerContent() {
  216. const timestamp = selItem.target.timestamp
  217. const strTime = dayjs(timestamp).format('HH:mm')
  218. var title, color;
  219. switch (selItem.scenario) {
  220. case 'FAST':
  221. title = selItem.event == 'FAST_END' ? '结束断食' : '开始断食'
  222. color = MainColorType.fast
  223. break;
  224. case 'SLEEP':
  225. title = selItem.event == 'SLEEP_WAKE_UP' ? '结束睡眠' : '开始睡眠'
  226. color = MainColorType.sleep
  227. }
  228. return <TimePicker time={strTime}
  229. color={color}
  230. title={title}
  231. confirm={(e) => {
  232. confirmPickerTime(e)
  233. }}
  234. cancel={() => {
  235. setShowPicker(false)
  236. }} />
  237. }
  238. function confirmPickerTime(strTime) {
  239. if (selItem.event == 'FAST_END') {
  240. const obj = health.windows.fast_eat.fast.timeline[0]
  241. if (obj.action == 'POST_MOMENT' || obj.action == 'NA') {
  242. const format = dayjs(obj.target.timestamp).format(`YYYY-MM-DDT${strTime}:ss`)
  243. var t = new Date(format).getTime()
  244. if (t <= obj.target.timestamp) {
  245. t += 24 * 3600 * 1000
  246. }
  247. updateTarget(t, obj.event_id).then(res => {
  248. global.refreshWindow()
  249. global.refreshHistory()
  250. setShowPicker(false)
  251. })
  252. return;
  253. }
  254. }
  255. else if (selItem.event == 'SLEEP_WAKE_UP') {
  256. const obj = health.windows.sleep_active.sleep.timeline[0]
  257. if (obj.action == 'POST_MOMENT' || obj.action == 'NA') {
  258. const format = dayjs(obj.target.timestamp).format(`YYYY-MM-DDT${strTime}:ss`)
  259. var t = new Date(format).getTime()
  260. if (t <= obj.target.timestamp) {
  261. t += 24 * 3600 * 1000
  262. }
  263. updateTarget(t, obj.event_id).then(res => {
  264. global.refreshWindow()
  265. global.refreshHistory()
  266. setShowPicker(false)
  267. })
  268. return;
  269. }
  270. }
  271. updateSchedule({
  272. time: strTime,
  273. event: selItem.event,
  274. title: selItem.title,
  275. is_all_day: false
  276. }, selItem.schedule_id).then(res => {
  277. global.refreshWindow()
  278. global.refreshHistory()
  279. setShowPicker(false)
  280. })
  281. }
  282. function modalContent() {
  283. global.set_time = new Date().getTime()
  284. return <Modal
  285. testInfo={null}
  286. dismiss={() => {
  287. setShowTimePicker(false)
  288. }}
  289. confirm={() => { }}>
  290. {
  291. timePickerContent()
  292. }
  293. </Modal>
  294. }
  295. function timePickerContent() {
  296. var title, color;
  297. switch (selItem.scenario) {
  298. case 'FAST':
  299. title = selItem.event == 'FAST_END' ? '结束断食' : '开始断食'
  300. color = MainColorType.fast
  301. break;
  302. case 'SLEEP':
  303. title = selItem.event == 'SLEEP_WAKE_UP' ? '结束睡眠' : '开始睡眠'
  304. color = MainColorType.sleep
  305. break
  306. }
  307. var endTimestamp = 0
  308. if (selItem.envent == 'FAST_END') {
  309. endTimestamp = new Date().getTime()//fastData.target.end_time
  310. }
  311. var duration = 24 * 3600 * 1000//fastData.target.duration
  312. global.set_time = new Date().getTime()
  313. return <View className="modal_content">
  314. <ConsolePicker ref={limitPickerRef}
  315. themeColor={color}
  316. title={title}
  317. onCancel={() => {
  318. setShowTimePicker(false)
  319. }}
  320. min={min}
  321. max={max}
  322. current={defaultTimestamp}
  323. duration={duration}
  324. endTimestamp={endTimestamp}
  325. isFast={true}
  326. isEnd={operateType == 'endFast'}
  327. isTimeout={false}
  328. isLoading={btnDisable}
  329. onChange={(e) => {
  330. pickerConfirm(e, null)
  331. global.pauseIndexTimer = false
  332. }}
  333. />
  334. </View>
  335. }
  336. function pickerConfirm(t1: number, event: any) {
  337. if (btnDisable) {
  338. return
  339. }
  340. global.scenario = 'FAST'
  341. setBtnDisable(true)
  342. clockTimes({
  343. check_items: [{
  344. schedule_id: selItem.schedule_id,
  345. date: dayjs(t1).format('YYYYMMDD'),
  346. timestamp: t1,
  347. extra: {
  348. set_time: global.set_time ? global.set_time : new Date().getTime(),
  349. confirm_time: new Date().getTime()
  350. }
  351. }]
  352. }).then(res => {
  353. dispatch(setShowActionTip({
  354. isShow: true,
  355. isCompleted: (selItem.event == 'FAST_END' || selItem.event == 'SLEEP_WAKE_UP')
  356. }))
  357. setBtnDisable(false)
  358. setShowTimePicker(false)
  359. global.refreshWindow()
  360. global.refreshHistory()
  361. }).catch(e => {
  362. setBtnDisable(false)
  363. })
  364. }
  365. function more() {
  366. var list: any = []
  367. switch (health.mode) {
  368. case 'DAY':
  369. case 'NIGHT':
  370. list = ['设置提醒', '设置位置']
  371. break;
  372. case 'FAST':
  373. case 'SLEEP':
  374. {
  375. const obj = getScenario(health.windows, health.mode)
  376. if (obj.window_id) {
  377. list.push('编辑本次时长')
  378. if (obj.timeline && obj.timeline[0].moment) {
  379. list.push('删除本次记录')
  380. }
  381. }
  382. list.push('编辑日程列表')
  383. }
  384. break;
  385. case 'EAT':
  386. {
  387. list = [
  388. 'Add Snack',
  389. '编辑日程列表',
  390. ]
  391. if (getScenario(health.windows, health.mode).window_id) {
  392. list.push('Make done')
  393. }
  394. }
  395. break;
  396. case 'ACTIVE':
  397. {
  398. list = [
  399. '记录一次活动',
  400. '编辑日程列表',
  401. ]
  402. if (getScenario(health.windows, health.mode).window_id) {
  403. list.push('Make done')
  404. }
  405. }
  406. break;
  407. }
  408. showActionSheet({
  409. showActionSheetWithOptions: showActionSheetWithOptions,
  410. title: 'Oprate Title',
  411. itemList: list,
  412. success: (res) => {
  413. tapActionSheet(res)
  414. }
  415. });
  416. }
  417. function tapActionSheet(index) {
  418. switch (index) {
  419. case 0:
  420. {
  421. switch (health.mode) {
  422. case 'DAY':
  423. case 'NIGHT':
  424. jumpPage('/_health/pages/schedules?mode=' + health.mode)
  425. break;
  426. case 'FAST':
  427. case 'SLEEP':
  428. {
  429. const obj = getScenario(health.windows, health.mode)
  430. if (obj.window_id) {
  431. //编辑本次时长
  432. setDurationPicker(true)
  433. }
  434. else {
  435. jumpPage('/_health/pages/schedules?mode=' + health.mode)
  436. }
  437. }
  438. break;
  439. case 'EAT':
  440. //add snack
  441. jumpPage(`/_health/pages/add_moment?title=加餐&is_temp=${true}`)
  442. break;
  443. case 'ACTIVE':
  444. //记录一次活动
  445. jumpPage(`/_health/pages/add_moment?title=&is_temp=${true}`)
  446. break;
  447. }
  448. }
  449. break;
  450. case 1:
  451. {
  452. switch (health.mode) {
  453. case 'EAT':
  454. jumpPage('/_health/pages/schedules?mode=' + health.mode)
  455. break;
  456. case 'FAST':
  457. case 'SLEEP':
  458. const obj = getScenario(health.windows, health.mode)
  459. if (obj.window_id) {
  460. //del record
  461. jumpPage('/_health/pages/schedules?mode=' + health.mode)
  462. console.log('zzzzzzzzz')
  463. }
  464. else {
  465. }
  466. break;
  467. case 'ACTIVE':
  468. jumpPage('/_health/pages/schedules?mode=' + health.mode)
  469. break;
  470. case 'DAY':
  471. case 'NIGHT':
  472. chooseLocation()
  473. break;
  474. }
  475. }
  476. break;
  477. case 2:
  478. {
  479. switch (health.mode) {
  480. case 'EAT':
  481. case 'ACTIVE':
  482. tapMakeDone()
  483. break;
  484. }
  485. }
  486. break;
  487. }
  488. }
  489. function tapMakeDone() {
  490. makeDone(getScenario(health.windows, health.mode).window_id).then(res => {
  491. global.refreshWindow()
  492. global.refreshHistory()
  493. })
  494. }
  495. function detail() {
  496. const { day, night } = health.windows.night_day
  497. const { fast, eat } = health.windows.fast_eat
  498. const { sleep, active } = health.windows.sleep_active
  499. let list: any = []
  500. switch (health.mode) {
  501. case 'DAY':
  502. list = day.timeline
  503. if (active.onboard == false) {
  504. return <OnBoard title='你还没有开启位置授权'
  505. desc="获取准确的日出日落信息需要您开启微信运动授权,点击下方按钮进行授权"
  506. btnTitle="去开启"
  507. onClick={chooseLocation}
  508. />
  509. }
  510. break;
  511. case 'NIGHT':
  512. list = night.timeline
  513. if (active.onboard == false) {
  514. return <OnBoard title='你还没有开启位置授权'
  515. desc='获取准确的日出日落信息需要您开启微信运动授权,点击下方按钮进行授权'
  516. btnTitle="去开启"
  517. onClick={chooseLocation}
  518. />
  519. }
  520. break;
  521. case 'FAST':
  522. list = fast.timeline
  523. break;
  524. case 'EAT':
  525. list = eat.timeline
  526. break;
  527. case 'SLEEP':
  528. list = sleep.timeline
  529. break;
  530. case 'ACTIVE':
  531. list = active.timeline
  532. if (active.onboard == false) {
  533. return <OnBoard title={list[0].title}
  534. desc="Subtitle"
  535. btnTitle="Action"
  536. onClick={() => {
  537. jumpPage('/_health/pages/active_plan?schedule=' + JSON.stringify(list.length > 0 ? list[0] : '{}'))
  538. }}
  539. />
  540. }
  541. break;
  542. }
  543. return <View>
  544. {
  545. list.map((item, index) => {
  546. return timelineItem(item, index, list.length)
  547. })
  548. }
  549. </View>
  550. }
  551. function switchText() {
  552. switch (health.mode) {
  553. case 'FAST':
  554. return 'Switch to Eat'
  555. case 'EAT':
  556. return 'Switch to Fast'
  557. case 'DAY':
  558. return 'Switch to Night'
  559. case 'NIGHT':
  560. return 'Switch to Daylight'
  561. case 'SLEEP':
  562. return 'Switch to Activity'
  563. case 'ACTIVE':
  564. return 'Switch to Sleep'
  565. }
  566. return ''
  567. }
  568. function tapSwitchBtn() {
  569. switch (health.mode) {
  570. case 'FAST':
  571. dispatch(setMode('EAT'));
  572. break
  573. case 'EAT':
  574. dispatch(setMode('FAST'));
  575. break
  576. case 'DAY':
  577. dispatch(setMode('NIGHT'));
  578. break
  579. case 'NIGHT':
  580. dispatch(setMode('DAY'));
  581. break
  582. case 'SLEEP':
  583. dispatch(setMode('ACTIVE'));
  584. break
  585. case 'ACTIVE':
  586. dispatch(setMode('SLEEP'));
  587. break
  588. }
  589. }
  590. function windowStatus() {
  591. var statusType = getWindowStatus(health.windows, health.mode)
  592. switch (statusType) {
  593. case WindowStatusType.open:
  594. return 'New open'
  595. case WindowStatusType.process:
  596. return 'In process'
  597. case WindowStatusType.upcoming:
  598. return 'Upcoming'
  599. }
  600. return ''
  601. }
  602. function tapClearLocation() {
  603. Taro.showModal({
  604. title: '提示',
  605. content: '确认清除位置数据?',
  606. success: function (res) {
  607. if (res.confirm) {
  608. clearLocation().then(res => {
  609. global.refreshWindow()
  610. })
  611. } else if (res.cancel) {
  612. console.log('用户点击取消')
  613. }
  614. }
  615. })
  616. }
  617. function chooseLocation() {
  618. if (!user.isLogin) {
  619. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  620. return
  621. }
  622. Taro.chooseLocation({
  623. // latitude: authInfo && authInfo.lat ? authInfo.lat : undefined,
  624. // longitude: authInfo && authInfo.lat ? authInfo.lng : undefined,
  625. success: function (res) {
  626. uploadLocation(res)
  627. },
  628. fail(res) {
  629. Taro.showToast({
  630. title: '位置修改失败!\n请重新选择就近位置',
  631. icon: 'none'
  632. })
  633. },
  634. complete(res) {
  635. }
  636. })
  637. }
  638. function uploadLocation(res) {
  639. var today = new Date()
  640. var yesterday = new Date(today.getTime() - 24 * 3600 * 1000)
  641. var tomorrow = new Date(today.getTime() + 24 * 3600 * 1000 * 5)
  642. var strYesterday = `${yesterday.getFullYear()}-${TimeFormatter.padZero(yesterday.getMonth() + 1)}-${TimeFormatter.padZero(yesterday.getDate())}`
  643. var strTomorrow = `${tomorrow.getFullYear()}-${TimeFormatter.padZero(tomorrow.getMonth() + 1)}-${TimeFormatter.padZero(tomorrow.getDate())}`
  644. systemLocation({
  645. lat: res.latitude,
  646. lng: res.longitude,
  647. name: res.name,
  648. address: res.address,
  649. date_start: strYesterday,
  650. date_end: strTomorrow,
  651. coordinate_system_standard: process.env.TARO_ENV == 'weapp' ? 'GCJ-02' : 'WGS-84'
  652. }).then(data => {
  653. global.refreshWindow()
  654. })
  655. }
  656. function updateDuration(duration) {
  657. setDurationPicker(false)
  658. const scenario = getScenario(health.windows, health.mode)
  659. updateEventDuration(scenario.timeline[0].event_id, duration).then(res => {
  660. global.refreshWindow()
  661. })
  662. }
  663. function timePointClass() {
  664. if (getWindowStatus(health.windows, health.mode) == WindowStatusType.process) {
  665. return 'time_point time_point_animation'
  666. }
  667. return 'time_point'
  668. }
  669. return <View className="main-console-bg">
  670. <Image className="main_arrow" src={require('@assets/images/center_arrow.png')} />
  671. <View className="main_summary">
  672. {/* <View className="main_summary_status" style={{ color: getThemeColor(health.mode) }}>{windowStatus()}</View> */}
  673. <View className="main_summary_time" style={{ color: getWindowStatus(health.windows, health.mode) == WindowStatusType.upcoming ? '#B2B2B2' : '#000' }}>{getCountownTime(health.windows, health.mode)}
  674. <View className={timePointClass()}
  675. style={{ backgroundColor: getWindowStatus(health.windows, health.mode) == WindowStatusType.upcoming ? '#B2B2B2' : getThemeColor(health.mode) }} />
  676. </View>
  677. <Text className="main_summary_duration">Total {getDuration(health.windows, health.mode)}</Text>
  678. <View className="border_footer_line" />
  679. </View>
  680. <View style={{ backgroundColor: '#fff', width: rpxToPx(750) }}>
  681. {
  682. detail()
  683. }
  684. {
  685. health.mode == 'ACTIVE' && <View onClick={() => {
  686. var list = getScenario(health.windows, health.mode).timeline
  687. jumpPage('/_health/pages/active_plan?schedule=' + JSON.stringify(list.length > 0 ? list[0] : '{}'))
  688. }}>测试</View>
  689. }
  690. </View>
  691. <View className="main_footer">
  692. <Text className="main_footer_text" onClick={tapSwitchBtn}>{switchText()}</Text>
  693. {/* {
  694. (health.mode == 'EAT' || health.mode == 'ACTIVE') && <Text style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }} onClick={more}>更多</Text>
  695. } */}
  696. {/* {
  697. (health.mode == 'DAY' || health.mode == 'NIGHT') && <Text onClick={chooseLocation}>选择位置</Text>
  698. } */}
  699. {
  700. (health.mode == 'DAY' || health.mode == 'NIGHT') && <Text onClick={tapClearLocation}>清除位置</Text>
  701. }
  702. <View className="main_footer_more" onClick={more}>
  703. <IconMore color="#b2b2b2" width={17} />
  704. </View>
  705. </View>
  706. {
  707. health.mode == 'ACTIVE' && <View className="console_active_bg" onClick={() => {
  708. if (!user.isLogin) {
  709. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  710. return
  711. }
  712. jumpPage('/_health/pages/move')
  713. }}>
  714. <View className="console_active">
  715. <Image className="active_icon" src={require('@assets/_health/walk.png')} />
  716. <Text className="active_text">Move More</Text>
  717. <Image className="cell_arrow" src={require('@assets/_health/cell_arrow.png')} />
  718. </View>
  719. </View>
  720. }
  721. <View className="circle" />
  722. {
  723. showTimePicker && modalContent()
  724. }
  725. {
  726. showPicker && timeContent()
  727. }
  728. {
  729. durationPicker && <DurationPicker
  730. done={(time) => {
  731. updateDuration(time)
  732. }}
  733. dismiss={() => {
  734. setDurationPicker(false)
  735. }} time={getScenario(health.windows, health.mode).target.duration} />
  736. }
  737. </View>
  738. }