OrderDetailScreen.jsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import { StyleSheet, View, Clipboard, RefreshControl } from 'react-native';
  4. import { Div, Button, Image, Text } from 'react-native-magnus';
  5. import { Flex } from '@ant-design/react-native';
  6. import { ScrollView } from 'react-native-gesture-handler';
  7. import { useRequest, useCreation } from '@umijs/hooks';
  8. import { useRoute } from '@react-navigation/native';
  9. import useModel from 'flooks';
  10. import Toast from '../../flooks/Toast';
  11. import Header from './Header'; // 头部
  12. import { connectKefu } from '../../Utils/TotastUtils';
  13. import {
  14. merchantStatusMap,
  15. orderStatusMap,
  16. RiderStatusMap,
  17. payMap,
  18. } from '../../Utils/OrderUtils';
  19. import Time from '../../Utils/TimeUtils';
  20. export default function OrderScreen({ navigation }) {
  21. const [orderInfo, setorderInfo] = React.useState({
  22. merchant: {},
  23. orderGoodsSpecs: [],
  24. });
  25. const { success, warnning } = useModel(Toast, []);
  26. const route = useRoute();
  27. const { params } = route;
  28. const { orderId } = params || 0;
  29. const orderRequest = useRequest(`/orderInfo/get/${orderId}`, {
  30. refreshDeps: [orderId],
  31. onSuccess: (result) => {
  32. setorderInfo(result);
  33. },
  34. });
  35. const { merchant, orderGoodsSpecs } = orderInfo;
  36. const statusInfo = useCreation(() => {
  37. const statusList = [];
  38. if (orderInfo.status) {
  39. statusList.push(orderStatusMap.get(orderInfo.status));
  40. }
  41. if (orderInfo.merchantStatus) {
  42. statusList.push(merchantStatusMap.get(orderInfo.merchantStatus));
  43. }
  44. if (orderInfo.riderStatus) {
  45. statusList.push(RiderStatusMap.get(orderInfo.riderStatus));
  46. }
  47. if (statusList.length > 0) {
  48. return statusList.sort((a, b) => {
  49. return b.sort - a.sort;
  50. })[0];
  51. } else {
  52. return {
  53. name: '订单详情',
  54. };
  55. }
  56. }, [orderInfo]);
  57. const finish = useCreation(() => {
  58. if (orderInfo.riderStatus === 'CARRY_OUT') {
  59. return true;
  60. } else {
  61. return false;
  62. }
  63. }, [orderInfo]);
  64. const Allfinish = useCreation(() => {
  65. if (orderInfo.status === 'COMPLETED') {
  66. return true;
  67. } else {
  68. return false;
  69. }
  70. }, [orderInfo]);
  71. return (
  72. <>
  73. <Header title={statusInfo.name} />
  74. <ScrollView
  75. contentContainerStyle={styles.scroll}
  76. refreshControl={
  77. <RefreshControl
  78. refreshing={orderRequest.loading}
  79. onRefresh={orderRequest.run}
  80. />
  81. }
  82. >
  83. <View style={[styles.card]}>
  84. {finish ? (
  85. <Text fontSize="xl">
  86. <Text fontSize="xl" color="brand500" mr={10} fontWeight="bold">
  87. {statusInfo.name}
  88. </Text>
  89. {new Time(
  90. orderInfo.userReceivedTime,
  91. 'yyyy-MM-DD HH:mm:ss'
  92. ).getFormat('HH:mm')}
  93. 送达
  94. </Text>
  95. ) : (
  96. <Text fontSize="xl">
  97. <Text fontSize="xl" color="brand500" mr={10} fontWeight="bold">
  98. {statusInfo.name}
  99. </Text>
  100. 预计
  101. {new Time(
  102. orderInfo.timeOfArrival,
  103. 'yyyy-MM-DD HH:mm:ss'
  104. ).getFormat('HH:mm')}
  105. 送达
  106. </Text>
  107. )}
  108. <Div row mt={10}>
  109. <Button
  110. fontSize="xs"
  111. flex={1}
  112. mx={5}
  113. bg="white"
  114. color="gray600"
  115. borderColor="brand500"
  116. borderWidth={1}
  117. rounded={3}
  118. onPress={() => connectKefu(orderId)}
  119. >
  120. 联系客服
  121. </Button>
  122. {!finish && (
  123. <Button
  124. fontSize="xs"
  125. flex={1}
  126. mx={5}
  127. bg="white"
  128. color="gray600"
  129. borderColor="brand500"
  130. borderWidth={1}
  131. rounded={3}
  132. onPress={() => {
  133. warnning('正在帮您联系骑手');
  134. }}
  135. >
  136. 联系骑手
  137. </Button>
  138. )}
  139. {!finish && (
  140. <Button
  141. fontSize="xs"
  142. flex={1}
  143. mx={5}
  144. bg="white"
  145. color="gray600"
  146. borderColor="brand500"
  147. borderWidth={1}
  148. rounded={3}
  149. onPress={() => {
  150. warnning('正在帮您催单');
  151. }}
  152. >
  153. 催单
  154. </Button>
  155. )}
  156. {finish && !Allfinish && (
  157. <Button
  158. fontSize="xs"
  159. flex={1}
  160. mx={5}
  161. bg="white"
  162. color="gray600"
  163. borderColor="brand500"
  164. borderWidth={1}
  165. rounded={3}
  166. onPress={() => {
  167. navigation.navigate('Evaluate', {
  168. orderId,
  169. });
  170. }}
  171. >
  172. 立即评价
  173. </Button>
  174. )}
  175. {finish && (
  176. <Button
  177. fontSize="xs"
  178. flex={1}
  179. mx={5}
  180. bg="white"
  181. color="gray600"
  182. borderColor="brand500"
  183. borderWidth={1}
  184. rounded={3}
  185. onPress={() => {
  186. navigation.navigate('MerchantDetail', {
  187. merchantId: orderInfo.merchantId,
  188. });
  189. }}
  190. >
  191. 再来一单
  192. </Button>
  193. )}
  194. </Div>
  195. </View>
  196. <View style={[styles.card]}>
  197. <Div row pb={10}>
  198. <Text fontSize="xl" fontWeight="bold">
  199. {merchant.showName}
  200. </Text>
  201. <Button
  202. fontSize="xs"
  203. w={100}
  204. bg="white"
  205. color="gray600"
  206. borderColor="brand500"
  207. borderWidth={1}
  208. rounded={3}
  209. ml={14}
  210. onPress={() => {
  211. warnning('正在帮您联系商家');
  212. }}
  213. >
  214. 联系商家
  215. </Button>
  216. </Div>
  217. <Div>
  218. {orderGoodsSpecs.map((item) => {
  219. return <GoodsItem info={item} goods={item.goods} key={item.id} />;
  220. })}
  221. </Div>
  222. <Flex style={styles.info}>
  223. <Flex.Item>
  224. <Flex>
  225. <Text fontSize="xs" color="gray300" textAlign="left">
  226. 包装费
  227. </Text>
  228. <Text fontSize="xs" color="gray300" textAlign="left">
  229. 餐盒
  230. </Text>
  231. </Flex>
  232. </Flex.Item>
  233. <Text fontSize="xs" color="gray300" textAlign="left">
  234. ¥{orderInfo.packingPrice}
  235. </Text>
  236. </Flex>
  237. <Flex style={styles.info}>
  238. <Flex.Item>
  239. <Text fontSize="xs" color="gray300" textAlign="left">
  240. 配送费(叮咚专送)
  241. </Text>
  242. </Flex.Item>
  243. <Text fontSize="xs" color="gray300" textAlign="left">
  244. ¥{orderInfo.deliveryAmount}
  245. </Text>
  246. </Flex>
  247. <Flex style={styles.info}>
  248. <Flex.Item>
  249. <Text fontSize="xs" color="gray300" textAlign="left">
  250. 满减
  251. </Text>
  252. </Flex.Item>
  253. <Text fontSize="xs" color="red500" textAlign="left">
  254. -¥{orderInfo.fullReduction}
  255. </Text>
  256. </Flex>
  257. {!!orderInfo.firstBuy && (
  258. <Flex style={styles.info}>
  259. <Flex.Item>
  260. <Text fontSize="xs" color="gray300" textAlign="left">
  261. 首单
  262. </Text>
  263. </Flex.Item>
  264. <Text fontSize="xs" color="red500" textAlign="left">
  265. ¥{orderInfo.firstBuy}
  266. </Text>
  267. </Flex>
  268. )}
  269. <Flex style={styles.info}>
  270. <Flex.Item>
  271. <Text fontSize="xs" color="gray300" textAlign="left">
  272. 红包
  273. </Text>
  274. </Flex.Item>
  275. <Text fontSize="xs" color="red500" textAlign="left">
  276. -¥{orderInfo.redBag || 0}
  277. </Text>
  278. </Flex>
  279. <Flex style={styles.total} justify="end">
  280. <Text size="s1">小计 ¥{orderInfo.realAmount}</Text>
  281. </Flex>
  282. </View>
  283. <View style={[styles.card]}>
  284. <Text size="c1">订单信息</Text>
  285. <View style={styles.main}>
  286. <Flex style={styles.info2}>
  287. <Flex.Item>
  288. <Text fontSize="xs" textAlign="left">
  289. 下单时间
  290. </Text>
  291. </Flex.Item>
  292. <Text fontSize="xs" textAlign="left">
  293. {orderInfo.orderTime}
  294. </Text>
  295. </Flex>
  296. {orderInfo.userReceivedTime ? (
  297. <Flex style={styles.info2}>
  298. <Flex.Item>
  299. <Text fontSize="xs" textAlign="left">
  300. 送达时间
  301. </Text>
  302. </Flex.Item>
  303. <Text fontSize="xs" textAlign="left">
  304. {orderInfo.userReceivedTime}
  305. </Text>
  306. </Flex>
  307. ) : (
  308. <Flex style={styles.info2}>
  309. <Flex.Item>
  310. <Text fontSize="xs" textAlign="left">
  311. 预计送达时间
  312. </Text>
  313. </Flex.Item>
  314. <Text fontSize="xs" textAlign="left">
  315. {orderInfo.timeOfArrival}
  316. </Text>
  317. </Flex>
  318. )}
  319. <Flex style={styles.info2}>
  320. <Flex.Item style={styles.address}>
  321. <Text fontSize="xs" textAlign="left">
  322. 收货地址
  323. </Text>
  324. </Flex.Item>
  325. <Text fontSize="xs" textAlign="left">
  326. {orderInfo.userAddress}
  327. </Text>
  328. </Flex>
  329. <Flex style={styles.info2}>
  330. <Flex.Item>
  331. <Text fontSize="xs" textAlign="left">
  332. 配送骑手
  333. </Text>
  334. </Flex.Item>
  335. <Flex>
  336. <Button
  337. fontSize="xs"
  338. w={100}
  339. bg="white"
  340. color="gray600"
  341. borderColor="brand500"
  342. borderWidth={1}
  343. rounded={3}
  344. onPress={() => {
  345. warnning('正在帮您联系骑手');
  346. }}
  347. >
  348. 联系骑手
  349. </Button>
  350. <Text fontSize="xs" ml={20} textAlign="left">
  351. 周猩猩
  352. </Text>
  353. </Flex>
  354. </Flex>
  355. <Flex style={styles.info2}>
  356. <Text fontSize="xs" textAlign="left">
  357. 订 单 号
  358. </Text>
  359. <Text fontSize="xs" textAlign="right" ml={10} flex={1}>
  360. {orderInfo.id}
  361. </Text>
  362. <Button
  363. fontSize="xs"
  364. w={62}
  365. bg="white"
  366. color="gray600"
  367. borderColor="brand500"
  368. borderWidth={1}
  369. rounded={3}
  370. onPress={() => {
  371. Clipboard.setString(orderInfo.id.toString());
  372. success('复制成功');
  373. }}
  374. ml={5}
  375. >
  376. 复制
  377. </Button>
  378. </Flex>
  379. {payMap.has(orderInfo.payMethod) && (
  380. <Flex style={styles.info2}>
  381. <Text fontSize="xs" flex={1}>
  382. 支付方式
  383. </Text>
  384. <Text fontSize="xs" textAlign="left">
  385. {payMap.get(orderInfo.payMethod).name}
  386. </Text>
  387. </Flex>
  388. )}
  389. </View>
  390. </View>
  391. </ScrollView>
  392. </>
  393. );
  394. }
  395. const GoodsItem = ({ info, goods }) => {
  396. return (
  397. <Div row>
  398. <Image w={33} h={33} rounded={3} source={{ uri: goods.img }} />
  399. <Div flex={1} ml={10}>
  400. <Div row>
  401. <Text fontSize="sm" flex={1}>
  402. {goods.name}
  403. </Text>
  404. <Text fontSize="sm">X {info.num}</Text>
  405. <Text ml={10}>¥{info.goodsRealPrice}</Text>
  406. </Div>
  407. <Text fontSize="xs" color="gray400">
  408. {info.specification}
  409. </Text>
  410. </Div>
  411. </Div>
  412. );
  413. };
  414. const styles = StyleSheet.create({
  415. scroll: {
  416. flexGrow: 1,
  417. paddingHorizontal: 15,
  418. paddingVertical: 10,
  419. backgroundColor: '#eee',
  420. },
  421. card: {
  422. borderRadius: 3,
  423. backgroundColor: '#fff',
  424. marginBottom: 5,
  425. padding: 15,
  426. },
  427. item: {
  428. paddingVertical: 5,
  429. },
  430. icon: {
  431. width: 33,
  432. height: 33,
  433. borderRadius: 3,
  434. },
  435. goodsMain: {
  436. marginLeft: 10,
  437. },
  438. type: {
  439. // marginTop:3,
  440. },
  441. main: {
  442. marginTop: 10,
  443. paddingVertical: 5,
  444. borderColor: '#E5E5E5',
  445. borderTopWidth: 1,
  446. },
  447. info: {
  448. marginTop: 10,
  449. },
  450. total: {
  451. paddingTop: 10,
  452. marginTop: 10,
  453. borderColor: '#E5E5E5',
  454. borderTopWidth: 1,
  455. },
  456. address: {
  457. minWidth: 50,
  458. marginRight: 30,
  459. },
  460. info2: {
  461. marginTop: 10,
  462. },
  463. });