ListTop.jsx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /* eslint-disable no-shadow */
  2. import * as WebBrowser from 'expo-web-browser';
  3. import * as React from 'react';
  4. import { Animated, Dimensions } from 'react-native';
  5. import { Div, Button, Text, Icon } from 'react-native-magnus';
  6. import { useBoolean, useCreation } from '@umijs/hooks';
  7. import { useTranslation } from 'react-i18next';
  8. import { useAnimation } from 'react-native-animation-hooks';
  9. import useModel from 'flooks';
  10. import HomeModel from './model';
  11. import { sortMap, filterMap, tagMap } from '../../../Utils/MerchantUtils';
  12. import Filter from './Filter';
  13. export default function List({
  14. animatedScrollYValue,
  15. topHeight,
  16. setscrollEnabled,
  17. }) {
  18. const { t } = useTranslation();
  19. const SortMenu = useBoolean(false);
  20. const filterMenu = useBoolean(false);
  21. const {
  22. sort,
  23. changeSort,
  24. merchantNatureList,
  25. getNature,
  26. clearFiliter,
  27. ChangeFiliter,
  28. filter,
  29. tag,
  30. natureId,
  31. endAmount,
  32. } = useModel(HomeModel, [
  33. 'sort',
  34. 'merchantNatureList',
  35. 'filter',
  36. 'tag',
  37. 'natureId',
  38. 'endAmount',
  39. ]);
  40. React.useEffect(() => {
  41. if (merchantNatureList.length === 0) {
  42. getNature();
  43. // setscrollEnabled(false);
  44. }
  45. }, [merchantNatureList]);
  46. const top = useCreation(() => {
  47. return topHeight ? topHeight + 56 : 200;
  48. }, [topHeight]);
  49. const translateY = animatedScrollYValue.interpolate({
  50. inputRange: [-1, 0, top, top + 1],
  51. outputRange: [0, 0, 0, 1],
  52. });
  53. const soltType = useCreation(() => {
  54. return 'first';
  55. }, [sort]);
  56. const sortInfo = useCreation(() => {
  57. return sortMap.get(sort);
  58. }, [sort]);
  59. const SortHeight = useAnimation({
  60. type: 'timing',
  61. initialValue: 0,
  62. duration: 100,
  63. toValue: SortMenu.state ? 230 : 0,
  64. });
  65. return (
  66. <>
  67. <Animated.View
  68. style={{
  69. zIndex: 100,
  70. backgroundColor: 'rgba(0,0,0,0)',
  71. transform: [{ translateY }],
  72. }}
  73. >
  74. <Div row bg="white">
  75. <Button
  76. onPress={SortMenu.setTrue}
  77. bg="hide"
  78. fontSize="xl"
  79. px={10}
  80. color={soltType === 'first' ? 'brand500' : 'gray600'}
  81. >
  82. {t('tui-jian-shang-jia')}
  83. </Button>
  84. {/* <View style={{ width: 33 }} /> */}
  85. <Button
  86. bg="hide"
  87. fontSize="xl"
  88. color="gray600"
  89. px={10}
  90. mx={10}
  91. onPress={() => {}}
  92. >
  93. {t('fa-xian-mei-shi')}
  94. </Button>
  95. </Div>
  96. <Div row bg="white" alignItems="center">
  97. <Button
  98. onPress={() => {
  99. SortMenu.toggle();
  100. filterMenu.setFalse();
  101. }}
  102. bg="hide"
  103. px={10}
  104. >
  105. <Text
  106. fontSize="xs"
  107. color={
  108. sort && sortInfo.showType !== 'top' ? 'brand500' : 'gray600'
  109. }
  110. >
  111. {sortInfo.showType !== 'top'
  112. ? sortInfo.name
  113. : sortMap.get('').name}
  114. </Text>
  115. <Icon
  116. name="down"
  117. fontSize="xs"
  118. color={
  119. sort && sortInfo.showType !== 'top' ? 'brand500' : 'gray600'
  120. }
  121. />
  122. </Button>
  123. <Button
  124. fontSize="xs"
  125. bg="hide"
  126. color={sort === '7' ? 'brand500' : 'gray600'}
  127. px={10}
  128. onPress={() => {
  129. changeSort('7');
  130. SortMenu.setFalse();
  131. filterMenu.setFalse();
  132. }}
  133. >
  134. {t('ju-li')}
  135. </Button>
  136. <Button
  137. fontSize="xs"
  138. bg="hide"
  139. color={sort === '8' ? 'brand500' : 'gray600'}
  140. px={10}
  141. onPress={() => {
  142. changeSort('8');
  143. SortMenu.setFalse();
  144. filterMenu.setFalse();
  145. }}
  146. >
  147. {t('xiao-liang')}
  148. </Button>
  149. <Div flex={1} />
  150. <Button
  151. onPress={() => {
  152. filterMenu.toggle();
  153. SortMenu.setFalse();
  154. }}
  155. bg="hide"
  156. px={10}
  157. >
  158. <Text fontSize="xs" color="gray600">
  159. {t('shai-xuan')}
  160. </Text>
  161. <Icon
  162. name="down"
  163. fontSize="xs"
  164. color={
  165. sort && sortInfo.showType !== 'top' ? 'brand500' : 'gray600'
  166. }
  167. />
  168. </Button>
  169. </Div>
  170. <Animated.View
  171. style={{
  172. height: SortHeight,
  173. overflow: 'hidden',
  174. backgroundColor: '#fff',
  175. }}
  176. >
  177. {[...sortMap.keys()].map((item, index) => {
  178. const info = sortMap.get(item);
  179. return info.showType !== 'top' ? (
  180. <Button
  181. key={index}
  182. block
  183. bg="white"
  184. rounded="none"
  185. onPress={() => {
  186. SortMenu.setFalse();
  187. changeSort(item);
  188. }}
  189. >
  190. <Text
  191. fontSize="xs"
  192. flex={1}
  193. color={sort === item ? 'brand500' : 'gray600'}
  194. >
  195. {info.name}
  196. </Text>
  197. </Button>
  198. ) : (
  199. <></>
  200. );
  201. })}
  202. </Animated.View>
  203. <Filter
  204. show={filterMenu.state}
  205. merchantNatureList={merchantNatureList}
  206. filters={filter}
  207. tags={tag}
  208. natureId={natureId}
  209. endAmount={endAmount}
  210. clear={() => {
  211. filterMenu.setFalse();
  212. clearFiliter();
  213. }}
  214. submit={(filter, tag, natureId, endAmount) => {
  215. filterMenu.setFalse();
  216. }}
  217. />
  218. </Animated.View>
  219. {(SortMenu.state || filterMenu.state) && (
  220. <Button
  221. bg="black600"
  222. position="absolute"
  223. top={top + 60}
  224. left={0}
  225. right={0}
  226. bottom={0}
  227. zIndex={2}
  228. onPress={() => {
  229. SortMenu.setFalse();
  230. filterMenu.setFalse();
  231. }}
  232. />
  233. )}
  234. </>
  235. );
  236. }