| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504 |
- import { StackScreenProps } from '@react-navigation/stack';
- import * as React from 'react';
- import { Div, Button, Image, Text, Avatar, Icon } from 'react-native-magnus';
- import { Menu } from 'teaset';
- import { ScrollView } from 'react-native-gesture-handler';
- import { useRequest, useCreation, useMount } from 'ahooks';
- import { RefreshControl, Dimensions } from 'react-native';
- import { toastInfo, toastSuccess, alert } from '../utils/SystemUtils';
- import { RiderStatusMap } from '../utils/RiderInfoUtils';
- import ImagePicker from '../components/ImagePicker';
- import { useTranslation } from 'react-i18next';
- import useModel from 'flooks';
- import OrderModel from './model';
- import { useSafeArea } from 'react-native-safe-area-context';
- import { changeCord, goMap } from '../utils/MapUtils';
- import { connect } from '../utils/SystemUtils';
- import Request from '../utils/RequestUtils';
- function RightMenuItem({ text = '' }) {
- return (
- <Text fontSize="sm" color="black">
- {text}
- </Text>
- );
- }
- export default function OrderDetailScreen({
- navigation,
- route,
- }: StackScreenProps) {
- const { t } = useTranslation();
- const { params } = route;
- const { orderId } = params;
- const [pickImg, setpickImg] = React.useState<string>('');
- const { receiverOrder, changeStatus, changeStatusAll } = useModel(
- OrderModel,
- []
- );
- navigation.setOptions({
- headerRight: (props) => (
- <Button
- bg="none"
- px={15}
- py={0}
- w={50}
- h={50}
- onPress={() => {
- const x = Dimensions.get('window').width - 80,
- y = 0,
- width = 50,
- height = 50;
- let items = [
- {
- title: '联系客服',
- onPress: () => connect(navigation),
- },
- ];
- if (!isRefund && statusInfo.type && statusInfo.type !== 'order') {
- items.splice(0, 0, {
- title: '取消订单申请',
- onPress: () => {
- navigation.navigate('Modal', {
- screen: 'Applay',
- params: {
- orderId,
- },
- });
- },
- });
- }
- Menu.show({ x, y, width, height }, items, {
- popoverStyle: {
- backgroundColor: '#fff',
- },
- });
- }}
- >
- <Icon
- name="more-horizontal"
- color="white"
- fontFamily="Feather"
- fontSize="lg"
- ></Icon>
- </Button>
- ),
- });
- const { data, loading, reload, run } = useRequest(
- `/orderInfo/get/${orderId}`,
- {
- manual: true,
- defaultLoading: false,
- debounceInterval: 1000,
- initialData: {},
- }
- );
- useMount(() => {
- run();
- });
- const orderGoodsSpecs = useCreation(() => {
- return data.orderGoodsSpecs || [];
- }, [data]);
- const statusInfo = useCreation(() => {
- if (data.riderStatus) {
- return RiderStatusMap.get(data.riderStatus);
- } else {
- return {};
- }
- }, [data]);
- const totalNum = useCreation(() => {
- return orderGoodsSpecs.reduce((total, currentValue) => {
- return total + currentValue.num;
- }, 0);
- }, [orderGoodsSpecs]);
- const isRefund = useCreation(() => {
- if (data.status === 'REFUNDED_PENDING') {
- return true;
- } else {
- return false;
- }
- }, [data]);
- function orderChange() {
- alert(navigation, {
- msg: statusInfo.infoText,
- hasCancel: true,
- dangers: true,
- submitEvent: () => {
- changeStatus(
- data.id,
- statusInfo.nextStatus,
- (res) => {
- toastSuccess(statusInfo.successText);
- },
- () => {
- alert(navigation, {
- msg: statusInfo.errorText,
- hasCancel: true,
- dangers: true,
- submitEvent: () => {
- changeStatusAll(data.id, statusInfo.nextStatus, (res) => {
- toastSuccess(statusInfo.successText);
- run();
- });
- },
- });
- },
- pickImg
- );
- },
- });
- }
- return (
- <Div bg="gray100" flex={1}>
- {/* <ModalDropdown ref={menu} options={['option 1', 'option 2']} /> */}
- {statusInfo.type && statusInfo.type !== 'order' && (
- <Div row bg="white" py={12}>
- {__DEV__ &&
- !isRefund &&
- statusInfo.type &&
- statusInfo.type !== 'order' && (
- <Button
- onPress={() => {
- navigation.navigate('Modal', {
- screen: 'Applay',
- params: {
- orderId,
- },
- });
- }}
- >
- 取消订单
- </Button>
- )}
- <Div flex={1} alignItems="center">
- <Text fontSize="xl" color="red500">
- {data.deliveryAmount}
- </Text>
- <Text fontSize="sm" color="gray600">
- {t('ben-dan-pai-song-shou-ru')}
- </Text>
- </Div>
- <Div w={1} bg="gray100" />
- {statusInfo.type === 'finish' ? (
- <Div flex={1} alignItems="center">
- <Text fontSize="xl" color="red500">
- {data.userReceivedTime}
- </Text>
- <Text fontSize="sm" color="gray600">
- {t('yong-hu-shou-dao-shi-jian')}
- </Text>
- </Div>
- ) : (
- <Div flex={1} alignItems="center">
- <Text fontSize="xl" color="red500">
- {data.timeOfArrival}
- </Text>
- <Text fontSize="sm" color="gray600">
- {t('yu-ji-song-da-shi-jian')}
- </Text>
- </Div>
- )}
- </Div>
- )}
- <ScrollView
- contentContainerStyle={{
- flexGrow: 1,
- backgroundColor: '#f2f2f2',
- paddingHorizontal: 15,
- paddingVertical: 10,
- }}
- refreshControl={
- <RefreshControl refreshing={loading} onRefresh={reload} />
- }
- >
- {statusInfo.type && (
- <>
- <Div bg="white" rounded="xs" px={15} py={10}>
- {statusInfo.type == 'user' && (
- <Div row py={10}>
- <Div flex={1}>
- <Text fontSize="xl" fontWeight="bold" color="yellow500">
- {statusInfo.name}
- </Text>
- <Text fontSize="sm" color="gray600" mt={2}>
- {t('liu-shui-hao')}:{data.id}
- </Text>
- </Div>
- <Button bg="yellow500" w={112} onPress={orderChange}>
- {t('que-ren-song-da')}
- </Button>
- </Div>
- )}
- {statusInfo.type === 'merchant' && (
- <>
- <Div row py={10}>
- <Div flex={1}>
- <Text>{t('wo-yi-dao-dian')}</Text>
- <Text fontSize="sm" color="gray600" mt={2}>
- {t('liu-shui-hao')}:{data.id}
- </Text>
- </Div>
- <Button
- bg="yellow500"
- w={112}
- disabled={statusInfo.status != 0}
- onPress={orderChange}
- >
- {t('wo-yi-dao-dian')}
- </Button>
- </Div>
- {statusInfo.status === 1 && (
- <>
- <Div row py={10}>
- <Div flex={1}>
- <Text>{t('wo-yi-qu-huo')}</Text>
- <Text fontSize="sm" color="gray600" mt={2} pr={48}>
- {t('ordertips')}
- </Text>
- </Div>
- <Button bg="yellow500" w={112} onPress={orderChange}>
- {t('pai-zhao-qu-huo')}
- </Button>
- </Div>
- <ImagePicker
- img={pickImg}
- setImg={(img) => setpickImg(img)}
- />
- </>
- )}
- </>
- )}
- {(statusInfo.type === 'user' || statusInfo.type === 'finish') && (
- <Div py={10}>
- <Text fontSize="sm">{t('yong-hu-xin-xi')}</Text>
- <Div px={10} mt={10}>
- <Text fontSize="xl" fontWeight="bold">
- {data.nickname}
- </Text>
- <Text fontSize="sm" mt={5}>
- {data.userAddress}
- </Text>
- </Div>
- <Button
- block
- bg="yellow500"
- mt={15}
- onPress={() => {
- if (!data.userId) {
- toastInfo('该订单缺少用户id,请重新下单');
- return;
- }
- navigation.navigate('NoticeStack', {
- screen: 'Chat',
- params: {
- toUserId: data.userId,
- toUserName: data.nickname,
- },
- });
- }}
- >
- {t('lian-xi-ke-hu')}
- </Button>
- </Div>
- )}
- {(statusInfo.type === 'merchant' ||
- statusInfo.type === 'finish') && (
- <Div borderTopColor="gray100" borderTopWidth={1} py={10}>
- <Text fontSize="sm">{t('shang-jia-xin-xi')}</Text>
- <Div px={10} mt={10}>
- <Text fontSize="xl" fontWeight="bold">
- {data.merShowName}
- </Text>
- <Text fontSize="sm" mt={5}>
- {data.merAddress}
- </Text>
- </Div>
- <Button
- block
- bg="yellow500"
- mt={15}
- onPress={() => {
- if (!data.muserId) {
- toastInfo('该订单缺少商家id,请重新下单');
- return;
- }
- navigation.navigate('NoticeStack', {
- screen: 'Chat',
- params: {
- toUserId: data.muserId,
- toUserName: data.merShowName,
- },
- });
- }}
- >
- {t('lian-xi-shang-jia')}
- </Button>
- </Div>
- )}
- {statusInfo.type === 'order' && (
- <Div py={15}>
- <Div row mt={10}>
- <Text fontSize="sm" color="gray600">
- 1.5Km
- </Text>
- <Div flex={1} ml={12}>
- <Text fontSize="md" pb={3}>
- {data.merShowName}
- </Text>
- <Text fontSize="sm">{data.merAddress}</Text>
- </Div>
- </Div>
- <Div row mt={10}>
- <Text fontSize="sm" color="gray600">
- 1.5Km
- </Text>
- <Div flex={1} ml={12}>
- {data.nickName && (
- <Text fontSize="md" pb={5}>
- {data.nickName}
- </Text>
- )}
- <Text fontSize="sm">{data.userAddress}</Text>
- </Div>
- </Div>
- </Div>
- )}
- <Div borderTopColor="gray100" borderTopWidth={1} py={10}>
- <Div row>
- <Text fontSize="sm" flex={2}>
- {t('shang-pin-xin-xi')}
- </Text>
- <Text fontSize="sm" flex={1} textAlign="right">
- {totalNum}
- {t('fen')}
- </Text>
- <Text fontSize="sm" flex={1} color="red500" textAlign="right">
- ¥{data.realAmount || 0}
- </Text>
- </Div>
- <Div p={15}>
- {orderGoodsSpecs.map((item) => {
- const goods = item.goods;
- return (
- <Div row key={item.id} mt={5}>
- <Text fontSize="sm"> {goods.name}</Text>
- <Text fontSize="sm" color="gray500" ml={5}>
- {item.specification}
- </Text>
- <Text fontSize="sm" flex={1} textAlign="right">
- X {item.num}
- </Text>
- </Div>
- );
- })}
- </Div>
- </Div>
- {statusInfo.type === 'order' && (
- <Button
- bg="yellow500"
- w={112}
- alignSelf="flex-end"
- my={10}
- onPress={() => {
- receiverOrder(data.id, (res) => {
- toastSuccess(t('jie-dan-cheng-gong'));
- });
- }}
- >
- {t('jie-dan')}
- </Button>
- )}
- </Div>
- <Div h={35} w="100%" />
- {(statusInfo.type === 'merchant' || statusInfo.type === 'user') &&
- !isRefund && (
- <Div position="absolute" bottom={0} left={0} right={0}>
- <Button
- block
- mx={15}
- my={10}
- bg="yellow500"
- onPress={() => {
- goMap(
- statusInfo.type === 'merchant'
- ? data.merShowName
- : data.userAddress,
- statusInfo.type === 'merchant'
- ? changeCord(data.merLocation)
- : changeCord(data.location),
- navigation
- );
- }}
- >
- {t('cha-kan-dao-hang')}
- </Button>
- </Div>
- )}
- {isRefund && (
- <Div
- row
- position="absolute"
- bottom={0}
- left={0}
- right={0}
- px={15}
- py={10}
- >
- <Button flex={1} bg="gray300" disabled>
- 订单申请取消中
- </Button>
- <Button
- w={105}
- ml={5}
- bg="yellow500"
- onPress={() => {
- Request.get('/orderRefundApply/cancel', {
- params: {
- orderId,
- },
- })
- .then((res) => {
- toastSuccess('取消成功');
- })
- .catch((e) => {
- toastInfo(e.error);
- })
- .finally(() => {
- run();
- });
- }}
- >
- 撤销申请
- </Button>
- </Div>
- )}
- </>
- )}
- </ScrollView>
- </Div>
- );
- }
|