import React, { Component } from "react"; import { Platform, StyleSheet, View, ScrollView, TouchableOpacity, ActivityIndicator, Alert, SafeAreaView } from "react-native"; import { observable } from "mobx"; import { Button } from "react-native-elements"; import Text from "react-native-text"; import { observer, inject } from "mobx-react/native"; import Header from "../../components/Public/header"; import Toast, { DURATION } from "react-native-easy-toast"; import { width, height } from "../../config/screen"; import FoodsRow from "../../components/MyOrders/foodsRow"; import moment from "moment"; import FoodsRowForOrderDetails from "../../components/MyOrders/foodsRowForOrderDetails"; import Icon from "react-native-vector-icons/dist/MaterialCommunityIcons"; import { scale, verticalScale, moderateScale } from "react-native-size-matters"; import { Dropdown } from "react-native-material-dropdown"; import FastImage from "react-native-fast-image"; import { Popup } from "react-native-map-link"; import theme from "../../config/colors"; import { Fonts } from "../../config/fonts"; import CommonTextView from "../../components/Public/commonTextView"; import Size from "../../config/size"; const size = new Size(); @inject(["menuStore"], ["userStore"]) @observer export default class OrderDetails extends Component { @observable buttonColor = theme.mainColor; @observable buttonDisabled = false; @observable options = { latitude: 38.8976763, longitude: -77.0387185, title: "", dialogTitle: "Select the map", dialogMessage: "", cancelText: "Cancel" }; timeIndex = null; data = {}; static navigationOptions = { drawerLabel: "My Orders" }; constructor(props) { super(props); this.store = this.props.menuStore; this.userStore = this.props.userStore; this.state = { isVisible: false }; } componentWillMount() { const { navigation } = this.props; this.data = navigation.getParam("data", {}); this.time = navigation.getParam("time", {}); //console.log(this.data+" "+this.time); this.options.latitude = this.data.pickUpLocation.lat; this.options.longitude = this.data.pickUpLocation.lng; this.options.title = this.data.pickUpLocation.name; this.canCancelOrNot(); } navigatieAction(page) { this.props.navigation.navigate(page); } dateFormat() { var momentDate = moment(this.data.items[0].pickupEnd); var timestamp = momentDate.toDate(); var options = { weekday: "long", year: "numeric", month: "long", day: "numeric" }; return timestamp.toLocaleDateString("En", options); } pickupTime(){ var pickupTimeStartString = this.data.items[0].pickupStart.substring(11,16) var pickupTimeEndString = this.data.items[0].pickupEnd.substring(11,16) return pickupTimeStartString + " - " + pickupTimeEndString } canCancelOrNot() { if (this.data.status != "D") { if (this.time) { this.buttonColor = theme.inputBgc; this.buttonDisabled = true; } else { console.log('this') this.buttonColor = theme.mainColor; this.buttonDisabled = false; } } else { this.buttonColor = theme.inputBgc; this.buttonDisabled = true; } } renderFoodsList() { return this.data.items.map(items => { return ( ); }); } back() { this.props.navigation.goBack(); } goLocationAction() { this.props.navigation.navigate("Location", { location: { latitude: this.data.pickUpLocation.lat, longitude: this.data.pickUpLocation.lng } }); } discountText() { if (this.data.discount > 0) { return ( {"- "+this.data.discount} ); } } cancelAction() {} cancelOrderAlert() { Alert.alert("", "Are you sure to cancel this order?", [ { text: "Cancel", onPress: () => console.log("Cancel") }, { text: "Cancel order", onPress: () => this.cancelOrder() } ]); } cancelOrder() { var token = this.userStore.userData.data.token; this.store.voidOrder(token, this.data.id, this); } render() { return ( this.back()} /> {this.renderFoodsList()} {this.discountText()} TOTAL HKD ${this.data.payAmount.toFixed(2)} Delivery Details { this.setState({ isVisible: true }); }} > Mobile phone {this.data.mobile} Message box {this.data.remark}