OrderScreen.jsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 { useCreation, useRequest } from '@umijs/hooks';
  8. import { useFocusEffect } from '@react-navigation/native';
  9. import useModel from 'flooks';
  10. import Toast from '../../flooks/Toast';
  11. import Header from './Header'; // 头部
  12. import Time from '../../Utils/TimeUtils';
  13. import MapMarkImg from '../Map/MapMarkImg';
  14. import { getStatusInfo } from '../../Utils/OrderUtils';
  15. export default function OrderScreen({ navigation }) {
  16. const [orderList, setorderList] = React.useState();
  17. const { success, warnning } = useModel(Toast, []);
  18. const orderRequest = useRequest('/orderInfo/my?sort=id,desc', {
  19. manual: true,
  20. onSuccess: (result) => {
  21. setorderList(result.content);
  22. },
  23. });
  24. useFocusEffect(
  25. React.useCallback(() => {
  26. orderRequest.run();
  27. }, [])
  28. );
  29. return (
  30. <>
  31. <Header noBack />
  32. <FlatList
  33. onRefresh={() => orderRequest.run()}
  34. refreshing={orderRequest.loading}
  35. contentContainerStyle={styles.list}
  36. data={orderList}
  37. renderItem={({ item, index }) => (
  38. <Item
  39. merchant={item.merchant}
  40. info={item}
  41. orderGoodsSpecs={item.orderGoodsSpecs}
  42. goNext={(name) => {
  43. navigation.navigate(name || 'OrderDetail', {
  44. orderId: item.id,
  45. });
  46. }}
  47. goMerchant={() => {
  48. navigation.navigate('MerchantDetail', {
  49. merchantId: item.merchantId,
  50. });
  51. }}
  52. index={index}
  53. connect={(type) => {
  54. if (type === 'merchant') {
  55. warnning('正在帮您联系商家');
  56. }
  57. }}
  58. />
  59. )}
  60. keyExtractor={(item) => item.id.toString()}
  61. />
  62. </>
  63. );
  64. }
  65. // 订单组件
  66. function Item({
  67. merchant,
  68. info,
  69. goNext,
  70. orderGoodsSpecs,
  71. goMerchant,
  72. connect,
  73. }) {
  74. const orderInfo =
  75. orderGoodsSpecs.length > 0 ? orderGoodsSpecs[0].goods.name : '';
  76. const statusInfo = getStatusInfo(info);
  77. const finish = info.riderStatus === 'CARRY_OUT';
  78. const Allfinish = info.status === 'COMPLETED';
  79. return (
  80. <Button bg="hide" block p={0} mt={10} onPress={() => goNext()}>
  81. <View style={styles.item}>
  82. <Div row>
  83. <Button bg="hide" p={0} onPress={() => goMerchant()}>
  84. <Image w={53} h={53} source={{ uri: merchant.logo }} />
  85. </Button>
  86. <Div flex={1} ml={10}>
  87. <Div row>
  88. <Text fontSize="xl" flex={1} fontWeight="bold">
  89. {merchant.name}
  90. </Text>
  91. {finish || Allfinish ? (
  92. <Text fontSize="xs">已送达</Text>
  93. ) : (
  94. <Text fontSize="xs">
  95. 预计
  96. <Text color="red500">
  97. {new Time(
  98. info.timeOfArrival,
  99. 'yyyy-MM-DD HH:mm:ss'
  100. ).getFormat('HH:mm')}
  101. </Text>
  102. 送达
  103. </Text>
  104. )}
  105. </Div>
  106. <Text fontSize="xs" my={10}>
  107. 订单时间: {info.orderTime}
  108. </Text>
  109. <Div h={1} bg="gray200" />
  110. <Div row py={10} alignItems="center">
  111. <Text fontSize="sm">订单商品</Text>
  112. <Text fontSize="xs" ml={5} flex={1}>
  113. {orderInfo}等{info.num}件
  114. </Text>
  115. <Text size="sm">¥{info.realAmount}</Text>
  116. </Div>
  117. </Div>
  118. </Div>
  119. <MapMarkImg
  120. imgType={statusInfo.nowImgType}
  121. label={statusInfo.name}
  122. info={info}
  123. />
  124. <Flex justify="end" style={styles.btns}>
  125. {finish && !Allfinish ? (
  126. <Button
  127. w={100}
  128. fontSize="xs"
  129. bg="white"
  130. color="gray600"
  131. borderColor="brand500"
  132. borderWidth={1}
  133. rounded={3}
  134. onPress={() => goNext('Evaluate')}
  135. >
  136. 立即评价
  137. </Button>
  138. ) : (
  139. <Button
  140. w={100}
  141. fontSize="xs"
  142. bg="white"
  143. color="gray600"
  144. borderColor="brand500"
  145. borderWidth={1}
  146. rounded={3}
  147. onPress={() => connect('merchant')}
  148. >
  149. 联系商家
  150. </Button>
  151. )}
  152. {finish && (
  153. <Button
  154. w={100}
  155. fontSize="xs"
  156. bg="white"
  157. color="gray600"
  158. borderColor="brand500"
  159. borderWidth={1}
  160. rounded={3}
  161. ml={10}
  162. onPress={goMerchant}
  163. >
  164. 再来一单
  165. </Button>
  166. )}
  167. </Flex>
  168. </View>
  169. </Button>
  170. );
  171. }
  172. const styles = StyleSheet.create({
  173. item: {
  174. paddingVertical: 20,
  175. paddingHorizontal: 10,
  176. backgroundColor: '#fff',
  177. borderRadius: 3,
  178. flex: 1,
  179. },
  180. list: {
  181. padding: 15,
  182. },
  183. icon: {
  184. width: 53,
  185. height: 53,
  186. borderRadius: 3,
  187. backgroundColor: '#eee',
  188. },
  189. main: {
  190. marginLeft: 5,
  191. },
  192. orderDetail: {
  193. paddingVertical: 10,
  194. borderTopWidth: 1,
  195. borderColor: '#E5E5E5',
  196. marginTop: 10,
  197. },
  198. btns: {
  199. paddingTop: 15,
  200. },
  201. });