AddressCom.jsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import { StyleSheet, View } from 'react-native';
  4. import {
  5. Div,
  6. Button,
  7. Select,
  8. Image,
  9. Text,
  10. Avatar,
  11. Icon,
  12. } from 'react-native-magnus';
  13. import { ScrollView } from 'react-native-gesture-handler';
  14. import { Modal, Portal, TouchableRipple, Badge } from 'react-native-paper';
  15. import { useTranslation } from 'react-i18next';
  16. import { useRequest, useCreation, useUnmount } from '@umijs/hooks';
  17. import { useNavigation, useFocusEffect } from '@react-navigation/native';
  18. import useModel from 'flooks';
  19. import AddressModel from './model'; // detail模块通用方法
  20. const AddressItem = ({ info, editEvent, isChoose, leftEvent }) => {
  21. return (
  22. <>
  23. <Div row alignItems="center" py={15}>
  24. <Button bg="white" onPress={leftEvent}>
  25. {isChoose ? (
  26. <Icon name="checkcircle" color="#FFC21C" size={16} />
  27. ) : (
  28. <Div
  29. w={16}
  30. h={16}
  31. rounded="circle"
  32. borderWidth={1}
  33. borderColor="#787878"
  34. />
  35. )}
  36. </Button>
  37. <Button block flex={1} mx={15} p={0} bg="hide" onPress={leftEvent}>
  38. <Div flex={1}>
  39. <Text fontSize="sm" textAlign="left">
  40. {info.addressName}
  41. </Text>
  42. <Text fontSize="xs" textAlign="left">
  43. {info.addressInfo}
  44. </Text>
  45. <Div row>
  46. <Text fontSize="xs" color="gray300" textAlign="left">
  47. {info.name}
  48. </Text>
  49. <Text ml={15} fontSize="xs" color="gray300" textAlign="left">
  50. {info.phone}
  51. </Text>
  52. </Div>
  53. </Div>
  54. </Button>
  55. <Button onPress={editEvent} bg="white">
  56. <Icon name="edit" color="#787878" size={20} />
  57. </Button>
  58. </Div>
  59. <Div h={1} bg="gray200" />
  60. </>
  61. );
  62. };
  63. export default function AddressCom() {
  64. const { t } = useTranslation();
  65. const {
  66. addressList,
  67. getAddressList,
  68. goEdit,
  69. setShow,
  70. chooseAddressId,
  71. setChoose,
  72. } = useModel(AddressModel, ['addressList', 'goEdit', 'chooseAddressId']);
  73. const addressRequest = useRequest(getAddressList);
  74. const [visible, setvisible] = React.useState(false);
  75. const navigation = useNavigation();
  76. useUnmount(() => {
  77. setShow(false);
  78. });
  79. useFocusEffect(
  80. React.useCallback(() => {
  81. if (goEdit) {
  82. setvisible(true);
  83. }
  84. }, [goEdit])
  85. );
  86. const chooseaddressInfo = useCreation(() => {
  87. if (chooseAddressId) {
  88. return addressList.find((item) => {
  89. return item.id === chooseAddressId;
  90. });
  91. } else {
  92. return {};
  93. }
  94. }, [chooseAddressId, addressList]);
  95. return (
  96. <>
  97. <TouchableRipple
  98. onPress={() => {
  99. setvisible(true);
  100. }}
  101. >
  102. <Div row alignItems="center" minH={56} py={10}>
  103. {chooseAddressId ? (
  104. <Div flex={1} overflow="hidden">
  105. <Text
  106. fontSize="xl"
  107. textAlign="left"
  108. // numberOfLines={1}
  109. // ellipsizeMode="tail"
  110. >
  111. {chooseaddressInfo.addressName}
  112. </Text>
  113. <Text fontSize="sm" color="gray300" textAlign="left">
  114. {chooseaddressInfo.number}
  115. </Text>
  116. <Div row>
  117. <Text fontSize="xs" color="gray300" textAlign="left">
  118. {chooseaddressInfo.name}
  119. </Text>
  120. <Text mx={10} fontSize="xs" color="gray300" textAlign="left">
  121. {chooseaddressInfo.sex}
  122. </Text>
  123. <Text fontSize="xs" color="gray300" textAlign="left">
  124. {chooseaddressInfo.phone}
  125. </Text>
  126. </Div>
  127. </Div>
  128. ) : (
  129. <>
  130. <Text color="gray300">{t('qing-xuan-ze-di-zhi')}</Text>
  131. <Div flex={1} />
  132. </>
  133. )}
  134. <Icon name="right" color="#000" />
  135. </Div>
  136. </TouchableRipple>
  137. <Div h={1} bg="gray200" />
  138. <Portal>
  139. <Modal
  140. visible={visible}
  141. contentContainerStyle={{
  142. position: 'absolute',
  143. left: 0,
  144. right: 0,
  145. bottom: 0,
  146. maxHeight: '70%',
  147. zIndex: 2,
  148. justifyContent: 'flex-end',
  149. }}
  150. onDismiss={() => {
  151. setvisible(false);
  152. setShow(false);
  153. }}
  154. >
  155. <Div bg="white" px={15} mt={56}>
  156. <Div py={15}>
  157. <Text textAlign="center">{t('xuan-ze-shou-huo-di-zhi')}</Text>
  158. </Div>
  159. <Div h={1} bg="gray200" />
  160. {addressList.map((item) => {
  161. return (
  162. <AddressItem
  163. key={item.id}
  164. info={item}
  165. isChoose={chooseAddressId === item.id}
  166. leftEvent={() => {
  167. setChoose(item.id);
  168. setvisible(false);
  169. setShow(false);
  170. }}
  171. editEvent={() => {
  172. setvisible(false);
  173. navigation.navigate('EditAddress', { id: item.id });
  174. setShow(true);
  175. }}
  176. />
  177. );
  178. })}
  179. {addressList.length === 0 && (
  180. <Div p={30}>
  181. <Text color="gray300" textAlign="center">
  182. {t('zan-wu-shu-ju')}
  183. </Text>
  184. </Div>
  185. )}
  186. <Button
  187. bg="white"
  188. position="absolute"
  189. right={20}
  190. top={15}
  191. onPress={() => {
  192. setvisible(false);
  193. navigation.navigate('EditAddress');
  194. setShow(true);
  195. }}
  196. >
  197. <Icon name="plus" color="#b5b5b5" size={16} />
  198. </Button>
  199. </Div>
  200. </Modal>
  201. </Portal>
  202. </>
  203. );
  204. }