import { StackScreenProps } from '@react-navigation/stack'; import * as React from 'react'; import * as Animatable from 'react-native-animatable'; import { Div, Button, Image, Text, Avatar, Icon } from 'react-native-magnus'; import { FlatList } from 'react-native-gesture-handler'; import { RefreshControl } from 'react-native'; import { useTranslation } from 'react-i18next'; import { useRequest } from 'ahooks'; import { FinancialType } from '../utils/MoneyUtils'; import { MonthDate, getSearchDate } from '../utils/TimeUtils'; import request from '../utils/RequestUtils'; import ReacordCom from './ReacordCom'; import { PopoverPicker } from '../utils/SystemUtils'; // import { PopoverPicker } from 'teaset'; interface Result { list: Item[]; last: boolean; current: number; } export default function MineRecordScreen({ navigation }: StackScreenProps) { const { t } = useTranslation(); const [type, settype] = React.useState('all'); const [show, setshow] = React.useState(false); const monthDate = new MonthDate(); const [showDate, setshowDate] = React.useState(monthDate.showList[0]); const [layout, setLayout] = React.useState(); const { data, loading, loadMore, loadingMore, reload } = useRequest( (d: Result | undefined) => { let current = 0; if (d && d.current) { current = Number(d.current) + 1; } return request.get(__DEV__ ? '/moneyRecord/all' : '/moneyRecord/my', { params: { query: { time: getSearchDate(showDate), type: type != 'all' ? type : '', }, size: 10, page: current, }, }); }, { refreshDeps: [showDate, type], formatResult: (response) => { return { list: response.content, current: response.number.toString(), last: response.last, empty: response.empty, }; }, isNoMore: (r: Result) => { if (r.last) { return true; } else { return false; } }, defaultLoading: false, debounceInterval: 1000, loadMore: true, } ); navigation.setOptions({ headerTitle: () => { let name = t('wo-de-dui-zhang-dan'); if (type !== 'all') { name += '(' + t(FinancialType.get(type).name) + ')'; } return ( ); }, }); return (
{show && (
{[...FinancialType.keys()].map((item, index) => { const info = FinancialType.get(item); return ( ); })}
)} } onEndReached={() => { if (!data.last && !loading && !loadingMore) { loadMore(); } }} onEndReachedThreshold={0.5} contentContainerStyle={{ flexGrow: 1, backgroundColor: '#f2f2f2', }} data={data.list} renderItem={({ item }) => { return (
); }} keyExtractor={(item) => item.id.toString()} onLayout={(e) => { console.log(e); }} ListFooterComponent={() => { return ( <> {!data.empty && ( {data.last ? t('dao-di-le') : t('jia-zai-zhong')} )} ); }} stickyHeaderIndices={[0]} ListEmptyComponent={() => { return ( <> {data.empty && ( {t('wu-shu-ju')} )} ); }} ListHeaderComponent={() => { return (
); }} />
); }