MerchantCom.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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) {
  52. return `${(distance / 1000).toFixed(2)}km`;
  53. } else {
  54. return false;
  55. }
  56. }, [distance]);
  57. const right = [
  58. {
  59. text: t('shan-chu'),
  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. {t('yue-shou')}
  139. {monthSales}
  140. </Text>
  141. </Flex>
  142. </Flex>
  143. <Flex>
  144. <Text fontSize="sm" color="gray300" textAlign="left">
  145. {t('qi-song')}${startingAmount || 0}
  146. </Text>
  147. <Flex.Item style={styles.text}>
  148. <Text fontSize="sm" color="gray300" textAlign="left">
  149. {t('pei-song')}$ 10
  150. </Text>
  151. </Flex.Item>
  152. <Text fontSize="sm" color="gray300" textAlign="left">
  153. {preparationTime || 60}
  154. {t('fen-zhong')}
  155. </Text>
  156. {!!long && (
  157. <View style={styles.text}>
  158. <Text fontSize="sm" color="gray300" textAlign="left">
  159. {long}
  160. </Text>
  161. </View>
  162. )}
  163. </Flex>
  164. {/* <Flex style={styles.label2}>
  165. <Chip size="mini" color="#FFE3B9" fontColor="#FF0000">
  166. {t(
  167. 'xi-huan-nin-lai-jin-gong-men-xi-huan-nin-lai-jin-gong-men'
  168. )}
  169. </Chip>
  170. <Chip size="mini" color="#FFE3B9" fontColor="#FF0000">
  171. “喜欢您来金拱门喜欢您来金拱门”
  172. </Chip>
  173. </Flex> */}
  174. <Flex style={styles.label2} wrap="wrap">
  175. <Chip size="mini" outline color="#FF0000">
  176. 12{t('jian')}5
  177. </Chip>
  178. </Flex>
  179. </Div>
  180. </Div>
  181. </TouchableRipple>
  182. </Div>
  183. </SwipeAction>
  184. );
  185. }
  186. const styles = StyleSheet.create({
  187. image: {
  188. width: 67,
  189. height: 67,
  190. borderRadius: 3,
  191. },
  192. text: {
  193. marginLeft: 6,
  194. },
  195. label2: {
  196. marginTop: 4,
  197. overflow: 'hidden',
  198. },
  199. main: {
  200. marginLeft: 10,
  201. borderBottomWidth: 1,
  202. borderBottomColor: '#C9C9C9',
  203. paddingBottom: 4,
  204. },
  205. merchant: {
  206. paddingTop: 10,
  207. },
  208. });