AddressCom.jsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. const AddressItem = ({ info, editEvent, isChoose, leftEvent }) => {
  13. return (
  14. <>
  15. <Div row alignItems="center" py={15}>
  16. <Button bg="white" onPress={leftEvent}>
  17. {isChoose ? (
  18. <Icon name="check-circle" color="#FFC21C" size={16} />
  19. ) : (
  20. <Icon name="circle-thin" color="#787878" size={16} />
  21. )}
  22. </Button>
  23. <Div flex={1} mx={15}>
  24. <Text fontSize="sm" textAlign="left">
  25. {info.addressName}
  26. </Text>
  27. <Text fontSize="xs" textAlign="left">
  28. {info.addressInfo}
  29. </Text>
  30. <Div row>
  31. <Text fontSize="xs" color="gray300" textAlign="left">
  32. {info.name}
  33. </Text>
  34. <Text ml={15} fontSize="xs" color="gray300" textAlign="left">
  35. {info.phone}
  36. </Text>
  37. </Div>
  38. </Div>
  39. <Button onPress={editEvent} bg="white">
  40. <Icon name="edit" color="#787878" size={20} />
  41. </Button>
  42. </Div>
  43. <Div h={1} bg="gray200" />
  44. </>
  45. );
  46. };
  47. export default function AddressCom() {
  48. const {
  49. addressList,
  50. getAddressList,
  51. goEdit,
  52. setShow,
  53. chooseAddressId,
  54. setChoose,
  55. } = useModel(AddressModel, ['addressList', 'goEdit', 'chooseAddressId']);
  56. const addressRequest = useRequest(getAddressList);
  57. const [visible, setvisible] = React.useState(false);
  58. const navigation = useNavigation();
  59. useUnmount(() => {
  60. setShow(false);
  61. });
  62. useFocusEffect(
  63. React.useCallback(() => {
  64. if (goEdit) {
  65. setvisible(true);
  66. }
  67. }, [goEdit])
  68. );
  69. const chooseaddressInfo = useCreation(() => {
  70. if (chooseAddressId) {
  71. return addressList.find((item) => {
  72. return item.id === chooseAddressId;
  73. });
  74. } else {
  75. return {};
  76. }
  77. }, [chooseAddressId, addressList]);
  78. return (
  79. <>
  80. <TouchableRipple
  81. onPress={() => {
  82. setvisible(true);
  83. }}
  84. >
  85. <Div row alignItems="center" h={56}>
  86. {chooseAddressId ? (
  87. <Div>
  88. <Text fontSize="xl" textAlign="left">
  89. {chooseaddressInfo.addressInfo}
  90. </Text>
  91. <Div row>
  92. <Text fontSize="xs" color="gray300" textAlign="left">
  93. {chooseaddressInfo.name}
  94. </Text>
  95. <Text mx={10} fontSize="xs" color="gray300" textAlign="left">
  96. {chooseaddressInfo.sex}
  97. </Text>
  98. <Text fontSize="xs" color="gray300" textAlign="left">
  99. {chooseaddressInfo.phone}
  100. </Text>
  101. </Div>
  102. </Div>
  103. ) : (
  104. <Text color="gray300">请选择地址</Text>
  105. )}
  106. <Div flex={1} />
  107. <Icon name="angle-right" color="#000" />
  108. </Div>
  109. </TouchableRipple>
  110. <Div h={1} bg="gray200" />
  111. <Portal>
  112. <Modal
  113. visible={visible}
  114. contentContainerStyle={{
  115. position: 'absolute',
  116. left: 0,
  117. right: 0,
  118. bottom: 0,
  119. maxHeight: '70%',
  120. zIndex: 2,
  121. justifyContent: 'flex-end',
  122. }}
  123. onDismiss={() => {
  124. setvisible(false);
  125. setShow(false);
  126. }}
  127. >
  128. <Div bg="white" px={15} mt={56}>
  129. <Div py={15}>
  130. <Text textAlign="center">选择收货地址</Text>
  131. </Div>
  132. <Div h={1} bg="gray200" />
  133. {addressList.map((item) => {
  134. return (
  135. <AddressItem
  136. key={item.id}
  137. info={item}
  138. isChoose={chooseAddressId === item.id}
  139. leftEvent={() => {
  140. setChoose(item.id);
  141. setvisible(false);
  142. setShow(false);
  143. }}
  144. editEvent={() => {
  145. setvisible(false);
  146. navigation.navigate('EditAddress', { id: item.id });
  147. setShow(true);
  148. }}
  149. />
  150. );
  151. })}
  152. {addressList.length === 0 && (
  153. <Div p={30}>
  154. <Text color="gray300" textAlign="center">
  155. 暂无数据111
  156. </Text>
  157. </Div>
  158. )}
  159. <Button
  160. bg="white"
  161. position="absolute"
  162. right={20}
  163. top={15}
  164. onPress={() => {
  165. setvisible(false);
  166. navigation.navigate('EditAddress');
  167. setShow(true);
  168. }}
  169. >
  170. <Icon name="plus" color="#b5b5b5" size={16} />
  171. </Button>
  172. </Div>
  173. </Modal>
  174. </Portal>
  175. </>
  176. );
  177. }