HomeAddressCom.jsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import { StyleSheet, View } from 'react-native';
  4. import { Div, Button, Select, Image, Text, Avatar } from 'react-native-magnus';
  5. import { ScrollView } from 'react-native-gesture-handler';
  6. import { Modal, Portal, TouchableRipple, Badge } from 'react-native-paper';
  7. import Icon from 'react-native-vector-icons/FontAwesome';
  8. import { useRequest, useCreation, useUnmount } from '@umijs/hooks';
  9. import { useNavigation, useFocusEffect } from '@react-navigation/native';
  10. import useModel from 'flooks';
  11. import AddressModel from './model'; // detail模块通用方法
  12. import MapModel from '../Map/model';
  13. const AddressItem = ({ info, onPress }) => {
  14. return (
  15. <>
  16. <Button onPress={onPress} bg="hide" p={0} block>
  17. <Div flex={1} row alignItems="center" py={15}>
  18. <Div flex={1} mx={15}>
  19. <Text fontSize="sm" textAlign="left">
  20. {info.addressName}
  21. </Text>
  22. <Text fontSize="sm" color="gray300" textAlign="left">
  23. {info.number}
  24. </Text>
  25. <Div row>
  26. <Text fontSize="sm" color="gray300" textAlign="left">
  27. {info.name}
  28. </Text>
  29. <Text fontSize="sm" color="gray300" textAlign="left">
  30. ({info.sex})
  31. </Text>
  32. <Text ml={15} fontSize="sm" color="gray300" textAlign="left">
  33. {info.phone}
  34. </Text>
  35. </Div>
  36. </Div>
  37. </Div>
  38. </Button>
  39. <Div h={1} bg="gray200" />
  40. </>
  41. );
  42. };
  43. export default function HomeAddressCom() {
  44. const {
  45. addressList,
  46. getAddressList,
  47. goEdit,
  48. setShow,
  49. chooseAddressId,
  50. setChoose,
  51. } = useModel(AddressModel, ['addressList', 'goEdit', 'chooseAddressId']);
  52. useRequest(getAddressList);
  53. const navigation = useNavigation();
  54. const { changeChooseInfo } = useModel(MapModel, []);
  55. useUnmount(() => {
  56. setShow(false);
  57. });
  58. return (
  59. <>
  60. <Div bg="white" px={15} pb={15}>
  61. <Div h={1} bg="gray200" />
  62. <Text py={12} fontSize="sm" color="gray500">
  63. 收货地址
  64. </Text>
  65. <Div h={1} bg="gray200" />
  66. {addressList.map((item) => {
  67. return (
  68. <AddressItem
  69. key={item.id}
  70. info={item}
  71. isChoose={chooseAddressId === item.id}
  72. onPress={() => {
  73. changeChooseInfo({
  74. addressName: item.addressName,
  75. location: {
  76. lat: item.latitude,
  77. lng: item.longitude,
  78. },
  79. });
  80. navigation.navigate('Home');
  81. }}
  82. />
  83. );
  84. })}
  85. {addressList.length === 0 && (
  86. <>
  87. <Div p={20}>
  88. <Text color="gray300" textAlign="center">
  89. 当前暂无地址
  90. </Text>
  91. </Div>
  92. <Div h={1} bg="gray200" />
  93. </>
  94. )}
  95. <Button
  96. block
  97. textAlign="left"
  98. px={0}
  99. bg="hide"
  100. py={15}
  101. onPress={() => {
  102. navigation.navigate('EditAddress');
  103. }}
  104. >
  105. <Text flex={1} color="brand500">
  106. 新增地址
  107. </Text>
  108. </Button>
  109. </Div>
  110. </>
  111. );
  112. }