leon 1 年之前
父節點
當前提交
bdb8d4f35d
共有 1 個文件被更改,包括 43 次插入37 次删除
  1. 43 37
      src/_health/pages/long_fast.tsx

+ 43 - 37
src/_health/pages/long_fast.tsx

@@ -20,6 +20,7 @@ import NewModal from "../base/new_modal";
 import NewDurationPicker, { DurationPickerType } from "../base/new_durationpicker";
 import Taro from "@tarojs/taro";
 import { useTranslation } from "react-i18next";
+import NewTimePicker from "../base/new_timepicker";
 
 let useActionSheet;
 if (process.env.TARO_ENV == 'rn') {
@@ -31,7 +32,9 @@ export default function LongFast() {
     const long_fast = health.long_fast
     const [count, setCount] = useState(1)
     const [editDuration, setEditDuration] = useState(false)
+    const [showPicker, setShowPicker] = useState(false)
     const [duration, setDuration] = useState(0)
+    const [time, setTime] = useState(dayjs().format('HH:mm'))
     const { t } = useTranslation()
     let showActionSheetWithOptions;
     if (process.env.TARO_ENV == 'rn') {
@@ -80,34 +83,8 @@ export default function LongFast() {
     }
 
     function tapEnd() {
-        save()
-        // global.set_time = new Date().getTime()
-        // var count = Math.floor((new Date().getTime() - long_fast.real.start_timestamp) / 1000)
-        // if (count >= 24 * 3600) {
-        //     // showAlert({
-        //     //     title: 'Saving as Long Fast',
-        //     //     content: 'Fasting that lasts more than 24 hours will be saved as Long Fast. ',
-        //     //     showCancel: true,
-        //     //     cancelText: '取消',
-        //     //     confirmText: '保存',
-        //     //     confirm: () => {
-        //     //         save()
-        //     //     }
-        //     // })
-        //     save()
-        // }
-        // else {
-        //     showAlert({
-        //         title: 'Saving as Intermittent Fasting',
-        //         content: 'Fasting that lasts fewer than 24 hours will be saved as Intermittent Fasting.',
-        //         showCancel: true,
-        //         cancelText: '取消',
-        //         confirmText: '保存',
-        //         confirm: () => {
-        //             save()
-        //         }
-        //     })
-        // }
+        // save()
+        setShowPicker(true)
     }
 
     function tapMore() {
@@ -152,11 +129,14 @@ export default function LongFast() {
     }
 
     function save(warn_code = null) {
+        var date = new Date()
+        date.setHours(parseInt(time.substring(0, 2)))
+        date.setMinutes(parseInt(time.substring(3, 5)))
         var params: any = {
             check_items: [{
                 schedule_id: long_fast.timeline[1].schedule_id,
-                date: dayjs().format('YYYYMMDD'),
-                timestamp: new Date().getTime(),
+                date: dayjs(date.getTime()).format('YYYYMMDD'),
+                timestamp: date.getTime(),
                 extra: {
                     set_time: global.set_time ? global.set_time : new Date().getTime(),
                     confirm_time: new Date().getTime()
@@ -226,7 +206,7 @@ export default function LongFast() {
                         mode="aspectFill"
                         style={{ width: rpxToPx(28), height: rpxToPx(28), borderRadius: rpxToPx(4) }} />
                 }
-                <Text className="h20" style={{ marginLeft: rpxToPx(12),  color: MainColorType.g02 }}>{moment.description} · {TimeFormatter.dateDescription(moment.time.timestamp, true)}</Text>
+                <Text className="h20" style={{ marginLeft: rpxToPx(12), color: MainColorType.g02 }}>{moment.description} · {TimeFormatter.dateDescription(moment.time.timestamp, true)}</Text>
                 {/* <Text className="h20" style={{ marginLeft: rpxToPx(12), color: MainColorType.g02 }}></Text> */}
             </View>
         }
@@ -291,12 +271,19 @@ export default function LongFast() {
 
         <View className="long_fast_footer" style={{ backgroundColor: 'transparent', marginBottom: -rpxToPx(35) }}>
             <View style={{ width: rpxToPx(316), height: rpxToPx(128), display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
-                <NewButton
-                    type={NewButtonType.link}
-                    title={'See Guidelines'}
-                    onClick={() => { }}
-                >
-                </NewButton>
+                {
+                    long_fast.status == 'OG' ? <NewButton
+                        type={NewButtonType.link}
+                        title={'End longfast'}
+                        onClick={tapEnd}
+                    >
+                    </NewButton> : <NewButton
+                        type={NewButtonType.link}
+                        title={'See Guidelines'}
+                        onClick={() => { }}
+                    >
+                    </NewButton>
+                }
             </View>
             {
                 long_fast.status == 'OG' && <NewButton
@@ -339,5 +326,24 @@ export default function LongFast() {
                 </View>
             </NewModal>
         }
+        {
+            showPicker && <NewModal
+                title='结束长断食'
+                dismiss={() => {
+                    setShowPicker(false)
+                }}
+                confirm={() => {
+
+                    save()
+                }}
+                themeColor={getThemeColor(health.mode)}>
+                <View style={{ flexDirection: 'column', display: 'flex', alignItems: 'center', marginBottom: 20 }}>
+                    <NewTimePicker
+                        color={MainColorType.fast}
+                        time={dayjs().format('HH:mm')}
+                        onChange={e => setTime(e)} />
+                </View>
+            </NewModal>
+        }
     </View>
 }