AddressCom.jsx 6.1 KB

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