| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739 |
- /* 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,
- } 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(() => {
- const statusList = [];
- if (orderInfo.status) {
- statusList.push(orderStatusMap.get(orderInfo.status));
- }
- if (orderInfo.merchantStatus) {
- statusList.push(merchantStatusMap.get(orderInfo.merchantStatus));
- }
- if (orderInfo.riderStatus) {
- statusList.push(RiderStatusMap.get(orderInfo.riderStatus));
- }
- if (statusList.length > 0) {
- return statusList.sort((a, b) => {
- return b.sort - a.sort;
- })[0];
- } else {
- return {
- name: t('ding-dan-xiang-qing'),
- };
- }
- }, [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]);
- 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) {
- 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]);
- 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 (
- <Div bg="gray200" w="100%" flex={1}>
- <Header
- title={showDetail ? statusInfo.name : ' '}
- bg={backgorundColor}
- orderId={orderId}
- hasRight={!finish && !Allfinish && !cancelOrder}
- />
- {/* <RefreshControl
- refreshing={orderRequest.loading}
- onRefresh={orderRequest.run}
- > */}
- {!finish && (
- <Div
- w={Dimensions.get('window').width}
- h={Dimensions.get('window').height + Constants.statusBarHeight}
- position="absolute"
- top={0}
- left={0}
- zIndex={1}
- >
- <MapScreen orderInfo={orderInfo} />
- </Div>
- )}
- <Animated.View
- ref={detailRef}
- style={{
- zIndex: 2,
- backgroundColor: 'rgba(0,0,0,0)',
- transform: [{ translateY: pan.y }],
- }}
- onLayout={({ nativeEvent }) => {
- minMove.setValue(
- Dimensions.get('window').height -
- nativeEvent.layout.height -
- nativeEvent.layout.y -
- Constants.statusBarHeight
- );
- }}
- >
- <View {...panResponder.panHandlers}>
- <Div pt={10} pb={10} px={15}>
- <View style={[styles.card]}>
- {!cancelOrder &&
- (finish ? (
- <Text fontSize="xl">
- <Text
- fontSize="xl"
- color="brand500"
- mr={10}
- fontWeight="bold"
- >
- {statusInfo.name}
- </Text>
- {new Time(
- orderInfo.userReceivedTime,
- 'yyyy-MM-DD HH:mm:ss'
- ).getFormat('HH:mm')}
- {t('song-da')}
- </Text>
- ) : (
- <Text fontSize="xl">
- <Text
- fontSize="xl"
- color="brand500"
- mr={10}
- fontWeight="bold"
- >
- {statusInfo.name}
- </Text>
- {t('yu-ji')}
- {new Time(
- orderInfo.timeOfArrival,
- 'yyyy-MM-DD HH:mm:ss'
- ).getFormat('HH:mm')}
- {t('song-da')}
- </Text>
- ))}
- {cancelOrder && (
- <Div row>
- <Text
- fontSize="xl"
- color="brand500"
- mr={10}
- fontWeight="bold"
- >
- {statusInfo.name}
- </Text>
- {!!orderInfo.reason && (
- <Text fontSize="xl" color="red500">
- ({reasonMap.get(orderInfo.reason).name})
- </Text>
- )}
- </Div>
- )}
- <Div row mt={10}>
- <Button
- fontSize="xs"
- flex={1}
- mx={5}
- bg="white"
- color="gray600"
- borderColor="brand500"
- borderWidth={1}
- rounded={3}
- onPress={() => connectKefu(orderId)}
- >
- {t('lian-xi-ke-fu')}
- </Button>
- <Button
- fontSize="xs"
- flex={1}
- mx={5}
- bg="white"
- color="gray600"
- borderColor="brand500"
- borderWidth={1}
- rounded={3}
- onPress={() => connectKefu(orderId)}
- >
- 立即支付
- </Button>
- {!finish && hasRider && (
- <Button
- fontSize="xs"
- flex={1}
- mx={5}
- bg="white"
- color="gray600"
- borderColor="brand500"
- borderWidth={1}
- rounded={3}
- onPress={(e) => {
- if (!orderInfo.ruserId) {
- warnning('骑手信息有误请联系客服');
- } else {
- navigation.navigate('Chat', {
- toUserId: orderInfo.ruserId,
- toUserName: orderInfo.riderName,
- });
- }
- console.log(e);
- }}
- >
- {t('lian-xi-qi-shou')}
- </Button>
- )}
- {!finish && isPay && (
- <Button
- fontSize="xs"
- flex={1}
- mx={5}
- bg="white"
- color="gray600"
- borderColor="brand500"
- borderWidth={1}
- rounded={3}
- onPress={() => {
- if (!orderInfo.muserId) {
- warnning('商家信息有误请联系客服帮你催单');
- } else {
- navigation.navigate('Chat', {
- toUserId: orderInfo.muserId,
- toUserName: orderInfo.merShowName,
- type: 'Reminder',
- });
- }
- }}
- >
- {t('cui-dan')}
- </Button>
- )}
- {finish && !cancelOrder && (
- <Button
- fontSize="xs"
- flex={1}
- mx={5}
- bg="white"
- color="gray600"
- borderColor="brand500"
- borderWidth={1}
- rounded={3}
- onPress={() => {
- navigation.navigate('RewardRider', {
- orderId,
- });
- }}
- >
- {t('da-shang-qi-shou')}
- </Button>
- )}
- {finish && !Allfinish && !cancelOrder && (
- <Button
- fontSize="xs"
- flex={1}
- mx={5}
- bg="white"
- color="gray600"
- borderColor="brand500"
- borderWidth={1}
- rounded={3}
- onPress={() => {
- navigation.navigate('Evaluate', {
- orderId,
- });
- }}
- >
- {t('li-ji-ping-jia')}
- </Button>
- )}
- </Div>
- </View>
- <View style={[styles.card]}>
- <Div row pb={10}>
- <Text fontSize="xl" fontWeight="bold">
- {orderInfo.merShowName}
- </Text>
- <Button
- fontSize="xs"
- w={100}
- bg="white"
- color="gray600"
- borderColor="brand500"
- borderWidth={1}
- rounded={3}
- ml={14}
- onPress={() => {
- if (!orderInfo.muserId) {
- warnning('商家信息有误请联系客服帮你催单');
- } else {
- navigation.navigate('Chat', {
- toUserId: orderInfo.muserId,
- toUserName: orderInfo.merShowName,
- });
- }
- }}
- >
- {t('lian-xi-shang-jia')}
- </Button>
- </Div>
- <Div>
- {orderGoodsSpecs.map((item) => {
- return (
- <GoodsItem info={item} goods={item.goods} key={item.id} />
- );
- })}
- </Div>
- <Flex style={styles.info}>
- <Flex.Item>
- <Flex>
- <Text fontSize="xs" color="gray300" textAlign="left">
- {t('bao-zhuang-fei')}
- </Text>
- <Text fontSize="xs" color="gray300" textAlign="left">
- {t('can-he')}
- </Text>
- </Flex>
- </Flex.Item>
- <Text fontSize="xs" color="gray300" textAlign="left">
- ¥{orderInfo.packingPrice}
- </Text>
- </Flex>
- <Flex style={styles.info}>
- <Flex.Item>
- <Text fontSize="xs" color="gray300" textAlign="left">
- {t('pei-song-fei-ding-dong-zhuan-song')}
- </Text>
- </Flex.Item>
- <Text fontSize="xs" color="gray300" textAlign="left">
- ¥{orderInfo.deliveryAmount}
- </Text>
- </Flex>
- <Flex style={styles.info}>
- <Flex.Item>
- <Text fontSize="xs" color="gray300" textAlign="left">
- {t('man-jian')}
- </Text>
- </Flex.Item>
- <Text fontSize="xs" color="red500" textAlign="left">
- -¥{orderInfo.fullReduction}
- </Text>
- </Flex>
- {!!orderInfo.firstBuy && (
- <Flex style={styles.info}>
- <Flex.Item>
- <Text fontSize="xs" color="gray300" textAlign="left">
- {t('shou-dan')}
- </Text>
- </Flex.Item>
- <Text fontSize="xs" color="red500" textAlign="left">
- ¥{orderInfo.firstBuy}
- </Text>
- </Flex>
- )}
- <Flex style={styles.info}>
- <Flex.Item>
- <Text fontSize="xs" color="gray300" textAlign="left">
- {t('hong-bao')}
- </Text>
- </Flex.Item>
- <Text fontSize="xs" color="red500" textAlign="left">
- -¥{orderInfo.redBag || 0}
- </Text>
- </Flex>
- <Flex style={styles.total} justify="end">
- <Text size="s1">
- {t('xiao-ji')} ¥{orderInfo.realAmount}
- </Text>
- </Flex>
- </View>
- <View style={[styles.card]}>
- <Text size="c1">{t('ding-dan-xin-xi')}</Text>
- <View style={styles.main}>
- <Flex style={styles.info2}>
- <Flex.Item>
- <Text fontSize="xs" textAlign="left">
- {t('xia-dan-shi-jian')}
- </Text>
- </Flex.Item>
- <Text fontSize="xs" textAlign="left">
- {orderInfo.orderTime}
- </Text>
- </Flex>
- {orderInfo.userReceivedTime ? (
- <Flex style={styles.info2}>
- <Flex.Item>
- <Text fontSize="xs" textAlign="left">
- {t('song-da-shi-jian')}
- </Text>
- </Flex.Item>
- <Text fontSize="xs" textAlign="left">
- {orderInfo.userReceivedTime}
- </Text>
- </Flex>
- ) : (
- <Flex style={styles.info2}>
- <Flex.Item>
- <Text fontSize="xs" textAlign="left">
- {t('yu-ji-song-da-shi-jian')}
- </Text>
- </Flex.Item>
- <Text fontSize="xs" textAlign="left">
- {orderInfo.timeOfArrival}
- </Text>
- </Flex>
- )}
- <Flex style={styles.info2}>
- <Flex.Item style={styles.address}>
- <Text fontSize="xs" textAlign="left">
- {t('shou-huo-di-zhi')}
- </Text>
- </Flex.Item>
- <Text fontSize="xs" textAlign="left">
- {orderInfo.userAddress}
- </Text>
- </Flex>
- {hasRider && (
- <Flex style={styles.info2}>
- <Flex.Item>
- <Text fontSize="xs" textAlign="left">
- {t('pei-song-qi-shou')}
- </Text>
- </Flex.Item>
- <Flex>
- <Button
- fontSize="xs"
- w={100}
- bg="white"
- color="gray600"
- borderColor="brand500"
- borderWidth={1}
- rounded={3}
- onPress={() => {
- if (!orderInfo.muserId) {
- warnning('骑手信息有误请联系客服');
- } else {
- navigation.navigate('Chat', {
- toUserId: orderInfo.muserId,
- toUserName: orderInfo.merShowName,
- });
- }
- }}
- >
- {t('lian-xi-qi-shou')}
- </Button>
- <Text fontSize="xs" ml={20} textAlign="left">
- {orderInfo.riderName}
- </Text>
- </Flex>
- </Flex>
- )}
- <Flex style={styles.info2}>
- <Text fontSize="xs" textAlign="left">
- {t('ding-dan-hao')}
- </Text>
- <Text fontSize="xs" textAlign="right" ml={10} flex={1}>
- {orderInfo.id}
- </Text>
- <Button
- fontSize="xs"
- w={62}
- bg="white"
- color="gray600"
- borderColor="brand500"
- borderWidth={1}
- rounded={3}
- onPress={() => {
- Clipboard.setString(orderInfo.id.toString());
- success(t('fu-zhi-cheng-gong'));
- }}
- ml={5}
- >
- {t('fu-zhi')}
- </Button>
- </Flex>
- {payMap.has(orderInfo.payMethod) && (
- <Flex style={styles.info2}>
- <Text fontSize="xs" flex={1}>
- {t('zhi-fu-fang-shi')}
- </Text>
- <Text fontSize="xs" textAlign="left">
- {payMap.get(orderInfo.payMethod).name}
- </Text>
- </Flex>
- )}
- </View>
- </View>
- </Div>
- </View>
- </Animated.View>
- {/* </RefreshControl> */}
- </Div>
- );
- }
- const GoodsItem = ({ info, goods }) => {
- return (
- <Div row>
- <Image w={33} h={33} rounded={3} source={{ uri: goods.img }} />
- <Div flex={1} ml={10}>
- <Div row>
- <Text fontSize="sm" flex={1}>
- {goods.name}
- </Text>
- <Text fontSize="sm">X {info.num}</Text>
- <Text ml={10}>¥{info.goodsRealPrice}</Text>
- </Div>
- <Text fontSize="xs" color="gray400">
- {info.specification}
- </Text>
- </Div>
- </Div>
- );
- };
- 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,
- },
- });
|