//plugin
import React, { Component } from "react";
import Text from "react-native-text";
import {
StyleSheet,
View,
FlatList,
TouchableOpacity,
Image
} from "react-native";
import { observable, transaction } from "mobx";
import { width, height } from "../../config/screen";
import Icon from "react-native-vector-icons/dist/MaterialCommunityIcons";
import { observer, inject } from "mobx-react/native";
import FastImage from "react-native-fast-image";
import firebase from "react-native-firebase";
import Log from '../../config/log'
import { scale, verticalScale, moderateScale } from "react-native-size-matters";
// function
import Size from "../../config/size";
import theme from "../../config/colors";
import { Fonts } from "../../config/fonts";
var size = new Size();
var log = new Log();
@inject(["menuStore"], ["userStore"])
@observer
export default class ListItem extends Component {
@observable
soldout = false
constructor(props) {
super(props);
this.store = this.props.menuStore;
this.userStore = this.props.userStore;
}
recommended() {
return (
);
}
componentDidMount(){
if(this.props.items.quota - this.props.items.sold == 0){
this.soldout = true
}else{
this.soldout = false
}
}
foodAttributes() {
return (
);
}
add() {
if(!this.soldout){
this.store.addCount(this.props.items.id);
}
}
sum() {
if(!this.soldout){
this.store.sumCount(this.props.items.id);
}
}
onClickAction() {
transaction(() => {
this.store.menuDetails.id = this.props.items.id;
if (!this.userStore.logined) {
this.store.menuDetails.tel = "";
} else {
this.store.menuDetails.tel = this.userStore.userData.data.mobile;
}
this.store.menuDetails.count = this.props.items.count;
this.store.menuDetails.price = this.props.items.price;
this.store.menuDetails.imageURL = this.props.items.cuisine.photo;
this.store.menuDetails.name = this.props.items.cuisine.name;
this.store.menuDetails.nameEn = this.props.items.cuisine.nameEn;
this.store.menuDetails.tags = this.props.items.cuisine.tags;
this.store.menuDetails.intro_ch = this.props.items.cuisine.description;
this.store.menuDetails.intro_en = this.props.items.cuisine.descriptionEn;
this.store.menuDetails.restaurant.name = this.props.items.cuisine.restaurant.name;
this.store.menuDetails.restaurant.nameEn = this.props.items.cuisine.restaurant.nameEn;
this.store.menuDetails.restaurant.addr = this.props.items.cuisine.restaurant.addr;
this.store.menuDetails.restaurant.addrEn = this.props.items.cuisine.restaurant.addrEn;
});
this.props.menu.foodInformationPagePopUp();
// firebase.analytics().logEvent('click_food_details', { foodName: this.store.menuDetails.nameEn });
log.firebaseLog('click_food_details',{foodName: this.store.menuDetails.nameEn,logined: this.userStore.logined})
}
getViewStye() {
if(this.props.index == this.store.menu.data.content.length-1) {
return {
marginBottom: 80, alignItems: "center"
}
} else {
return {
marginBottom: 20, alignItems: "center"
}
}
}
render() {
var lang = this.userStore.languageSelection;
return (
this.onClickAction()}
>
HKD ${this.props.items.price}
{
this.soldout?(
Sold out
):(
)
}
{/*
{this.props.items.cuisine.description}
|| {this.props.items.cuisine.descriptionEn}
*/}
{this.userStore.dataLanguage(this.props.items.cuisine, "name")}
{this.userStore.dataLanguage(
this.props.items.cuisine.restaurant,
"name"
)}
this.sum()}
/>
{this.props.items.count}
this.add()}
/>
);
}
}