import React, { Component } from "react"; import { Platform, StyleSheet, View, ScrollView, TouchableOpacity, Image, SafeAreaView, TextInput, Alert } from "react-native"; import { observable } from "mobx"; import Text from "react-native-text"; import { Button } from "react-native-elements"; 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 FastImage from "react-native-fast-image"; import Icon from "react-native-vector-icons/dist/MaterialCommunityIcons"; import Log from "../../config/log"; import Size from "../../config/size"; import { scale, verticalScale, moderateScale } from "react-native-size-matters"; import { Dropdown } from "react-native-material-dropdown"; import CommonTextView from "../../components/Public/commonTextView"; import theme from "../../config/colors"; import Loader from "../../components/Public/loader"; import { Popup } from "react-native-map-link"; import { Fonts } from "../../config/fonts"; import { colors } from "react-native-elements"; const size = new Size(); const log = new Log(); const time = [ { value: "12:10 - 12:40", format: "12101240" }, { value: "13:10 - 13:40", format: "13101340" }, { value: "14:10 - 14:40", format: "14101440" } ]; @inject(["menuStore"], ["userStore"]) @observer export default class ConfirmOrder extends Component { @observable message = ""; @observable tel = "1234556"; @observable pomoCode = ""; @observable total = 0; @observable discount = 0; @observable subVaule = 0; @observable options = { latitude: 38.8976763, longitude: -77.0387185, title: "", dialogTitle: "Select the map", dialogMessage: "", cancelText: "Cancel" }; timeIndex = null; couponLabel = []; static navigationOptions = { drawerLabel: "My Orders" }; constructor(props) { super(props); this.store = this.props.menuStore; this.userStore = this.props.userStore; this.state = { isVisible: false }; } componentDidMount() { log.firebaseClass("ConfirmOrder"); this.total = this.store.totalMoney.toFixed(2); this.tel = this.userStore.userData.data.member.mobile; console.log(this.store.couponLabel); } navigatieAction(page) { this.props.navigation.navigate(page); } renderFoodsList() { return this.store.orderList.map(items => { console.log(items.cuisine.nameEn); return ( ); }); } dateFormat() { var cutoffDate = this.store.cutoffDateTime; console.log(this.store.cutoffDateTime); var today = new Date(); var tomorrowOrToday = ""; if (today.getUTCDate() == cutoffDate.getUTCDate()) { var tomorrowOrToday = "(Today)"; } var options = { weekday: "long", year: "numeric", month: "long", day: "numeric" }; return cutoffDate.toLocaleDateString("En", options) + tomorrowOrToday; } discountText() { if (this.discount > 0) { return ( Discount {this.discount + "%" + " off"} ); } else if (this.subVaule > 0) { return ( Total {"- " + this.subVaule} ); } } orderAction() { var today = new Date(); yymmdd = today.getFullYear() + "-" + ("0" + (today.getMonth() + 1)).slice(-2) + "-" + ("0" + (today.getDay() + 1)).slice(-2); console.log(yymmdd); var token = this.userStore.userData.data.token; console.log(token); var orderData = { pickUpLocation: { id: this.userStore.pickupPointId }, // "pickUpDate": yymmdd, // "pickUpTime": time[this.timeIndex].format, items: this.store.items, coupon: this.pomoCode, mobile: this.tel, remark: this.message }; console.log(orderData); this.store.order(token, orderData, this); } onChangeText(text) { this.pomoCode = text; this.pressYeahButton(); } pay() { this.store.loading = false; Alert.alert("", "Pay now? ", [ { text: "Cancel", onPress: () => { log.firebaseLog("press_cancel_button_on_confirmOrder", {}), this.store.cancelOrder(this.userStore.userData.data.token); } }, { text: "Pay", onPress: () => { log.firebaseLog("press_pay_button_on_confirmOrder", {}), this.store.pay( this.userStore.userData.data.token, this, this.userStore.creditCardinfo.id ); } } ]); } // type 0 all user can use, type 1 all user can use once discountAction(data) { if (data.value == 0) { this.discount = data.percent; if (this.discount == null || this.discount == 0) { this.total = this.store.totalMoney.toFixed(2); } else { var total = (this.store.totalMoney * (100 - this.discount)) / 100; this.total = total.toFixed(2); } } else { this.subVaule = data.value; if (this.subVaule == null || this.subVaule == 0) { this.total = this.store.totalMoney.toFixed(2); } else { var total = this.store.totalMoney - this.subVaule; this.total = total.toFixed(2); } } } pressYeahButton() { log.firebaseLog("press_yeah_button_on_confirmOrder", {}), this.store.coupon( this.userStore.userData.data.token, this, this.pomoCode ); this.subVaule = 0; this.discount = 0; } back() { this.props.navigation.goBack(); } render() { return ( this.back()} /> {this.renderFoodsList()} (this.pomoCode = text)} placeholder={"Promo Code"} placeholderStyle={{ fontWeight: "bold", fontFamily: Fonts.century }} placeholderTextColor={theme.coolGrey} /> { this.onChangeText(text); }} data={this.store.couponLabel} fontSize={12} /> { this.pressYeahButton(); }} > Yeah {this.discountText()} TOTAL HKD ${this.total} Delivery Details { this.options.latitude = this.userStore.pickupPointLabel[ this.userStore.pickupIndex ].lat; this.options.longitude = this.userStore.pickupPointLabel[ this.userStore.pickupIndex ].lng; this.setState({ isVisible: true }); }} > Mobile phone (this.tel = tel)} /> Message box (this.message = text)} placeholder={"Tell me any requires"} placeholderStyle={{ fontWeight: "bold", fontFamily: Fonts.century }} placeholderTextColor={theme.foodNameColor} />