|
|
@@ -0,0 +1,252 @@
|
|
|
+import { View, Text, Image } from "@tarojs/components";
|
|
|
+import './guide.scss'
|
|
|
+import '@/_health/pages/schedules.scss'
|
|
|
+import NewHeader, { NewHeaderType } from "../components/new_header";
|
|
|
+import { useEffect, useState } from "react";
|
|
|
+import { createSchedule, getLabelsEvent, getSchedules } from "@/services/health";
|
|
|
+import { setSchedules } from "@/store/health";
|
|
|
+import { useDispatch, useSelector } from "react-redux";
|
|
|
+import Card from "../components/card";
|
|
|
+import { rpxToPx } from "@/utils/tools";
|
|
|
+import { getThemeColor } from "@/features/health/hooks/health_hooks";
|
|
|
+import Modal from "@/components/layout/Modal.weapp";
|
|
|
+import TimePicker from "@/features/common/TimePicker";
|
|
|
+import NewButton, { NewButtonType } from "../base/new_button";
|
|
|
+import { MainColorType } from "@/context/themes/color";
|
|
|
+import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
|
|
|
+import { IconAdd } from "@/components/basic/Icons";
|
|
|
+import AddLabel from "../components/add_label";
|
|
|
+
|
|
|
+export default function GuideActive() {
|
|
|
+ const health = useSelector((state: any) => state.health);
|
|
|
+ const [schedules, setSchedules1] = useState(health.schedules)
|
|
|
+ const [errors, setErrors] = useState<any>([])
|
|
|
+ const [highlight, setHighlight] = useState(true)
|
|
|
+
|
|
|
+ const [selItem, setSelItem] = useState<any>(null)
|
|
|
+ const [selIndex, setSelIndex] = useState(-1)
|
|
|
+ const [showTimePicker, setShowTimePicker] = useState(false)
|
|
|
+ const [showModal,setShowModal] = useState(false)
|
|
|
+ const [labels, setLabels] = useState<any>([])
|
|
|
+
|
|
|
+ const dispatch = useDispatch()
|
|
|
+ const selMode = 'ACTIVE'
|
|
|
+ useEffect(() => {
|
|
|
+ getLabelsEvent({ window: 'ACTIVE' }).then(res => {
|
|
|
+ setLabels((res as any).labels)
|
|
|
+ })
|
|
|
+
|
|
|
+ setTimeout(() => {
|
|
|
+ setHighlight(false)
|
|
|
+ }, 2000)
|
|
|
+ }, [])
|
|
|
+
|
|
|
+ function itemStyle(obj) {
|
|
|
+ if (obj.is_conflict) {
|
|
|
+ return {
|
|
|
+ backgroundColor: '#FF00001A',
|
|
|
+ color: '#FF0000'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (errors.length > 0) {
|
|
|
+ return {
|
|
|
+ backgroundColor: '#B2B2B21A',
|
|
|
+ color: '#000'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ backgroundColor: obj.window == selMode ? getThemeColor(selMode) + '1A' : '#B2B2B21A',
|
|
|
+ color: obj.window == selMode ? getThemeColor(selMode) : '#000'
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function modalContent() {
|
|
|
+ const strTime = selItem.time
|
|
|
+
|
|
|
+ var title = selItem.title
|
|
|
+ var color = getThemeColor(selItem.window)
|
|
|
+
|
|
|
+ return <TimePicker time={strTime}
|
|
|
+ color={color}
|
|
|
+ title={title}
|
|
|
+ confirm={(e) => {
|
|
|
+ // selItem.time = e
|
|
|
+ setSelItem(selItem)
|
|
|
+ setShowTimePicker(false)
|
|
|
+ var array = JSON.parse(JSON.stringify(health.schedules))
|
|
|
+ array.map(item => {
|
|
|
+ if (item.id == selItem.id) {
|
|
|
+ item.time = e
|
|
|
+ }
|
|
|
+ })
|
|
|
+ dispatch(setSchedules(array))
|
|
|
+ check(array)
|
|
|
+ // var array = JSON.parse(JSON.stringify(list))
|
|
|
+ // array[selIndex].time = e
|
|
|
+ // setList(array)
|
|
|
+ // checkData(array)
|
|
|
+ }}
|
|
|
+ cancel={() => {
|
|
|
+ setShowTimePicker(false)
|
|
|
+ }} />
|
|
|
+ }
|
|
|
+
|
|
|
+ function check(array) {
|
|
|
+ createSchedule({
|
|
|
+ schedules: array,
|
|
|
+ only_check: true,
|
|
|
+ op_page: 'SCHEDULE_WALKTHROUGH_4'
|
|
|
+ }).then(res => {
|
|
|
+ dispatch(setSchedules((res as any).schedules))
|
|
|
+ if ((res as any).result) {
|
|
|
+ setErrors([])
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ setErrors((res as any).error_messages ? (res as any).error_messages : [])
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ function add() {
|
|
|
+ setShowModal(true)
|
|
|
+ }
|
|
|
+
|
|
|
+ function items() {
|
|
|
+ var items = health.schedules.filter(item => item.window == 'ACTIVE')
|
|
|
+ return <Card>
|
|
|
+ {
|
|
|
+ errors.map((item1, index) => {
|
|
|
+ return <View key={index} className='error_tip'>{item1}</View>
|
|
|
+ })
|
|
|
+ }
|
|
|
+ {
|
|
|
+ items.map((obj, i) => {
|
|
|
+ return <View className='schedule_item' key={i} style={{
|
|
|
+ width: rpxToPx(700),
|
|
|
+ boxSizing: 'border-box',
|
|
|
+ backgroundColor: (obj.window == selMode && highlight) ? getThemeColor(selMode) + '08' : '#fff'
|
|
|
+
|
|
|
+ }}>
|
|
|
+ <View className='item_left2'>
|
|
|
+ <View className='item_index'>
|
|
|
+ <View className="index_point" style={{ backgroundColor: getThemeColor(obj.window) }} />
|
|
|
+ </View>
|
|
|
+ <Text className='item_name'>{obj.title}</Text>
|
|
|
+ <View style={{ flex: 1 }} />
|
|
|
+ {
|
|
|
+ obj.is_conflict && <Text className="conflict_tip">时间冲突,请调整</Text>
|
|
|
+ }
|
|
|
+ {
|
|
|
+ !obj.is_all_day && !obj.reminder && <Image src={require('@assets/images/notification_off.png')} className='notification_icon' />
|
|
|
+ }
|
|
|
+ {
|
|
|
+ !obj.is_all_day && <View className='edit_item_time' onClick={() => {
|
|
|
+ setSelIndex(i)
|
|
|
+ setSelItem(obj)
|
|
|
+ setShowTimePicker(true)
|
|
|
+ }} style={itemStyle(obj)}>{obj.time}</View>
|
|
|
+ }
|
|
|
+
|
|
|
+ <View className='item_line' />
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ })
|
|
|
+ }
|
|
|
+ <View className='item_add'
|
|
|
+ onClick={() => add()}>
|
|
|
+ <IconAdd color={MainColorType.eat} width={rpxToPx(34)} />
|
|
|
+ <View className='toolbar_btn' style={{ color: MainColorType.eat }} >添加</View>
|
|
|
+ <View style={{ flex: 1 }} />
|
|
|
+ </View>
|
|
|
+ </Card>
|
|
|
+ }
|
|
|
+
|
|
|
+ function fastSleepItems() {
|
|
|
+ var items = health.schedules.filter(item => item.window == 'SLEEP')
|
|
|
+ return <Card>
|
|
|
+ {
|
|
|
+ items.map((obj, i) => {
|
|
|
+ return <View className='schedule_item' key={i} style={{
|
|
|
+ width: rpxToPx(700),
|
|
|
+ boxSizing: 'border-box',
|
|
|
+ backgroundColor: (obj.window == selMode && highlight) ? getThemeColor(selMode) + '08' : '#fff'
|
|
|
+
|
|
|
+ }}>
|
|
|
+ <View className='item_left2'>
|
|
|
+ <View className='item_index'>
|
|
|
+ <View className="index_point" style={{ backgroundColor: getThemeColor(obj.window) }} />
|
|
|
+ </View>
|
|
|
+ <Text className='item_name'>{obj.title}</Text>
|
|
|
+ <View style={{ flex: 1 }} />
|
|
|
+ {
|
|
|
+ obj.is_conflict && <Text className="conflict_tip">时间冲突,请调整</Text>
|
|
|
+ }
|
|
|
+ {
|
|
|
+ !obj.is_all_day && !obj.reminder && <Image src={require('@assets/images/notification_off.png')} className='notification_icon' />
|
|
|
+ }
|
|
|
+ {
|
|
|
+ !obj.is_all_day && <View className='edit_item_time' onClick={() => {
|
|
|
+ setSelIndex(i)
|
|
|
+ setSelItem(obj)
|
|
|
+ setShowTimePicker(true)
|
|
|
+ }} style={itemStyle(obj)}>{obj.time}</View>
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ i < items.length - 1 && <View className='item_line' />
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ })
|
|
|
+ }
|
|
|
+ </Card>
|
|
|
+ }
|
|
|
+ return <View style={{ flex: 1, display: 'flex', flexDirection: 'column', height: '100vh' }}>
|
|
|
+ <NewHeader type={NewHeaderType.center_subtitle} title="保持活跃" subtitle="我的活动日程" />
|
|
|
+ {
|
|
|
+ items()
|
|
|
+ }
|
|
|
+ <View style={{ height: 20 }} />
|
|
|
+ {
|
|
|
+ fastSleepItems()
|
|
|
+ }
|
|
|
+ <View style={{ flex: 1 }} />
|
|
|
+ <View style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', marginBottom: rpxToPx(128) }}>
|
|
|
+ <NewButton
|
|
|
+ type={NewButtonType.fill}
|
|
|
+ title="下一步"
|
|
|
+ disable={errors.length > 0}
|
|
|
+ color={MainColorType.active}
|
|
|
+ width={rpxToPx(646)}
|
|
|
+ height={rpxToPx(96)}
|
|
|
+ onClick={() => {
|
|
|
+ jumpPage('./guide_full')
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ </View>
|
|
|
+ {
|
|
|
+ showTimePicker && <Modal
|
|
|
+ testInfo={null}
|
|
|
+ dismiss={() => {
|
|
|
+ setShowTimePicker(false)
|
|
|
+ }}
|
|
|
+ confirm={() => {
|
|
|
+
|
|
|
+ }}>
|
|
|
+ {
|
|
|
+ modalContent()
|
|
|
+ }
|
|
|
+ </Modal>
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ showModal && <Modal testInfo={null}
|
|
|
+ dismiss={() => {
|
|
|
+ setShowModal(false)
|
|
|
+ }}
|
|
|
+ confirm={() => { }}>
|
|
|
+ <AddLabel labels={labels} disMiss={() => setShowModal(false)} />
|
|
|
+ </Modal>
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+}
|