Leon 1 ano atrás
pai
commit
238f220cec

+ 2 - 2
src/_health/components/fast_sleep_console.tsx

@@ -65,7 +65,7 @@ export default function FastSleepConsole(props: { step: number, data: any, del:
                 break;
         }
 
-        jumpPage(`/_health/pages/log_time?is_fast_with_sleep=1&index=${index}&initCheck=${health.fast_with_sleep.status == 'OG2_MISALIGNED' ? 1 : 0}&single=${index == 0 ? 1 : 0}&is_start=${is_start}&window=${window}&data=${JSON.stringify(props.data)}`)
+        jumpPage(`/_health/pages/log_time?is_fast_with_sleep=1&index=${index}&initCheck=${health.fast_with_sleep.status == 'OG2_MISALIGNED' ? 1 : 0}&single=${index == 0 ? 1 : 0}&is_start=${is_start}&window=${window}`)
         /*
             const isSingle = router.params.single == '1'
     const isFast = router.params.window == 'FAST'
@@ -278,7 +278,7 @@ export default function FastSleepConsole(props: { step: number, data: any, del:
                         width={rpxToPx(128)}
                         height={rpxToPx(72)}
                         onClick={() => {
-                            jumpPage(`/_health/pages/log_time?is_fast_with_sleep=1&index=${1}&single=0&initCheck=1`)
+                            jumpPage(`/_health/pages/log_time?is_fast_with_sleep=1&index=${1}&single=0&initCheck=1&initIndex=${index}`)
                         }}
                     />
                 </View>

+ 78 - 33
src/_health/pages/log_time.tsx

@@ -50,7 +50,7 @@ export default function LogTime() {
     const [showGoal, setShowGoal] = useState(false)
     const tapIndex = router.params.index ?? 0
 
-    const [expandIndex, setExpandIndex] = useState(tapIndex)
+    const [expandIndex, setExpandIndex] = useState(router.params.initIndex ? router.params.initIndex : tapIndex)
     const [array, setArray] = useState<any>([])
     const [errors, setErrors] = useState<any>([])
     const [conflicts, setConflicts] = useState<any>([])
@@ -58,6 +58,8 @@ export default function LogTime() {
     const [autoCheck, setAutoCheck] = useState(false)
     const [initCheck, setInitCheck] = useState(router.params.initCheck == '1')
 
+    const [ignoreCheck, setIgnoreCheck] = useState(false)
+
 
     useEffect(() => {
         if (isSingle) {
@@ -85,13 +87,6 @@ export default function LogTime() {
         t2 += 24 * 3600 * 1000
         var left = t2 - t + 500
         setTimeout(() => {
-            setEnterTime(new Date().getTime())
-            // var list = arrayRef.current
-            // debugger
-            // list.map((item) => {
-            //     item.today = false
-            // })
-            // setArray(list)
             setArray(array => {
                 array.map((item) => {
                     item.today = false
@@ -104,10 +99,16 @@ export default function LogTime() {
 
     useEffect(() => {
         if (autoCheck) {
-            tapCommit(true)
+            if (ignoreCheck) {
+                setIgnoreCheck(false)
+            }
+            else {
+                tapCommit(true)
+            }
+
         }
         if (initCheck && array.length > 0) {
-            tapCommit(true)
+            tapCommit(true, true)
             setInitCheck(false)
         }
     }, [array])
@@ -219,11 +220,31 @@ export default function LogTime() {
                     var sleepEndToday = new Date().getDate() == new Date(sleepEndTime).getDate()
                     list[2].today = sleepEndToday
                     list[2].time = dayjs(sleepEndTime).format('HH:mm')
+
                 }
+
             }
 
+            if (fast.real && fast.real.start_timestamp) {
+                var fastStartToday = new Date().getDate() == new Date(fast.real.start_timestamp).getDate()
+                list[0].today = fastStartToday
+                list[0].disable = true
+                list[0].time = dayjs(fast.real.start_timestamp).format('HH:mm')
+            }
 
+            if (sleep.real && sleep.real.start_timestamp) {
+                var sleepStartToday = new Date().getDate() == new Date(sleep.real.start_timestamp).getDate()
+                list[1].today = sleepStartToday
+                list[1].disable = true
+                list[1].time = dayjs(sleep.real.start_timestamp).format('HH:mm')
+            }
 
+            if (list.length > 2 && sleep.real && sleep.real.end_timestamp) {
+                var sleepEndToday = new Date().getDate() == new Date(sleep.real.end_timestamp).getDate()
+                list[2].today = sleepEndToday
+                list[2].disable = true
+                list[2].time = dayjs(sleep.real.end_timestamp).format('HH:mm')
+            }
         }
         setArray(list)
 
@@ -254,7 +275,7 @@ export default function LogTime() {
         return timestamp
     }
 
-    function tapCommit(onlyCheck) {
+    function tapCommit(onlyCheck, firstCheck = false) {
         var list: any = []
         if (isSingle) {
             var obj = array[0]
@@ -319,13 +340,10 @@ export default function LogTime() {
             else {
 
 
-                const { status } = data
+                // const { status } = data
                 for (var i = 0; i <= tapIndex; i++) {
-                    if ((status == 'OG1' || status == 'OG2' || status == 'OG3') && i == 0) {
-                    }
-                    else if ((status == 'OG2' || status == 'OG3' || status == 'OG2_NO1') && i == 1) {
-                    }
-                    else if (status == 'OG3' && i == 2) {
+                    if (firstCheck && i > 1) {
+
                     }
                     else {
                         var obj = array[i]
@@ -363,13 +381,26 @@ export default function LogTime() {
                 return;
             }
         }
-        commit(list, onlyCheck)
+
+        if (firstCheck && parseInt(router.params.initIndex) == 1) {
+            var temps = [list[1], list[0]]
+            commit(temps, onlyCheck)
+        }
+        else {
+            commit(list, onlyCheck)
+        }
+
 
     }
 
     function commit(list, onlyCheck) {
+        console.log(list)
+        const sortedData = list.sort((a, b) => {
+            return b.extra.confirm_time - a.extra.confirm_time; // 降序
+        });
+        console.log(sortedData)
         clockTimes({
-            check_items: list,
+            check_items: sortedData,
             op_page: isFastWithSleep ? 'FAST_WITH_SLEEP' : null,
             only_check: onlyCheck,
             extra: {
@@ -389,11 +420,22 @@ export default function LogTime() {
                     })
                 }
 
+
+
             }
             else {
                 setErrors((res as any).error_messages)
                 setConflicts((res as any).conflict_schedule_ids)
                 setAutoCheck(true)
+                var tempList = JSON.parse(JSON.stringify(array))
+                tempList.map(item => {
+                    if ((res as any).conflict_schedule_ids.includes(item.schedule_id)) {
+                        item.disable = false
+                    }
+                })
+                setIgnoreCheck(true)
+                setArray(tempList)
+
             }
 
             // Taro.navigateBack({
@@ -412,6 +454,7 @@ export default function LogTime() {
         var list = JSON.parse(JSON.stringify(array))
         list[index].today = isToday
         list[index].time = schedule_time
+        list[index].extra.confirm_time = new Date().getTime()
         setArray(list)
     }
 
@@ -447,7 +490,7 @@ export default function LogTime() {
 
     }
 
-    function logItem(index: number, iFast: boolean, iStart: boolean, showLine: boolean, disable = false) {
+    function logItem(index: number, iFast: boolean, iStart: boolean, showLine: boolean) {
         const { fast, sleep } = data
         var schedule_time = ''
         var title = ''
@@ -467,7 +510,7 @@ export default function LogTime() {
 
 
 
-            if (disable) {
+            if (array[index].disable) {
                 var timestamp = iStart ? fast.real.start_timestamp : fast.real.end_timestamp
                 const dt = dayjs(timestamp);
                 const yesterday = today.subtract(1, 'day');
@@ -489,7 +532,7 @@ export default function LogTime() {
                 schedule_time = dayjs(sleep.target.end_timestamp).format('HH:mm')
             }
             title = iStart ? 'Bedtime' : 'Wake up'
-            if (disable) {
+            if (array[index].disable) {
                 var timestamp = iStart ? sleep.real.start_timestamp : sleep.real.end_timestamp
                 const dt = dayjs(timestamp);
                 const yesterday = today.subtract(1, 'day');
@@ -508,7 +551,6 @@ export default function LogTime() {
         var showError = false;
         if (conflicts.includes(schedule_id)) {
             showError = true
-            disable = false
         }
 
 
@@ -538,10 +580,11 @@ export default function LogTime() {
                         fontSize={rpxToPx(34)}
                         width={rpxToPx(196)}
                         height={rpxToPx(84)}
-                        disable={disable}
+                        disable={array[index].disable}
                         onClick={() => {
                             var list = JSON.parse(JSON.stringify(array))
                             list[index].today = !list[index].today
+                            list[index].extra.confirm_time = new Date().getTime()
                             setArray(list)
                         }}
                     />
@@ -560,7 +603,7 @@ export default function LogTime() {
                         fontSize={rpxToPx(34)}
                         width={rpxToPx(136)}
                         height={rpxToPx(84)}
-                        disable={disable}
+                        disable={array[index].disable}
                         onClick={() => {
                             setExpandIndex(index)
                         }}
@@ -569,13 +612,15 @@ export default function LogTime() {
                 {
                     isSingle && <View style={{ flex: 1 }} />
                 }
-                <View className='border_footer_line' style={{left:rpxToPx(66)}}/>
+                <View className='border_footer_line' style={{ left: rpxToPx(66) }} />
             </View>
             {
                 expandIndex == index && <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', width: rpxToPx(698) }}>
                     <NewTimePicker time={array[index].time} onChange={(e) => {
                         var list = JSON.parse(JSON.stringify(array))
                         list[index].time = e
+                        list[index].extra.confirm_time = new Date().getTime()
+                        debugger
                         setArray(list)
                     }} color={iFast ? MainColorType.fast : MainColorType.sleep} />
                 </View>
@@ -600,7 +645,7 @@ export default function LogTime() {
                 </View>
             }
             {
-                showLine && <View className="border_footer_line" style={{left:rpxToPx(66)}}/>
+                showLine && <View className="border_footer_line" style={{ left: rpxToPx(66) }} />
             }
 
         </View>
@@ -635,7 +680,7 @@ export default function LogTime() {
             case 1:
                 return <View style={{ position: 'relative' }}>
                     {
-                        logItem(0, true, true, true, !(status == 'WFS' || status == 'OG2_NO1'))
+                        logItem(0, true, true, true)
                     }
                     {
                         logItem(1, false, true, false)
@@ -644,10 +689,10 @@ export default function LogTime() {
             case 2:
                 return <View style={{ position: 'relative' }}>
                     {
-                        logItem(0, true, true, true, !(status == 'WFS' || status == 'OG2_NO1'))
+                        logItem(0, true, true, true)
                     }
                     {
-                        logItem(1, false, true, true, !(status == 'WFS' || status == 'OG1'))
+                        logItem(1, false, true, true)
                     }
                     {
                         logItem(2, false, false, false)
@@ -656,13 +701,13 @@ export default function LogTime() {
             case 3:
                 return <View style={{ position: 'relative' }}>
                     {
-                        logItem(0, true, true, true, !(status == 'WFS' || status == 'OG2_NO1'))
+                        logItem(0, true, true, true)
                     }
                     {
-                        logItem(1, false, true, true, !(status == 'WFS' || status == 'OG1'))
+                        logItem(1, false, true, true)
                     }
                     {
-                        logItem(2, false, false, true, !(status == 'WFS' || status == 'OG1' || status == 'OG2' || status == 'OG2_NO1'))
+                        logItem(2, false, false, true)
                     }
                     {
                         logItem(3, true, false, false)