SearchMapScreen copy.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* eslint-disable no-underscore-dangle */
  2. import * as WebBrowser from 'expo-web-browser';
  3. import * as React from 'react';
  4. import { StatusBar } from 'expo-status-bar';
  5. import {
  6. Div,
  7. Button,
  8. Image,
  9. Text,
  10. Avatar,
  11. Icon,
  12. Input,
  13. } from 'react-native-magnus';
  14. import { Appbar } from 'react-native-paper';
  15. import { ScrollView } from 'react-native-gesture-handler';
  16. import useModel from 'flooks';
  17. import { getSearch } from '../../Utils/MapUtils';
  18. // 搜索
  19. export default function SearchMapScreen({ navigation }) {
  20. const [points, setPoints] = React.useState([]);
  21. return (
  22. <>
  23. <Div bg="white" pb={10} borderBottomWidth={1} borderColor="gray200">
  24. <StatusBar backgroundColor="#fff" style="dark" translucent />
  25. <Appbar.Header
  26. theme={{ colors: { primary: '#fff' } }}
  27. style={{
  28. elevation: 0,
  29. shadowOffset: {
  30. width: 0,
  31. height: 0,
  32. },
  33. shadowOpacity: 0,
  34. zIndex: 2,
  35. }}
  36. >
  37. <Appbar.BackAction onPress={navigation.goBack} />
  38. <Appbar.Content
  39. title="选择收货地址"
  40. titleStyle={{ textAlign: 'center', fontSize: 16 }}
  41. />
  42. <Div w={56} h={56} />
  43. </Appbar.Header>
  44. <Div
  45. row
  46. rounded="circle"
  47. block
  48. bg="gray200"
  49. mx={15}
  50. mt={10}
  51. alignItems="center"
  52. px={10}
  53. >
  54. <Text>南京市</Text>
  55. <Input
  56. placeholder="小区/写字楼/学校 等"
  57. p={10}
  58. focusBorderColor="gray200"
  59. bg="gray200"
  60. fontSize="xs"
  61. prefix={<Icon name="search" color="gray300" fontFamily="Feather" />}
  62. onChangeText={(val) => {
  63. getSearch(val, 'nearby(31.983908,118.730357,10000)').then(
  64. (res) => {
  65. setPoints(res.pois);
  66. }
  67. );
  68. }}
  69. />
  70. </Div>
  71. </Div>
  72. <ScrollView
  73. contentContainerStyle={{
  74. flexGrow: 1,
  75. backgroundColor: '#fff',
  76. }}
  77. >
  78. <Div px={15}>
  79. {points.map((item) => {
  80. return (
  81. <AddressItem
  82. info={item}
  83. key={item.id}
  84. onPress={() => {
  85. navigation.navigate('Home');
  86. }}
  87. />
  88. );
  89. })}
  90. </Div>
  91. </ScrollView>
  92. </>
  93. );
  94. }
  95. function AddressItem({ info, onPress }) {
  96. const distance =
  97. info._distance > 1000
  98. ? `${(info._distance / 1000).toFixed(2)}km`
  99. : `${info._distance}m`;
  100. return (
  101. <Button bg="hide" block p={0} onPress={onPress}>
  102. <Div borderBottomWidth={1} borderColor="gray200" py={5} flex={1}>
  103. <Div row alignItems="center">
  104. <Text fontSize="xl" flex={1} fontWeight="bold">
  105. {info.title}
  106. </Text>
  107. <Text fontSize="sm" color="gray300">
  108. {distance}
  109. </Text>
  110. </Div>
  111. <Text fontSize="sm" color="gray300" mt={5}>
  112. {info.address}
  113. </Text>
  114. </Div>
  115. </Button>
  116. );
  117. }