OrderScreen.jsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 Header from './Header'; // 头部
  10. import Time from '../../Utils/TimeUtils';
  11. export default function OrderScreen({ navigation }) {
  12. const [orderList, setorderList] = React.useState();
  13. const orderRequest = useRequest('/orderInfo/my?sort=id,desc', {
  14. manual: true,
  15. onSuccess: (result) => {
  16. setorderList(result.content);
  17. },
  18. });
  19. useFocusEffect(
  20. React.useCallback(() => {
  21. orderRequest.run();
  22. }, [])
  23. );
  24. return (
  25. <>
  26. <Header noBack />
  27. <FlatList
  28. onRefresh={() => orderRequest.run()}
  29. refreshing={orderRequest.loading}
  30. contentContainerStyle={styles.list}
  31. data={orderList}
  32. renderItem={({ item }) => (
  33. <Item
  34. merchant={item.merchant}
  35. info={item}
  36. orderGoodsSpecs={item.orderGoodsSpecs}
  37. goNext={() => {
  38. navigation.navigate('OrderDetail', {
  39. orderId: item.id,
  40. });
  41. }}
  42. />
  43. )}
  44. keyExtractor={(item) => item.id.toString()}
  45. />
  46. </>
  47. );
  48. }
  49. // 订单组件
  50. function Item({ merchant, info, goNext, orderGoodsSpecs }) {
  51. const orderInfo =
  52. orderGoodsSpecs.length > 0 ? orderGoodsSpecs[0].goods.name : '';
  53. return (
  54. <TouchableRipple style={{ marginBottom: 10 }} onPress={goNext}>
  55. <View style={styles.item}>
  56. <Div row>
  57. <Image w={53} h={53} source={{ uri: merchant.logo }} />
  58. <Div flex={1} ml={10}>
  59. <Div row>
  60. <Text fontSize="xl" flex={1} fontWeight="bold">
  61. {merchant.name}
  62. </Text>
  63. <Text fontSize="xs">
  64. 预计
  65. <Text color="red500">
  66. {new Time(
  67. info.timeOfArrival,
  68. 'yyyy-MM-DD HH:mm:ss'
  69. ).getFormat('HH:mm')}
  70. </Text>
  71. 送达
  72. </Text>
  73. </Div>
  74. <Text fontSize="xs" my={10}>
  75. 订单时间: {info.orderTime}
  76. </Text>
  77. <Div h={1} bg="gray200" />
  78. <Div row py={10} alignItems="center">
  79. <Text fontSize="sm">订单商品</Text>
  80. <Text fontSize="xs" ml={5} flex={1}>
  81. {orderInfo}等{info.num}件
  82. </Text>
  83. <Text size="sm">¥{info.realAmount}</Text>
  84. </Div>
  85. </Div>
  86. </Div>
  87. <Image h={200} source={{ uri: 'https://picsum.photos/700' }} />
  88. <Flex justify="end" style={styles.btns}>
  89. <Button
  90. w={100}
  91. fontSize="xs"
  92. bg="white"
  93. color="gray600"
  94. borderColor="brand500"
  95. borderWidth={1}
  96. rounded={3}
  97. >
  98. 联系商家
  99. </Button>
  100. </Flex>
  101. </View>
  102. </TouchableRipple>
  103. );
  104. }
  105. const styles = StyleSheet.create({
  106. item: {
  107. paddingVertical: 20,
  108. paddingHorizontal: 10,
  109. backgroundColor: '#fff',
  110. borderRadius: 3,
  111. },
  112. list: {
  113. padding: 15,
  114. },
  115. icon: {
  116. width: 53,
  117. height: 53,
  118. borderRadius: 3,
  119. backgroundColor: '#eee',
  120. },
  121. main: {
  122. marginLeft: 5,
  123. },
  124. orderDetail: {
  125. paddingVertical: 10,
  126. borderTopWidth: 1,
  127. borderColor: '#E5E5E5',
  128. marginTop: 10,
  129. },
  130. btns: {
  131. paddingTop: 15,
  132. },
  133. });