Center.jsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import Constants from 'expo-constants';
  4. import { StyleSheet, View, Image } from 'react-native';
  5. import { Text } from 'react-native-magnus';
  6. import { Flex } from '@ant-design/react-native';
  7. import { TouchableRipple } from 'react-native-paper';
  8. import { useRequest } from '@umijs/hooks';
  9. import useModel from 'flooks';
  10. import Icon from 'react-native-vector-icons/FontAwesome';
  11. import Detail from './model';
  12. import User from '../../flooks/User';
  13. import Chip from '../../components/Chip';
  14. import SvgIcon from '../../components/SvgIcon';
  15. export default function Center() {
  16. const { merchantInfo, like, delLike } = useModel(Detail, ['merchantInfo']);
  17. const { id } = useModel(User, ['id']);
  18. const {
  19. logo,
  20. showName,
  21. monthSales,
  22. goodNum,
  23. badNum,
  24. fullReductions,
  25. proclamation,
  26. mid,
  27. } = merchantInfo;
  28. const [Collection, setCollection] = React.useState({});
  29. const collectRequest = useRequest(
  30. () => {
  31. const params = {
  32. query: {
  33. merchantId: mid,
  34. userId: id,
  35. },
  36. };
  37. const urls = Object.keys(params).map((item) => {
  38. return `${item}=${encodeURI(JSON.stringify(params[item]))}`;
  39. });
  40. return `/myCollection/all?${urls.join('&')}`;
  41. },
  42. {
  43. refreshDeps: [mid],
  44. onSuccess: (result) => {
  45. if (!result.empty) {
  46. setCollection(result.content[0]);
  47. } else {
  48. setCollection({});
  49. }
  50. },
  51. }
  52. );
  53. return (
  54. <View style={styles.box}>
  55. <View style={styles.main}>
  56. <Flex>
  57. <Image
  58. style={styles.icon}
  59. resizeMode="cover"
  60. source={{ uri: logo }}
  61. />
  62. <Flex.Item style={styles.center}>
  63. <Text fontSize="xl" textAlign="center" fontWeight="bold">
  64. {showName}
  65. </Text>
  66. <Flex justify="space-around" style={styles.lab}>
  67. <Flex>
  68. <SvgIcon name="zan" type="primary" width={18} height={18} />
  69. <Text fontSize="sm" textAlign="left" color="brand500">
  70. {goodNum || 0}
  71. </Text>
  72. </Flex>
  73. <Flex style={styles.text}>
  74. <SvgIcon name="zan" Flip color="#000" width={18} height={18} />
  75. <Text fontSize="sm" textAlign="left" color="gray300">
  76. {badNum || 0}
  77. </Text>
  78. </Flex>
  79. <Flex style={styles.text}>
  80. <Text fontSize="sm" textAlign="left" color="gray300">
  81. 月售
  82. {monthSales}
  83. </Text>
  84. </Flex>
  85. </Flex>
  86. </Flex.Item>
  87. <TouchableRipple
  88. onPress={() => {
  89. Collection.id
  90. ? delLike(Collection.id).then(() => {
  91. collectRequest.run();
  92. })
  93. : like().then(() => {
  94. collectRequest.run();
  95. });
  96. }}
  97. style={styles.like}
  98. >
  99. <Icon
  100. name={Collection.id ? 'heart' : 'heart-o'}
  101. size={16}
  102. color="#FF0000"
  103. />
  104. </TouchableRipple>
  105. </Flex>
  106. {fullReductions && (
  107. <Flex style={styles.chips}>
  108. {fullReductions.map((item) => {
  109. return (
  110. <Chip size="mini" key={item.id} outline color="#FF0000">
  111. 满{item.fullAmount}减{item.minusAmount}
  112. </Chip>
  113. );
  114. })}
  115. </Flex>
  116. )}
  117. <Text fontSize="sm" color="gray500" mt={3} textAlign="center">
  118. {proclamation}
  119. </Text>
  120. </View>
  121. </View>
  122. );
  123. }
  124. const styles = StyleSheet.create({
  125. box: {
  126. marginBottom: -56 - Constants.statusBarHeight,
  127. zIndex: 12,
  128. backgroundColor: '#eee',
  129. },
  130. main: {
  131. marginHorizontal: 15,
  132. backgroundColor: '#fff',
  133. borderRadius: 3,
  134. padding: 10,
  135. marginTop: -20,
  136. },
  137. icon: {
  138. width: 53,
  139. height: 53,
  140. borderRadius: 3,
  141. },
  142. text: {
  143. marginLeft: 5,
  144. },
  145. like: {
  146. padding: 5,
  147. alignSelf: 'flex-start',
  148. },
  149. pro: {
  150. marginTop: 3,
  151. },
  152. center: {
  153. alignItems: 'center',
  154. paddingRight: 28,
  155. },
  156. lab: {
  157. minWidth: 180,
  158. },
  159. chips: {
  160. maxWidth: '80%',
  161. overflow: 'hidden',
  162. alignSelf: 'center',
  163. marginTop: 5,
  164. },
  165. });