| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- /* eslint-disable no-shadow */
- import * as WebBrowser from 'expo-web-browser';
- import * as React from 'react';
- import { Animated, Dimensions } from 'react-native';
- import { Div, Button, Text, Icon } from 'react-native-magnus';
- import { useBoolean, useCreation } from '@umijs/hooks';
- import { useTranslation } from 'react-i18next';
- import { useAnimation } from 'react-native-animation-hooks';
- import useModel from 'flooks';
- import HomeModel from './model';
- import { sortMap, filterMap, tagMap } from '../../../Utils/MerchantUtils';
- import Filter from './Filter';
- export default function List({
- animatedScrollYValue,
- topHeight,
- setscrollEnabled,
- }) {
- const { t } = useTranslation();
- const SortMenu = useBoolean(false);
- const filterMenu = useBoolean(false);
- const {
- sort,
- changeSort,
- merchantNatureList,
- getNature,
- clearFiliter,
- ChangeFiliter,
- filter,
- tag,
- natureId,
- endAmount,
- } = useModel(HomeModel, [
- 'sort',
- 'merchantNatureList',
- 'filter',
- 'tag',
- 'natureId',
- 'endAmount',
- ]);
- React.useEffect(() => {
- if (merchantNatureList.length === 0) {
- getNature();
- // setscrollEnabled(false);
- }
- }, [merchantNatureList]);
- const top = useCreation(() => {
- return topHeight ? topHeight + 56 : 200;
- }, [topHeight]);
- const translateY = animatedScrollYValue.interpolate({
- inputRange: [-1, 0, top, top + 1],
- outputRange: [0, 0, 0, 1],
- });
- const soltType = useCreation(() => {
- return 'first';
- }, [sort]);
- const sortInfo = useCreation(() => {
- return sortMap.get(sort);
- }, [sort]);
- const SortHeight = useAnimation({
- type: 'timing',
- initialValue: 0,
- duration: 100,
- toValue: SortMenu.state ? 230 : 0,
- });
- return (
- <>
- <Animated.View
- style={{
- zIndex: 100,
- backgroundColor: 'rgba(0,0,0,0)',
- transform: [{ translateY }],
- }}
- >
- <Div row bg="white">
- <Button
- onPress={SortMenu.setTrue}
- bg="hide"
- fontSize="xl"
- px={10}
- color={soltType === 'first' ? 'brand500' : 'gray600'}
- >
- {t('tui-jian-shang-jia')}
- </Button>
- {/* <View style={{ width: 33 }} /> */}
- <Button
- bg="hide"
- fontSize="xl"
- color="gray600"
- px={10}
- mx={10}
- onPress={() => {}}
- >
- {t('fa-xian-mei-shi')}
- </Button>
- </Div>
- <Div row bg="white" alignItems="center">
- <Button
- onPress={() => {
- SortMenu.toggle();
- filterMenu.setFalse();
- }}
- bg="hide"
- px={10}
- >
- <Text
- fontSize="xs"
- color={
- sort && sortInfo.showType !== 'top' ? 'brand500' : 'gray600'
- }
- >
- {sortInfo.showType !== 'top'
- ? sortInfo.name
- : sortMap.get('').name}
- </Text>
- <Icon
- name="down"
- fontSize="xs"
- color={
- sort && sortInfo.showType !== 'top' ? 'brand500' : 'gray600'
- }
- />
- </Button>
- <Button
- fontSize="xs"
- bg="hide"
- color={sort === '7' ? 'brand500' : 'gray600'}
- px={10}
- onPress={() => {
- changeSort('7');
- SortMenu.setFalse();
- filterMenu.setFalse();
- }}
- >
- {t('ju-li')}
- </Button>
- <Button
- fontSize="xs"
- bg="hide"
- color={sort === '8' ? 'brand500' : 'gray600'}
- px={10}
- onPress={() => {
- changeSort('8');
- SortMenu.setFalse();
- filterMenu.setFalse();
- }}
- >
- {t('xiao-liang')}
- </Button>
- <Div flex={1} />
- <Button
- onPress={() => {
- filterMenu.toggle();
- SortMenu.setFalse();
- }}
- bg="hide"
- px={10}
- >
- <Text fontSize="xs" color="gray600">
- {t('shai-xuan')}
- </Text>
- <Icon
- name="down"
- fontSize="xs"
- color={
- sort && sortInfo.showType !== 'top' ? 'brand500' : 'gray600'
- }
- />
- </Button>
- </Div>
- <Animated.View
- style={{
- height: SortHeight,
- overflow: 'hidden',
- backgroundColor: '#fff',
- }}
- >
- {[...sortMap.keys()].map((item, index) => {
- const info = sortMap.get(item);
- return info.showType !== 'top' ? (
- <Button
- key={index}
- block
- bg="white"
- rounded="none"
- onPress={() => {
- SortMenu.setFalse();
- changeSort(item);
- }}
- >
- <Text
- fontSize="xs"
- flex={1}
- color={sort === item ? 'brand500' : 'gray600'}
- >
- {info.name}
- </Text>
- </Button>
- ) : (
- <></>
- );
- })}
- </Animated.View>
- <Filter
- show={filterMenu.state}
- merchantNatureList={merchantNatureList}
- filters={filter}
- tags={tag}
- natureId={natureId}
- endAmount={endAmount}
- clear={() => {
- filterMenu.setFalse();
- clearFiliter();
- }}
- submit={(filter, tag, natureId, endAmount) => {
- filterMenu.setFalse();
- }}
- />
- </Animated.View>
- {(SortMenu.state || filterMenu.state) && (
- <Button
- bg="black600"
- position="absolute"
- top={top + 60}
- left={0}
- right={0}
- bottom={0}
- zIndex={2}
- onPress={() => {
- SortMenu.setFalse();
- filterMenu.setFalse();
- }}
- />
- )}
- </>
- );
- }
|