|
|
@@ -1,31 +1,45 @@
|
|
|
-import { View, Text, Input } from "@tarojs/components";
|
|
|
+import { View, Text, Input, Switch } from "@tarojs/components";
|
|
|
import './add_label.scss'
|
|
|
-import { useState } from "react";
|
|
|
+import { useEffect, useState } from "react";
|
|
|
import Modal from "@/components/layout/Modal.weapp";
|
|
|
import TimePicker from "@/features/common/TimePicker";
|
|
|
import dayjs from "dayjs";
|
|
|
import { MainColorType } from "@/context/themes/color";
|
|
|
-import { createSchedule } from "@/services/health";
|
|
|
+import { createSchedule, getLabelsTime, getSchedules } from "@/services/health";
|
|
|
import Taro from "@tarojs/taro";
|
|
|
import { useSelector } from "react-redux";
|
|
|
import { getThemeColor } from "@/features/health/hooks/health_hooks";
|
|
|
|
|
|
-export default function AddLabel(props: { labels: any }) {
|
|
|
+export default function AddLabel(props: { labels: any, defaultValue?: string }) {
|
|
|
const [showTimePicker, setShowTimePicker] = useState(false)
|
|
|
const health = useSelector((state: any) => state.health);
|
|
|
- const [value, setValue] = useState('')
|
|
|
+ const [value, setValue] = useState(props.defaultValue ?? '')
|
|
|
+ const [isFullday, setIsFullday] = useState(false)
|
|
|
+ const [timeLabels, setTimeLabels] = useState<any>([])
|
|
|
+ const [strTime, setStrTime] = useState('')
|
|
|
|
|
|
- function timeContent() {
|
|
|
- return <Modal
|
|
|
- testInfo={null}
|
|
|
- dismiss={() => {
|
|
|
- setShowTimePicker(false)
|
|
|
- }}
|
|
|
- confirm={() => { }}>
|
|
|
- {
|
|
|
- pickerContent()
|
|
|
- }
|
|
|
- </Modal>
|
|
|
+ // function timeContent() {
|
|
|
+ // return <Modal
|
|
|
+ // testInfo={null}
|
|
|
+ // dismiss={() => {
|
|
|
+ // setShowTimePicker(false)
|
|
|
+ // }}
|
|
|
+ // confirm={() => { }}>
|
|
|
+ // {
|
|
|
+ // pickerContent()
|
|
|
+ // }
|
|
|
+ // </Modal>
|
|
|
+ // }
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ getData()
|
|
|
+ }, [])
|
|
|
+
|
|
|
+ function getData() {
|
|
|
+
|
|
|
+ getLabelsTime({}).then(res => {
|
|
|
+ setTimeLabels((res as any).labels)
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
function pickerContent() {
|
|
|
@@ -59,6 +73,59 @@ export default function AddLabel(props: { labels: any }) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ function done() {
|
|
|
+ createSchedule({
|
|
|
+
|
|
|
+ schedules: [{
|
|
|
+ event: health.mode == 'EAT' ? 'EAT_CUSTOM' : 'ACTIVE_CUSTOM',
|
|
|
+ title: value,
|
|
|
+ time: dayjs().format('HH:mm'),
|
|
|
+ is_all_day: isFullday
|
|
|
+ }]
|
|
|
+ }).then(res => {
|
|
|
+ global.refreshWindow()
|
|
|
+ global.refreshSchedules()
|
|
|
+ // if (process.env.TARO_ENV == 'weapp') {
|
|
|
+ // Taro.navigateBack()
|
|
|
+ // }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ function timeContent() {
|
|
|
+ return <View>
|
|
|
+ <View className="header1">Set Time</View>
|
|
|
+ <View style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between' }}>
|
|
|
+ <Text>全天时间</Text>
|
|
|
+ <Switch
|
|
|
+ color={getThemeColor(health.mode)}
|
|
|
+ onChange={(e) => {
|
|
|
+ setIsFullday(e.detail.value)
|
|
|
+ // item.reminder = e.detail.value
|
|
|
+ // setList([...list])
|
|
|
+ }} />
|
|
|
+ </View>
|
|
|
+ {
|
|
|
+ isFullday ? <View>
|
|
|
+ <Input className="input_lb" placeholder="选择或输入时间标签" value={strTime} onInput={(e: any) => {
|
|
|
+ setStrTime(e.target.value)
|
|
|
+ }} />
|
|
|
+ <View className="label_bg">
|
|
|
+ {
|
|
|
+ timeLabels.map((item, index) => {
|
|
|
+ return <View className="label" key={index} onClick={() => setStrTime(item.title)}>{item.title}</View>
|
|
|
+ })
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ </View> :
|
|
|
+ <View style={{ flexDirection: 'column', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
|
|
+ <Text>{dayjs().format('HH:mm')}</Text>
|
|
|
+ <Text>Picker placeholder</Text>
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+ <View className="pop_footer" style={{ backgroundColor: getThemeColor(health.mode) }} onClick={() => done()}>完成</View>
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+
|
|
|
return <View>
|
|
|
<View className="header1">标记为</View>
|
|
|
<View className="body1">
|
|
|
@@ -74,8 +141,19 @@ export default function AddLabel(props: { labels: any }) {
|
|
|
</View>
|
|
|
</View>
|
|
|
<View className="pop_footer" style={{ backgroundColor: getThemeColor(health.mode) }} onClick={() => setShowTimePicker(true)}>下一步</View>
|
|
|
- {
|
|
|
+ {/* {
|
|
|
showTimePicker && timeContent()
|
|
|
+ } */}
|
|
|
+ {
|
|
|
+ showTimePicker && <Modal testInfo={null}
|
|
|
+ dismiss={() => {
|
|
|
+ setShowTimePicker(false)
|
|
|
+ }}
|
|
|
+ confirm={() => { }}>
|
|
|
+ {
|
|
|
+ timeContent()
|
|
|
+ }
|
|
|
+ </Modal>
|
|
|
}
|
|
|
</View>
|
|
|
}
|