MerchantCom.js 6.4 KB

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