Leon 1 рік тому
батько
коміт
ebf48419d9

+ 14 - 13
src/_eat/pages/meal_list.tsx

@@ -19,8 +19,9 @@ export default function MealList() {
 
     function schedules() {
         getSchedules({ window: 'EAT' }).then(res => {
-            if ((res as any).schedules && (res as any).schedules.length > 0) {
-                setList((res as any).schedules[0].items)
+            console.log('sss',res)
+            if ((res as any).data && (res as any).data.length > 0) {
+                setList((res as any).data)
             }
         }).catch(e => {
 
@@ -44,27 +45,27 @@ export default function MealList() {
     return <View>
         {
             list.map((item, index) => {
-                return <AtSwipeAction key={index} isOpened options={[
-                    {
-                        text: '删除',
-                        style: {
-                            backgroundColor: '#FF4949'
-                        }
-                    }
-                ]}>
-                    <View className='item' >
+                // return <AtSwipeAction key={index} isOpened options={[
+                //     {
+                //         text: '删除',
+                //         style: {
+                //             backgroundColor: '#FF4949'
+                //         }
+                //     }
+                // ]}>
+                return    <View className='item' key={index}>
                         {
                             showDel && <Text style={{ color: 'red', marginRight: 5 }} onClick={() => delItem(index)}>删除</Text>
                         }
         
                         <View className='item_left'>
                             <Text className='item_index'>第{index + 1}餐</Text>
-                            <Text className='item_name'>{item.label}</Text>
+                            <Text className='item_name'>{item.title}</Text>
                         </View>
                         <Text className='item_time'>{item.time}</Text>
                         <View className='item_line' />
                     </View>
-                </AtSwipeAction>
+                // </AtSwipeAction>
             })
         }
         

+ 39 - 2
src/features/health/MainConsole.tsx

@@ -8,7 +8,7 @@ import { jumpPage } from "../trackTimeDuration/hooks/Common";
 import Modal from "@/components/layout/Modal.weapp";
 import { MainColorType } from "@/context/themes/color";
 import ConsolePicker from "../trackTimeDuration/components/ConsolePicker";
-import { clockTimes, updateSchedule } from "@/services/health";
+import { clockTimes, updateSchedule, updateTarget } from "@/services/health";
 import TimePicker from "../common/TimePicker";
 import showActionSheet from "@/components/basic/ActionSheet";
 
@@ -45,10 +45,15 @@ export default function MainConsole(props: { type: WindowType }) {
         if (item.scenario != 'FAST' && item.scenario != 'SLEEP') {
             return
         }
+
+        if (item.action == 'NA' || item.action == 'POST_MOMENT' ||'SLEEP_WAKE_UP' == item.action) {
+            return;
+        }
         if (!user.isLogin) {
             jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
             return
         }
+        console.log(item)
         setSelItem(item)
         setShowPicker(true)
     }
@@ -150,6 +155,38 @@ export default function MainConsole(props: { type: WindowType }) {
     }
 
     function confirmPickerTime(strTime) {
+        if (selItem.event == 'FAST_END') {
+            const obj = health.windows.fast_eat.fast.timeline[0]
+            if (obj.action=='POST_MOMENT' || obj.action == 'NA') {
+                const format = dayjs(obj.target.timestamp).format(`YYYY-MM-DDT${strTime}:ss`)
+                var t = new Date(format).getTime()
+                if (t <= obj.target.timestamp) {
+                    t += 24 * 3600 * 1000
+                }
+                updateTarget(t, obj.event_id).then(res => {
+                    global.refreshWindow()
+                    setShowPicker(false)
+                })
+                return;
+            }
+        }
+        else if (selItem.event == 'SLEEP_WAKE_UP') {
+            const obj = health.windows.sleep_active.sleep.timeline[0]
+            if (obj.action=='POST_MOMENT' || obj.action == 'NA') {
+                const format = dayjs(obj.target.timestamp).format(`YYYY-MM-DDT${strTime}:ss`)
+                var t = new Date(format).getTime()
+                if (t <= obj.target.timestamp) {
+                    t += 24 * 3600 * 1000
+                }
+                updateTarget(t, obj.event_id).then(res => {
+                    global.refreshWindow()
+                    setShowPicker(false)
+                })
+                return;
+            }
+        }
+        console.log('zzz')
+
         updateSchedule({
             time: strTime
         }, selItem.schedule_id).then(res => {
@@ -318,7 +355,7 @@ export default function MainConsole(props: { type: WindowType }) {
             detail()
         }
         {
-            (health.mode == 'EAT' || health.mode == 'ACTIVE') && <Text style={{display:'flex',alignItems:'center',justifyContent:'center'}} onClick={more}>更多</Text>
+            (health.mode == 'EAT' || health.mode == 'ACTIVE') && <Text style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }} onClick={more}>更多</Text>
         }
         {
             showTimePicker && modalContent()

+ 3 - 0
src/pages/clock/AddMoment.tsx

@@ -137,6 +137,9 @@ export default function AddMoment() {
                 source: 'album'
             }]
         }
+        if (moment.event_id){
+            params.event_id = moment.event_id
+        }
         createMoment(params).then(res => {
             if (process.env.TARO_ENV == 'weapp') {
                 Taro.navigateBack();

+ 14 - 1
src/services/health.tsx

@@ -1,4 +1,4 @@
-import { API_HEALTH_CLOCK, API_HEALTH_LABELS, API_HEALTH_MOMENT, API_HEALTH_RECORD, API_HEALTH_SCHEDULES, API_HEALTH_STREAKS, API_HEALTH_WINDOWS } from "./http/api";
+import { API_HEALTH_CLOCK, API_HEALTH_LABELS, API_HEALTH_MOMENT, API_HEALTH_RECORD, API_HEALTH_SCHEDULES, API_HEALTH_STREAKS, API_HEALTH_TARGET, API_HEALTH_WINDOWS } from "./http/api";
 import { request } from "./http/request";
 
 export const getLabels = (params) => {
@@ -66,6 +66,19 @@ export const delSchedule = (code:string) => {
     })
 }
 
+export const updateTarget = (timestamp,id) =>{
+    return new Promise((resolve, reject) => {
+        request({
+            url: `${API_HEALTH_TARGET}/${id}/duration`, method: 'PUT', data: {target_end_timestamp:timestamp}
+        }).then(res => {
+            resolve(res);
+            // dispatch(loginSuccess(res));
+        }).catch(e => {
+            reject(e)
+        })
+    })
+}
+
 export const records = (params:any)=>{
     return new Promise((resolve, reject) => {
         request({

+ 1 - 0
src/services/http/api.js

@@ -95,6 +95,7 @@ export const API_ORDER_CHECK = `${baseUrl}/api/payment/member/orders/`
 
 //health
 export const API_SET_SCHEDULE = `${baseUrl}/api/fast/schedules`
+export const API_HEALTH_TARGET = `${baseUrl}/api/health/events`
 export const API_HEALTH_MOMENT = `${baseUrl}/api/health/moments`
 export const API_HEALTH_SCHEDULES = `${baseUrl}/api/health/schedules`
 export const API_HEALTH_LABELS = `${baseUrl}/api/health/labels`