OrderScreen.jsx 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import { StyleSheet, View, FlatList } from 'react-native';
  4. import { Div, Button, Text, Avatar, Image } from 'react-native-magnus';
  5. import { Flex } from '@ant-design/react-native';
  6. import { TouchableRipple } from 'react-native-paper';
  7. import { useTranslation } from 'react-i18next';
  8. import { useCreation, useRequest } from '@umijs/hooks';
  9. import { useFocusEffect } from '@react-navigation/native';
  10. import useModel from 'flooks';
  11. import Toast from '../../flooks/Toast';
  12. import Order from './model';
  13. import Header from './Header'; // 头部
  14. import Time from '../../Utils/TimeUtils';
  15. import MapMarkImg from '../Map/MapMarkImg';
  16. import { getStatusInfo, getGoodsInfo } from '../../Utils/OrderUtils';
  17. export default function OrderScreen({ navigation }) {
  18. const { t } = useTranslation();
  19. const [orderList, setorderList] = React.useState();
  20. const { success, warnning } = useModel(Toast, []);
  21. const { again } = useModel(Order, []);
  22. const orderRequest = useRequest('/orderInfo/my?sort=id,desc', {
  23. manual: true,
  24. onSuccess: (result) => {
  25. setorderList(result.content);
  26. },
  27. });
  28. useFocusEffect(
  29. React.useCallback(() => {
  30. orderRequest.run();
  31. }, [])
  32. );
  33. return (
  34. <>
  35. <Header noBack />
  36. <FlatList
  37. onRefresh={() => orderRequest.run()}
  38. refreshing={orderRequest.loading}
  39. contentContainerStyle={styles.list}
  40. data={orderList}
  41. renderItem={({ item, index }) => (
  42. <Item
  43. merchant={item.merchant}
  44. info={item}
  45. orderGoodsSpecs={item.orderGoodsSpecs}
  46. goNext={(name) => {
  47. navigation.navigate(name || 'OrderDetail', {
  48. orderId: item.id,
  49. });
  50. }}
  51. goMerchant={() => {
  52. again(item.id).then(() => {
  53. navigation.navigate('MerchantDetail', {
  54. merchantId: item.merchantId,
  55. });
  56. });
  57. }}
  58. index={index}
  59. connect={(type) => {
  60. if (type === 'merchant') {
  61. if (!item.muserId) {
  62. warnning('商家信息有误请联系客服帮你催单');
  63. } else {
  64. navigation.navigate('Chat', {
  65. toUserId: item.muserId,
  66. toUserName: item.merShowName,
  67. });
  68. }
  69. }
  70. }}
  71. />
  72. )}
  73. keyExtractor={(item) => item.id.toString()}
  74. />
  75. </>
  76. );
  77. }
  78. // 订单组件
  79. function Item({
  80. merchant = {},
  81. info,
  82. goNext,
  83. orderGoodsSpecs,
  84. goMerchant,
  85. connect,
  86. }) {
  87. const { t } = useTranslation();
  88. const orderGoodsInfo = getGoodsInfo(orderGoodsSpecs);
  89. const statusInfo = getStatusInfo(info);
  90. const finish = info.riderStatus === 'CARRY_OUT';
  91. const Allfinish = info.status === 'COMPLETED';
  92. return (
  93. <Button bg="hide" block p={0} mt={10} onPress={() => goNext()}>
  94. <View style={styles.item}>
  95. <Div row>
  96. <Button bg="hide" p={0} onPress={() => goMerchant()}>
  97. <Image w={53} h={53} source={{ uri: info.merLogo }} />
  98. </Button>
  99. <Div flex={1} ml={10}>
  100. <Div row>
  101. <Text fontSize="xl" flex={1} fontWeight="bold">
  102. {info.merShowName}
  103. </Text>
  104. {finish || Allfinish ? (
  105. <Text fontSize="xs">{t('yi-song-da')}</Text>
  106. ) : (
  107. <Text fontSize="xs">
  108. {t('yu-ji')}
  109. <Text color="red500">
  110. {new Time(
  111. info.timeOfArrival,
  112. 'yyyy-MM-DD HH:mm:ss'
  113. ).getFormat('HH:mm')}
  114. </Text>
  115. {t('song-da')}
  116. </Text>
  117. )}
  118. </Div>
  119. <Text fontSize="xs" my={10}>
  120. {t('ding-dan-shi-jian')}: {info.orderTime}
  121. </Text>
  122. <Div h={1} bg="gray200" />
  123. <Div row py={10} alignItems="center">
  124. <Text fontSize="sm">{t('ding-dan-shang-pin')}</Text>
  125. <Text fontSize="xs" ml={5} flex={1}>
  126. {orderGoodsInfo.name}
  127. {t('deng')}
  128. {orderGoodsInfo.num}
  129. {t('jian2')}
  130. </Text>
  131. <Text size="sm">¥{info.realAmount}</Text>
  132. </Div>
  133. </Div>
  134. </Div>
  135. <MapMarkImg
  136. imgType={statusInfo.nowImgType}
  137. label={statusInfo.name}
  138. info={info}
  139. />
  140. <Flex justify="end" style={styles.btns}>
  141. {info.status !== 'UNPAID' && (
  142. <Button
  143. w={100}
  144. fontSize="xs"
  145. bg="white"
  146. color="gray600"
  147. borderColor="brand500"
  148. borderWidth={1}
  149. rounded={3}
  150. onPress={() => goNext('PayOrder')}
  151. >
  152. 去支付
  153. </Button>
  154. )}
  155. {finish && !Allfinish ? (
  156. <Button
  157. w={100}
  158. fontSize="xs"
  159. bg="white"
  160. color="gray600"
  161. borderColor="brand500"
  162. borderWidth={1}
  163. rounded={3}
  164. onPress={() => goNext('Evaluate')}
  165. >
  166. {t('li-ji-ping-jia')}
  167. </Button>
  168. ) : (
  169. <Button
  170. w={100}
  171. fontSize="xs"
  172. bg="white"
  173. color="gray600"
  174. borderColor="brand500"
  175. borderWidth={1}
  176. rounded={3}
  177. onPress={() => connect('merchant')}
  178. >
  179. {t('lian-xi-shang-jia')}
  180. </Button>
  181. )}
  182. {finish && (
  183. <Button
  184. w={100}
  185. fontSize="xs"
  186. bg="white"
  187. color="gray600"
  188. borderColor="brand500"
  189. borderWidth={1}
  190. rounded={3}
  191. ml={10}
  192. onPress={goMerchant}
  193. >
  194. {t('zai-lai-yi-dan')}
  195. </Button>
  196. )}
  197. </Flex>
  198. </View>
  199. </Button>
  200. );
  201. }
  202. const styles = StyleSheet.create({
  203. item: {
  204. paddingVertical: 20,
  205. paddingHorizontal: 10,
  206. backgroundColor: '#fff',
  207. borderRadius: 3,
  208. flex: 1,
  209. },
  210. list: {
  211. padding: 15,
  212. },
  213. icon: {
  214. width: 53,
  215. height: 53,
  216. borderRadius: 3,
  217. backgroundColor: '#eee',
  218. },
  219. main: {
  220. marginLeft: 5,
  221. },
  222. orderDetail: {
  223. paddingVertical: 10,
  224. borderTopWidth: 1,
  225. borderColor: '#E5E5E5',
  226. marginTop: 10,
  227. },
  228. btns: {
  229. paddingTop: 15,
  230. },
  231. });