HomeCategoryScreen.tsx 7.1 KB

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