Leon 2 anni fa
parent
commit
e6fbd26491

BIN
src/assets/images/more-vertical.png


+ 6 - 2
src/features/food/FoodConsole.tsx

@@ -29,19 +29,22 @@ export default function Component(props: { addItem: Function, firstItem: any })
     }
 
     useEffect(() => {
-        console.log('apple',props.firstItem)
         setFirstData(props.firstItem)
-    }, [props.firstItem,props.firstItem.feel.post_meal])
+    }, [props.firstItem, props.firstItem.feel.post_meal])
 
     useEffect(() => {
         if (firstData &&
             firstData.mindful_mode == 'AWARE' &&
+            firstData.status != 'ABANDONED' &&
             (!firstData.feel.post_meal || !firstData.feel.pre_meal)) {
             setLastUnFinished(true)
             setModeOn(true)
         }
         else {
             setLastUnFinished(false)
+            var isOn = Taro.getStorageSync('food_switch')
+            setModeOn(isOn)
+            // Taro.setStorageSync('food_switch',e.detail.value)
         }
     }, [firstData])
 
@@ -206,6 +209,7 @@ export default function Component(props: { addItem: Function, firstItem: any })
 
     function modeChange(e) {
         setModeOn(e.detail.value)
+        Taro.setStorageSync('food_switch', e.detail.value)
     }
 
     return <View style={{ marginBottom: rpxToPx(60) }}>

+ 22 - 0
src/features/food/FoodTimelineItem.scss

@@ -122,4 +122,26 @@
     color: #fff;
     opacity: 0.4;
     margin-top: 12px;
+}
+
+.food_item_point{
+    width: 20px;
+    height: 20px;
+    border-radius: 10px;
+    margin-left: -11px;
+    margin-right: 6px;
+}
+
+.food_item_score{
+    font-size: 32px;
+    line-height: 32px;
+    font-weight: bold;
+}
+
+.food_timeline_more{
+    position: absolute;
+    right: 0;
+    top: 0;
+    width: 72px;
+    height: 72px;
 }

+ 46 - 6
src/features/food/FoodTimelineItem.tsx

@@ -219,11 +219,10 @@ export default function Component(props: {
         editFoodJournal({
             feel: feel
         }, detail.id).then(res => {
-            (res as any).showDate = props.data.showDate
-
-            setDetail(res)
-            setCount(count + 1)
             if (isPreMeal) {
+                (res as any).showDate = props.data.showDate
+                setDetail(res)
+                setCount(count + 1)
                 props.refresh()
             }
             else {
@@ -293,6 +292,16 @@ export default function Component(props: {
         })
     }
 
+    function abandon() {
+        editFoodJournal({
+            status: 'ABANDONED'
+        }, detail.id).then(res => {
+            props.forceRefresh()
+        }).catch(e => {
+
+        })
+    }
+
     function showRefreshAlert() {
         Taro.showModal({
             title: t('feature.food.prompt'),
@@ -351,10 +360,31 @@ export default function Component(props: {
         }
     }
 
+    function more() {
+        Taro.showActionSheet({
+            itemList: ['重新开始']
+        }).then(res => {
+            if (res.tapIndex == 0) {
+                abandon()
+            }
+        })
+    }
+
     return <View>
         {
-            detail.mindful_mode == 'AWARE' && detail.feel.pre_meal && !detail.feel.post_meal && <View style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', marginBottom: rpxToPx(60) }}>
+            detail.mindful_mode == 'AWARE' && detail.status != 'ABANDONED' && detail.feel.pre_meal && !detail.feel.post_meal &&
+            <View style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', marginBottom: rpxToPx(60), position: 'relative' }}>
                 <Slider onChanged={(value) => { updateFeel(value, false) }} />
+                <Image src={require('@assets/images/more-vertical.png')} className="food_timeline_more" onClick={more} />
+            </View>
+        }
+        {
+            detail.mindful_mode == 'AWARE' && detail.feel.post_meal &&
+            <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', marginBottom: rpxToPx(60) }}>
+                <View style={{ width: rpxToPx(375) }} />
+                <View className="food_item_point" style={{ backgroundColor: ColorType.food }} />
+                <Text className="food_item_score" style={{ color: ColorType.food }}>{detail.feel.post_meal}
+                    <Text style={{ fontSize: rpxToPx(24) }}>分饱</Text></Text>
             </View>
         }
         <View className="food_timeline_item" onLongPress={showActionSheet}>
@@ -396,10 +426,20 @@ export default function Component(props: {
 
         </View>
         {
-            detail.mindful_mode == 'AWARE' && !detail.feel.pre_meal && <View style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', marginBottom: rpxToPx(60) }}>
+            detail.mindful_mode == 'AWARE' && !detail.feel.pre_meal &&
+            <View style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', marginBottom: rpxToPx(60) }}>
                 <Slider onChanged={(value) => { updateFeel(value, true) }} />
             </View>
         }
+        {
+            detail.mindful_mode == 'AWARE' && detail.feel.pre_meal &&
+            <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', marginBottom: rpxToPx(60) }}>
+                <View style={{ width: rpxToPx(375) }} />
+                <View className="food_item_point" style={{ backgroundColor: ColorType.fast }} />
+                <Text className="food_item_score" style={{ color: ColorType.fast }}>{detail.feel.pre_meal}
+                    <Text style={{ fontSize: rpxToPx(24) }}>分饿</Text></Text>
+            </View>
+        }
         {
             showModal && <Modal dismiss={() => { setShowModal(false) }} confirm={() => { setShowModal(false) }}>
                 <View className='modal_content'>