MerchantCom.js 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 { Div, Text, Image, Tag } from 'react-native-magnus';
  5. import { Flex, SwipeAction } from '@ant-design/react-native';
  6. import { TouchableRipple } from 'react-native-paper';
  7. import useModel from 'flooks';
  8. import { useCreation } from '@umijs/hooks';
  9. import { useNavigation } from '@react-navigation/native';
  10. import Chip from '../../../components/Chip';
  11. import Icon from '../../../components/SvgIcon';
  12. import DetailModel from '../../Detail/model';
  13. import { getColor } from '../../../Utils/ColorUtils';
  14. // 首页商家组件
  15. export default function MerchantCom(props) {
  16. const { info, isCollection, CollectionId, freash, isNew } = props;
  17. const navigation = useNavigation();
  18. const { delLike } = useModel(DetailModel, []);
  19. const {
  20. showName,
  21. logo,
  22. distance,
  23. category,
  24. merchantNature,
  25. startingAmount,
  26. monthSales,
  27. goodNum,
  28. badNum,
  29. preparationTime,
  30. mid,
  31. } = info || { showName: '' };
  32. const tags = useCreation(() => {
  33. let list = [];
  34. if (merchantNature) {
  35. list.push({
  36. name: merchantNature.name,
  37. });
  38. }
  39. if (category) {
  40. list = list.concat(
  41. category.map((item) => {
  42. return { name: item.name };
  43. })
  44. );
  45. }
  46. return list;
  47. }, [category, merchantNature]);
  48. const long = useCreation(() => {
  49. if (distance < 1000) {
  50. return `${distance}米`;
  51. } else if (distance) {
  52. return `${(distance / 1000).toFixed(1)}km`;
  53. } else {
  54. return false;
  55. }
  56. }, [distance]);
  57. const right = [
  58. {
  59. text: '删除',
  60. onPress: () => {
  61. console.log('删除');
  62. delLike(CollectionId).then(() => freash());
  63. },
  64. style: { backgroundColor: 'red', color: 'white' },
  65. },
  66. ];
  67. return (
  68. <SwipeAction
  69. autoClose
  70. style={{ backgroundColor: 'transparent' }}
  71. right={right}
  72. disabled={!isCollection}
  73. >
  74. <Div my={isCollection || isNew ? 5 : 0}>
  75. <TouchableRipple
  76. onPress={() => {
  77. navigation.navigate('MerchantDetail', {
  78. merchantId: isCollection || isNew ? info.id : mid,
  79. });
  80. }}
  81. >
  82. <Div row px={10} pt={10} bg="white">
  83. {logo ? (
  84. <Image
  85. w={67}
  86. h={67}
  87. bg="gray200"
  88. rounded="sm"
  89. source={{ uri: logo || '' }}
  90. />
  91. ) : (
  92. <Div w={67} h={67} bg="gray200" />
  93. )}
  94. <Div
  95. flex={1}
  96. ml={10}
  97. pb={4}
  98. borderColor="gray300"
  99. borderBottomWidth={1}
  100. >
  101. <Text size="xl" fontWeight="bold" textAlign="left">
  102. {showName}
  103. </Text>
  104. {tags.length > 0 && (
  105. <Div row my={3}>
  106. {tags.map((item, index) => {
  107. return (
  108. <Tag
  109. bg={getColor()}
  110. color="white"
  111. key={index}
  112. rounded="circle"
  113. fontSize="sm"
  114. py={2}
  115. ml={3}
  116. >
  117. {item.name}
  118. </Tag>
  119. );
  120. })}
  121. </Div>
  122. )}
  123. <Flex>
  124. <Flex>
  125. <Icon name="zan" type="primary" width={18} height={18} />
  126. <Text fontSize="sm" color="brand500" textAlign="left">
  127. {goodNum || 0}
  128. </Text>
  129. </Flex>
  130. <Flex style={styles.text}>
  131. <Icon name="zan" Flip color="#000" width={18} height={18} />
  132. <Text fontSize="sm" color="gray300" textAlign="left">
  133. {badNum || 0}
  134. </Text>
  135. </Flex>
  136. <Flex style={styles.text}>
  137. <Text size="c1" color="gray300" textAlign="left">
  138. 月售
  139. {monthSales}
  140. </Text>
  141. </Flex>
  142. </Flex>
  143. <Flex>
  144. <Text fontSize="sm" color="gray300" textAlign="left">
  145. 起送$
  146. {startingAmount || 0}
  147. </Text>
  148. <Flex.Item style={styles.text}>
  149. <Text fontSize="sm" color="gray300" textAlign="left">
  150. 配送$ 10
  151. </Text>
  152. </Flex.Item>
  153. <Text fontSize="sm" color="gray300" textAlign="left">
  154. {preparationTime || 60}
  155. 分钟
  156. </Text>
  157. {!!long && (
  158. <View style={styles.text}>
  159. <Text fontSize="sm" color="gray300" textAlign="left">
  160. {long}
  161. </Text>
  162. </View>
  163. )}
  164. </Flex>
  165. <Flex style={styles.label2}>
  166. <Chip size="mini" color="#FFE3B9" fontColor="#FF0000">
  167. “喜欢您来金拱门喜欢您来金拱门”
  168. </Chip>
  169. <Chip size="mini" color="#FFE3B9" fontColor="#FF0000">
  170. “喜欢您来金拱门喜欢您来金拱门”
  171. </Chip>
  172. </Flex>
  173. <Flex style={styles.label2} wrap="wrap">
  174. <Chip size="mini" outline color="#FF0000">
  175. 12减5
  176. </Chip>
  177. </Flex>
  178. </Div>
  179. </Div>
  180. </TouchableRipple>
  181. </Div>
  182. </SwipeAction>
  183. );
  184. }
  185. const styles = StyleSheet.create({
  186. image: {
  187. width: 67,
  188. height: 67,
  189. borderRadius: 3,
  190. },
  191. text: {
  192. marginLeft: 6,
  193. },
  194. label2: {
  195. marginTop: 4,
  196. overflow: 'hidden',
  197. },
  198. main: {
  199. marginLeft: 10,
  200. borderBottomWidth: 1,
  201. borderBottomColor: '#C9C9C9',
  202. paddingBottom: 4,
  203. },
  204. merchant: {
  205. paddingTop: 10,
  206. },
  207. });