|
|
@@ -13,7 +13,10 @@ import { IconShare } from "@/components/basic/Icons";
|
|
|
import { TimeFormatter } from "@/utils/time_format";
|
|
|
import { baseUrl } from "@/services/http/api";
|
|
|
|
|
|
-export default function Component(props: { data: any, index: number, delete: Function, preview: Function, update: Function }) {
|
|
|
+export default function Component(props: {
|
|
|
+ data: any, index: number,
|
|
|
+ delete: Function, preview: Function, update: Function, forceRefresh?: Function
|
|
|
+}) {
|
|
|
const common = useSelector((state: any) => state.common);
|
|
|
const [detail, setDetail] = useState(props.data)
|
|
|
const [count, setCount] = useState(0)
|
|
|
@@ -71,13 +74,17 @@ export default function Component(props: { data: any, index: number, delete: Fun
|
|
|
}
|
|
|
|
|
|
function operateActionSheet() {
|
|
|
+ var itemList = [t('feature.food.action_sheet.tag')]
|
|
|
+ var date = TimeFormatter.getMonthAndDayByDate(detail.start.date)
|
|
|
+ if (date == '今天' || date == '昨天') {
|
|
|
+ itemList.push(t('feature.food.action_sheet.start_time'))
|
|
|
+ itemList.push(t('feature.food.action_sheet.end_time'))
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
Taro.showActionSheet({
|
|
|
alertText: t('feature.food.action_sheet.alert_text'),
|
|
|
- itemList: [
|
|
|
- t('feature.food.action_sheet.tag'),
|
|
|
- t('feature.food.action_sheet.start_time'),
|
|
|
- t('feature.food.action_sheet.end_time'),
|
|
|
- ]
|
|
|
+ itemList: itemList
|
|
|
})
|
|
|
.then(res => {
|
|
|
switch (res.tapIndex) {
|
|
|
@@ -182,6 +189,7 @@ export default function Component(props: { data: any, index: number, delete: Fun
|
|
|
source: detail.media[0].source ? detail.media[0].source : 'album'
|
|
|
}]
|
|
|
}, detail.id).then(res => {
|
|
|
+ (res as any).showDate = props.data.showDate
|
|
|
setDetail(res)
|
|
|
setCount(count + 1)
|
|
|
|
|
|
@@ -210,13 +218,9 @@ export default function Component(props: { data: any, index: number, delete: Fun
|
|
|
code: tag.code
|
|
|
}
|
|
|
}, detail.id).then(res => {
|
|
|
- var obj = detail
|
|
|
- // obj.tags = [tag]
|
|
|
- obj.meal_tag = {
|
|
|
- code: tag.code,
|
|
|
- label: tag.label
|
|
|
- }
|
|
|
- setDetail(obj)
|
|
|
+ (res as any).showDate = props.data.showDate
|
|
|
+
|
|
|
+ setDetail(res)
|
|
|
setCount(count + 1)
|
|
|
|
|
|
props.update(res)
|
|
|
@@ -249,14 +253,33 @@ export default function Component(props: { data: any, index: number, delete: Fun
|
|
|
editFoodJournal({
|
|
|
...obj
|
|
|
}, detail.id).then(res => {
|
|
|
+ (res as any).showDate = props.data.showDate
|
|
|
setDetail(res)
|
|
|
setCount(count + 1)
|
|
|
props.update(res)
|
|
|
+ if ((res as any).index_change) {
|
|
|
+ showRefreshAlert()
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}).catch(e => {
|
|
|
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ function showRefreshAlert() {
|
|
|
+ Taro.showModal({
|
|
|
+ title: t('feature.food.prompt'),
|
|
|
+ content: t('feature.food.prompt_detail'),
|
|
|
+ showCancel: false,
|
|
|
+ success: function (res) {
|
|
|
+ if (res.confirm) {
|
|
|
+ props.forceRefresh!()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
function pickerTagIndex() {
|
|
|
var list = common.meal_tags
|
|
|
if (detail.meal_tag) {
|
|
|
@@ -298,7 +321,7 @@ export default function Component(props: { data: any, index: number, delete: Fun
|
|
|
return detail.start.timestamp
|
|
|
}
|
|
|
else {
|
|
|
- return detail.end.timestamp ? detail.end.timestamp : new Date().getTime()
|
|
|
+ return detail.end.timestamp ? detail.end.timestamp : detail.start.timestamp
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -308,7 +331,7 @@ export default function Component(props: { data: any, index: number, delete: Fun
|
|
|
<View style={{ flex: 1 }}>
|
|
|
{
|
|
|
<View className="tags">
|
|
|
- {detail.showDate && <Text className="food_timeline_item_day">{TimeFormatter.getMonthDayByTimestamp(detail.start.timestamp)}</Text>}
|
|
|
+ {detail.showDate && <Text className="food_timeline_item_day">{TimeFormatter.getMonthAndDayByDate(detail.start.date)}</Text>}
|
|
|
{
|
|
|
props.index == 0 && !detail.meal_tag && common.meal_tags.map((item, index) => {
|
|
|
return index <= 2 ? <View className="tag-item" onClick={() => updateTag(index)}>
|
|
|
@@ -326,7 +349,7 @@ export default function Component(props: { data: any, index: number, delete: Fun
|
|
|
{/* <Image className="thumb" src={detail.cover.url} mode="aspectFill" onClick={preview} /> */}
|
|
|
<Image className="thumb" src={detail.media[0].url + '?x-oss-process=image/resize,w_300,limit_0'} mode="aspectFill" onClick={preview} />
|
|
|
<View className="food_desc" onClick={operateActionSheet}>
|
|
|
- {/* <Text className="food_desc_text">{detail.start && TimeFormatter.getMonthDayByTimestamp(detail.start.timestamp)}</Text> */}
|
|
|
+ {/* <Text className="food_desc_text">{detail.start && TimeFormatter.getMonthAndDayByDate(detail.start.timestamp)}</Text> */}
|
|
|
<Text className="food_desc_text">{detail.meal_tag && detail.meal_tag.label}</Text>
|
|
|
<Text className="food_desc_text">{detail.start && TimeFormatter.getTimeByTimestamp(detail.start.timestamp)}</Text>
|
|
|
<Text className="food_desc_text">{detail.end.timestamp && '~' + TimeFormatter.getTimeByTimestamp(detail.end.timestamp)}</Text>
|