AddressScreen.jsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import { Div, Button, Image, Text, Avatar } from 'react-native-magnus';
  4. import { Flex, SwipeAction } from '@ant-design/react-native';
  5. import { ScrollView } from 'react-native-gesture-handler';
  6. import { useTranslation } from 'react-i18next';
  7. import { useRequest, useCreation } from '@umijs/hooks';
  8. import useModel from 'flooks';
  9. import AddressModel from './model'; // detail模块通用方法
  10. import Header from '../../components/Header';
  11. const AddressItem = ({ info, goNext, del }) => {
  12. const { t } = useTranslation();
  13. const right = [
  14. {
  15. text: t('shan-chu'),
  16. onPress: () => {
  17. console.log('删除');
  18. del();
  19. },
  20. style: { backgroundColor: 'red', color: 'white' },
  21. },
  22. ];
  23. return (
  24. <SwipeAction
  25. autoClose
  26. style={{ backgroundColor: 'transparent' }}
  27. right={right}
  28. >
  29. <Div bg="white" px={15} py={10} my={5} mx={10}>
  30. <Text fontSize="xl" textAlign="left">
  31. {info.addressName}
  32. </Text>
  33. <Div row>
  34. <Text fontSize="xs" color="gray300" textAlign="left">
  35. {info.name}
  36. </Text>
  37. <Text fontSize="xs" color="gray300" textAlign="left">
  38. {info.sex}
  39. </Text>
  40. <Text ml={15} fontSize="xs" color="gray300" textAlign="left">
  41. {info.phone}
  42. </Text>
  43. </Div>
  44. <Div row justifyContent="flex-end">
  45. {info.isDefault && (
  46. <Button fontSize="xs" bg="brand500">
  47. {t('mo-ren')}
  48. </Button>
  49. )}
  50. <Button
  51. fontSize="xs"
  52. ml={15}
  53. bg="white"
  54. color="gray600"
  55. borderColor="gray300"
  56. borderWidth={1}
  57. onPress={goNext}
  58. >
  59. {t('bian-ji')}
  60. </Button>
  61. </Div>
  62. </Div>
  63. </SwipeAction>
  64. );
  65. };
  66. export default function AddressScreen({ navigation }) {
  67. const { t } = useTranslation();
  68. const { addressList, getAddressList, delAddress } = useModel(AddressModel, [
  69. 'addressList',
  70. ]);
  71. const addressRequest = useRequest(getAddressList);
  72. return (
  73. <>
  74. <Header title={t('di-zhi-lie-biao')} />
  75. <ScrollView>
  76. {addressList.map((item) => {
  77. return (
  78. <AddressItem
  79. key={item.id}
  80. info={item}
  81. del={() => {
  82. delAddress(item.id);
  83. }}
  84. goNext={() => {
  85. navigation.navigate('EditAddress', {
  86. id: item.id,
  87. });
  88. }}
  89. />
  90. );
  91. })}
  92. </ScrollView>
  93. <Button
  94. block
  95. my={20}
  96. mx={15}
  97. bg="brand500"
  98. onPress={() => {
  99. navigation.navigate('EditAddress');
  100. }}
  101. >
  102. {t('xin-zeng-di-zhi')}
  103. </Button>
  104. </>
  105. );
  106. }