AddressScreen.jsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 { useRequest, useCreation } from '@umijs/hooks';
  7. import useModel from 'flooks';
  8. import AddressModel from './model'; // detail模块通用方法
  9. import Header from '../../components/Header';
  10. const AddressItem = ({ info, goNext, del }) => {
  11. const right = [
  12. {
  13. text: '删除',
  14. onPress: () => {
  15. console.log('删除');
  16. del();
  17. },
  18. style: { backgroundColor: 'red', color: 'white' },
  19. },
  20. ];
  21. return (
  22. <SwipeAction
  23. autoClose
  24. style={{ backgroundColor: 'transparent' }}
  25. right={right}
  26. >
  27. <Div bg="white" px={15} py={10} my={5} mx={10}>
  28. <Text fontSize="xl" textAlign="left">
  29. {info.addressName}
  30. </Text>
  31. <Div row>
  32. <Text fontSize="xs" color="gray300" textAlign="left">
  33. {info.name}
  34. </Text>
  35. <Text fontSize="xs" color="gray300" textAlign="left">
  36. {info.sex}
  37. </Text>
  38. <Text ml={15} fontSize="xs" color="gray300" textAlign="left">
  39. {info.phone}
  40. </Text>
  41. </Div>
  42. <Div row justifyContent="flex-end">
  43. {info.isDefault && (
  44. <Button fontSize="xs" bg="brand500">
  45. 默认
  46. </Button>
  47. )}
  48. <Button
  49. fontSize="xs"
  50. ml={15}
  51. bg="white"
  52. color="gray600"
  53. borderColor="gray300"
  54. borderWidth={1}
  55. onPress={goNext}
  56. >
  57. 编辑
  58. </Button>
  59. </Div>
  60. </Div>
  61. </SwipeAction>
  62. );
  63. };
  64. export default function AddressScreen({ navigation }) {
  65. const { addressList, getAddressList, delAddress } = useModel(AddressModel, [
  66. 'addressList',
  67. ]);
  68. const addressRequest = useRequest(getAddressList);
  69. return (
  70. <>
  71. <Header title="地址列表" />
  72. <ScrollView>
  73. {addressList.map((item) => {
  74. return (
  75. <AddressItem
  76. key={item.id}
  77. info={item}
  78. del={() => {
  79. delAddress(item.id);
  80. }}
  81. goNext={() => {
  82. navigation.navigate('EditAddress', {
  83. id: item.id,
  84. });
  85. }}
  86. />
  87. );
  88. })}
  89. </ScrollView>
  90. <Button
  91. block
  92. my={20}
  93. mx={15}
  94. bg="brand500"
  95. onPress={() => {
  96. navigation.navigate('EditAddress');
  97. }}
  98. >
  99. 新增地址
  100. </Button>
  101. </>
  102. );
  103. }