|
@@ -8,12 +8,14 @@ import LimitPickers from "@/components/input/LimitPickers";
|
|
|
import Modal from "@/components/layout/Modal";
|
|
import Modal from "@/components/layout/Modal";
|
|
|
import { ColorType } from "@/context/themes/color";
|
|
import { ColorType } from "@/context/themes/color";
|
|
|
import { useSelector } from "react-redux";
|
|
import { useSelector } from "react-redux";
|
|
|
|
|
+import PickerViews from "@/components/input/PickerViews";
|
|
|
|
|
|
|
|
-export default function Component(props: { data: any, delete: Function, preview: Function }) {
|
|
|
|
|
|
|
+export default function Component(props: { data: any, index: number, delete: Function, preview: Function, update: Function }) {
|
|
|
const common = useSelector((state: any) => state.common);
|
|
const common = useSelector((state: any) => state.common);
|
|
|
const [detail, setDetail] = useState(props.data)
|
|
const [detail, setDetail] = useState(props.data)
|
|
|
const [count, setCount] = useState(0)
|
|
const [count, setCount] = useState(0)
|
|
|
const [showModal, setShowModal] = useState(false)
|
|
const [showModal, setShowModal] = useState(false)
|
|
|
|
|
+ const [showTagModal, setShowTagModal] = useState(false)
|
|
|
const [isStart, setIsStart] = useState(false)
|
|
const [isStart, setIsStart] = useState(false)
|
|
|
const { t } = useTranslation()
|
|
const { t } = useTranslation()
|
|
|
|
|
|
|
@@ -31,7 +33,7 @@ export default function Component(props: { data: any, delete: Function, preview:
|
|
|
|
|
|
|
|
function showActionSheet() {
|
|
function showActionSheet() {
|
|
|
Taro.showActionSheet({
|
|
Taro.showActionSheet({
|
|
|
- itemList: [t('feature.common.action_sheet.delete'), '餐前时间', '餐后时间']
|
|
|
|
|
|
|
+ itemList: [t('feature.common.action_sheet.delete')]
|
|
|
})
|
|
})
|
|
|
.then(res => {
|
|
.then(res => {
|
|
|
switch (res.tapIndex) {
|
|
switch (res.tapIndex) {
|
|
@@ -46,14 +48,35 @@ export default function Component(props: { data: any, delete: Function, preview:
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
break;
|
|
break;
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch(err => {
|
|
|
|
|
+ console.log(err.errMsg)
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function operateActionSheet() {
|
|
|
|
|
+ Taro.showActionSheet({
|
|
|
|
|
+ alertText: t('feature.food.action_sheet.title'),
|
|
|
|
|
+ itemList: [t('feature.food.action_sheet.tag'),
|
|
|
|
|
+ t('feature.food.action_sheet.start_time'),
|
|
|
|
|
+ t('feature.food.action_sheet.end_time')]
|
|
|
|
|
+ })
|
|
|
|
|
+ .then(res => {
|
|
|
|
|
+ switch (res.tapIndex) {
|
|
|
|
|
+ case 0:
|
|
|
|
|
+ setShowTagModal(true)
|
|
|
|
|
+ break;
|
|
|
case 1:
|
|
case 1:
|
|
|
{
|
|
{
|
|
|
|
|
+ global.set_time = new Date().getTime()
|
|
|
setIsStart(true)
|
|
setIsStart(true)
|
|
|
setShowModal(true)
|
|
setShowModal(true)
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
case 2:
|
|
case 2:
|
|
|
{
|
|
{
|
|
|
|
|
+ global.set_time = new Date().getTime()
|
|
|
setIsStart(false)
|
|
setIsStart(false)
|
|
|
setShowModal(true)
|
|
setShowModal(true)
|
|
|
}
|
|
}
|
|
@@ -80,6 +103,8 @@ export default function Component(props: { data: any, delete: Function, preview:
|
|
|
}
|
|
}
|
|
|
setDetail(obj)
|
|
setDetail(obj)
|
|
|
setCount(count + 1)
|
|
setCount(count + 1)
|
|
|
|
|
+
|
|
|
|
|
+ props.update(res)
|
|
|
}).catch(e => {
|
|
}).catch(e => {
|
|
|
|
|
|
|
|
})
|
|
})
|
|
@@ -111,6 +136,7 @@ export default function Component(props: { data: any, delete: Function, preview:
|
|
|
}, detail.id).then(res => {
|
|
}, detail.id).then(res => {
|
|
|
setDetail(res)
|
|
setDetail(res)
|
|
|
setCount(count + 1)
|
|
setCount(count + 1)
|
|
|
|
|
+ props.update(res)
|
|
|
}).catch(e => {
|
|
}).catch(e => {
|
|
|
|
|
|
|
|
})
|
|
})
|
|
@@ -123,18 +149,63 @@ export default function Component(props: { data: any, delete: Function, preview:
|
|
|
return (hour < 10 ? '0' + hour : hour) + ':' + (minute < 10 ? '0' + minute : minute)
|
|
return (hour < 10 ? '0' + hour : hour) + ':' + (minute < 10 ? '0' + minute : minute)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ function pickerTagIndex() {
|
|
|
|
|
+ var list = common.meal_tags
|
|
|
|
|
+ if (detail.meal_tag) {
|
|
|
|
|
+ for (var i = 0; i < list.length; i++) {
|
|
|
|
|
+ if (list[i].label == detail.meal_tag.label) {
|
|
|
|
|
+ return i;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function pickerTagItems() {
|
|
|
|
|
+ var list = common.meal_tags
|
|
|
|
|
+ var tags: any = []
|
|
|
|
|
+ list.map(item => {
|
|
|
|
|
+ tags.push(item.label)
|
|
|
|
|
+ })
|
|
|
|
|
+ return [tags];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function tagChanged(data) {
|
|
|
|
|
+ setShowTagModal(false)
|
|
|
|
|
+ updateTag(data[0])
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function getPickerLimit() {
|
|
|
|
|
+ if (isStart) {
|
|
|
|
|
+ return new Date().getTime() - 7 * 24 * 3600 * 1000
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ return detail.start.timestamp
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function getPickerInitValue() {
|
|
|
|
|
+ if (isStart) {
|
|
|
|
|
+ return detail.start.timestamp
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ return detail.end.timestamp ? detail.end.timestamp : new Date().getTime()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return <View className="food_timeline_item" onLongPress={showActionSheet}>
|
|
return <View className="food_timeline_item" onLongPress={showActionSheet}>
|
|
|
{/* <View className="thumb" style={{backgroundColor:'pink'}}/> */}
|
|
{/* <View className="thumb" style={{backgroundColor:'pink'}}/> */}
|
|
|
<View className="tags">
|
|
<View className="tags">
|
|
|
{
|
|
{
|
|
|
- common.meal_tags.map((item, index) => {
|
|
|
|
|
|
|
+ props.index == 0 && !detail.meal_tag && common.meal_tags.map((item, index) => {
|
|
|
return <Text onClick={() => updateTag(index)}>{item.label}</Text>
|
|
return <Text onClick={() => updateTag(index)}>{item.label}</Text>
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
</View>
|
|
</View>
|
|
|
<View className="thumb_bg">
|
|
<View className="thumb_bg">
|
|
|
<Image className="thumb" src={detail.cover} mode="aspectFill" onClick={preview} />
|
|
<Image className="thumb" src={detail.cover} mode="aspectFill" onClick={preview} />
|
|
|
- <View className="food_desc">
|
|
|
|
|
|
|
+ <View className="food_desc" onClick={operateActionSheet}>
|
|
|
<Text>{detail.meal_tag && detail.meal_tag.label}</Text>
|
|
<Text>{detail.meal_tag && detail.meal_tag.label}</Text>
|
|
|
<Text>{detail.start && getTime(detail.start.timestamp)} </Text>
|
|
<Text>{detail.start && getTime(detail.start.timestamp)} </Text>
|
|
|
{
|
|
{
|
|
@@ -147,10 +218,10 @@ export default function Component(props: { data: any, delete: Function, preview:
|
|
|
showModal && <Modal dismiss={() => { setShowModal(false) }} confirm={() => { setShowModal(false) }}>
|
|
showModal && <Modal dismiss={() => { setShowModal(false) }} confirm={() => { setShowModal(false) }}>
|
|
|
<View className='modal_content'>
|
|
<View className='modal_content'>
|
|
|
<LimitPickers
|
|
<LimitPickers
|
|
|
- isRealTime={true} time={new Date().getTime()} limit={new Date().getTime() - 120 * 24 * 3600 * 1000}
|
|
|
|
|
- title={isStart ? '餐前時間' : '餐後時間'}
|
|
|
|
|
- themeColor={ColorType.fast}
|
|
|
|
|
- limitDay={120} onCancel={() => { setShowModal(false) }}
|
|
|
|
|
|
|
+ isRealTime={true} time={getPickerInitValue()} limit={getPickerLimit()}
|
|
|
|
|
+ title={isStart ? t('feature.food.picker_start_title') : t('feature.food.picker_end_title')}
|
|
|
|
|
+ themeColor={ColorType.food}
|
|
|
|
|
+ limitDay={7} onCancel={() => { setShowModal(false) }}
|
|
|
onChange={(e) => {
|
|
onChange={(e) => {
|
|
|
updateTime(e)
|
|
updateTime(e)
|
|
|
setShowModal(false)
|
|
setShowModal(false)
|
|
@@ -158,6 +229,18 @@ export default function Component(props: { data: any, delete: Function, preview:
|
|
|
</View>
|
|
</View>
|
|
|
</Modal>
|
|
</Modal>
|
|
|
}
|
|
}
|
|
|
|
|
+ {
|
|
|
|
|
+ showTagModal && <Modal dismiss={() => { setShowTagModal(false) }} confirm={() => { setShowTagModal(false) }}>
|
|
|
|
|
+ <PickerViews title={t('feature.food.picker_tag_title')}
|
|
|
|
|
+ value={[pickerTagIndex()]}
|
|
|
|
|
+ items={pickerTagItems()}
|
|
|
|
|
+ onChange={(e) => { tagChanged(e) }}
|
|
|
|
|
+ onCancel={() => { setShowTagModal(false) }}
|
|
|
|
|
+ themeColor={ColorType.food}
|
|
|
|
|
+
|
|
|
|
|
+ />
|
|
|
|
|
+ </Modal>
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
</View>
|
|
</View>
|
|
|
}
|
|
}
|