/* eslint-disable react/jsx-props-no-spreading */ /* eslint-disable no-underscore-dangle */ import * as WebBrowser from 'expo-web-browser'; import * as React from 'react'; import { StyleSheet, View, Clipboard, Dimensions, Animated, PanResponder, findNodeHandle, UIManager, TouchableOpacity, } from 'react-native'; import { Div, Button, Image, Text } from 'react-native-magnus'; import { Appbar, Menu } from 'react-native-paper'; import Constants from 'expo-constants'; import { Flex } from '@ant-design/react-native'; import { ScrollView } from 'react-native-gesture-handler'; import { useRequest, useCreation, useMount } from '@umijs/hooks'; import { useTranslation } from 'react-i18next'; import { useRoute } from '@react-navigation/native'; import { useAnimation } from 'react-native-animation-hooks'; import useModel from 'flooks'; import Toast from '../../flooks/Toast'; import Header from './Header'; // 头部 import { connectKefu } from '../../Utils/TotastUtils'; import { merchantStatusMap, orderStatusMap, RiderStatusMap, payMap, reasonMap, getStatusInfo, } from '../../Utils/OrderUtils'; import Time from '../../Utils/TimeUtils'; import MapScreen from '../Map/MapScreen'; export default function OrderScreen({ navigation }) { const { t } = useTranslation(); const [orderInfo, setorderInfo] = React.useState({ merchant: {}, orderGoodsSpecs: [], }); const { loading, success, warnning, clearLoading } = useModel(Toast, []); const route = useRoute(); const { params } = route; const { orderId } = params || 0; const orderRequest = useRequest(`/orderInfo/get/${orderId}`, { refreshDeps: [orderId], onSuccess: (result) => { setorderInfo(result); }, }); const { merchant, orderGoodsSpecs } = orderInfo; const statusInfo = useCreation(() => { return getStatusInfo(orderInfo); }, [orderInfo]); const finish = useCreation(() => { if ( orderInfo.riderStatus === 'CARRY_OUT' || orderInfo.status === 'CANCELLED' ) { return true; } else { return false; } }, [orderInfo]); const cancelOrder = useCreation(() => { if (orderInfo.status === 'CANCELLED') { return true; } else { return false; } }, [orderInfo, statusInfo]); const Allfinish = useCreation(() => { if (orderInfo.status === 'COMPLETED') { return true; } else { return false; } }, [orderInfo]); const isPay = useCreation(() => { if (orderInfo.status === 'UNPAID') { return false; } else { return true; } }, [orderInfo]); const hasRider = useCreation(() => { if (orderInfo.riderStatus !== 'NOT_RECEIVED' && orderInfo.riderStatus) { return true; } else { return false; } }); const detailRef = React.useRef(); const pan = React.useRef(new Animated.ValueXY()).current; const minMove = React.useRef(new Animated.Value(0)).current; const maxMove = React.useRef( new Animated.Value(Dimensions.get('window').height * 0.6) ).current; const panResponder = React.useRef( PanResponder.create({ onMoveShouldSetPanResponder: () => { console.log('a2'); return false; }, onMoveShouldSetPanResponderCapture: () => false, onStartShouldSetPanResponder: () => { console.log('a1'); return true; }, onStartShouldSetPanResponderCapture: () => false, onResponderTerminationRequest: () => true, onPanResponderGrant: () => { pan.setOffset({ y: pan.y._value, }); }, onPanResponderMove: (e, ges) => { const y = ges.dy + pan.y._offset; if (y >= minMove._value && y <= maxMove._value) { pan.setValue({ y: ges.dy, }); } else if (y < minMove._value) { pan.setValue({ y: minMove._value - pan.y._offset, }); } else { pan.setValue({ y: maxMove._value - pan.y._offset, }); if (ges.moveY > 500) { orderRequest.run(); } } if (maxMove._value !== 0) { if (maxMove._value - y < 200) { setbackgorundColor( `rgba(255, 194, 28,${Math.ceil( (1 / 200) * (maxMove._value - y) )})` ); setshowDetail(false); } else { setbackgorundColor('#FFC21C'); setshowDetail(true); } } }, onPanResponderRelease: () => { pan.flattenOffset(); }, }) ).current; React.useEffect(() => { if (finish || statusInfo.isRefund) { maxMove.setValue(0); pan.setValue({ y: 0, }); setshowDetail(true); setbackgorundColor('#FFC21C'); } else { maxMove.setValue(Dimensions.get('window').height * 0.6); pan.setValue({ y: Dimensions.get('window').height * 0.6, }); setshowDetail(false); } }, [finish, statusInfo]); const [backgorundColor, setbackgorundColor] = React.useState( 'rgba(255, 194, 28,0)' ); const [showDetail, setshowDetail] = React.useState(false); React.useEffect(() => { if (orderRequest.loading) { loading(); } else { clearLoading(); } }, [orderRequest.loading]); return (
{/* */} {!finish && !statusInfo.isRefund && (
)} { minMove.setValue( Dimensions.get('window').height - nativeEvent.layout.height - nativeEvent.layout.y - Constants.statusBarHeight ); }} >
{/* {statusInfo.name} */} {/* */} {!finish && hasRider && ( )} {!finish && isPay && !statusInfo.isRefund && !cancelOrder && ( )} {finish && !cancelOrder && !statusInfo.isRefund && ( )} {finish && !Allfinish && !cancelOrder && !statusInfo.isRefund && ( )}
{orderInfo.merShowName}
{orderGoodsSpecs.map((item) => { return ( ); })}
{t('bao-zhuang-fei')} {t('can-he')} ¥{orderInfo.packingPrice} {t('pei-song-fei-ding-dong-zhuan-song')} ¥{orderInfo.deliveryAmount} {t('man-jian')} -¥{orderInfo.fullReduction} {!!orderInfo.firstBuy && ( {t('shou-dan')} ¥{orderInfo.firstBuy} )} {t('hong-bao')} -¥{orderInfo.redBag || 0} {t('xiao-ji')} ¥{orderInfo.realAmount}
{t('ding-dan-xin-xi')} {t('xia-dan-shi-jian')} {orderInfo.orderTime} {orderInfo.userReceivedTime ? ( {t('song-da-shi-jian')} {orderInfo.userReceivedTime} ) : ( {t('yu-ji-song-da-shi-jian')} {orderInfo.timeOfArrival} )} {t('shou-huo-di-zhi')} {orderInfo.userAddress} {hasRider && ( {t('pei-song-qi-shou')} {orderInfo.riderName} )} {t('ding-dan-hao')} {orderInfo.id} {payMap.has(orderInfo.payMethod) && ( {t('zhi-fu-fang-shi')} {payMap.get(orderInfo.payMethod).name} )} {/* */} ); } const GoodsItem = ({ info, goods }) => { return (
{goods.name} X {info.num} ¥{info.goodsRealPrice}
{info.specification}
); }; const styles = StyleSheet.create({ scroll: { flexGrow: 1, }, card: { borderRadius: 3, backgroundColor: '#fff', marginBottom: 5, padding: 15, }, item: { paddingVertical: 5, }, icon: { width: 33, height: 33, borderRadius: 3, }, goodsMain: { marginLeft: 10, }, type: { // marginTop:3, }, main: { marginTop: 10, paddingVertical: 5, borderColor: '#E5E5E5', borderTopWidth: 1, }, info: { marginTop: 10, }, total: { paddingTop: 10, marginTop: 10, borderColor: '#E5E5E5', borderTopWidth: 1, }, address: { minWidth: 50, marginRight: 30, }, info2: { marginTop: 10, }, });