import * as React from 'react'; import { View, SafeAreaView, Text, FlatList, TouchableHighlight } from 'react-native'; import { useDispatch, useSelector } from 'react-redux'; import { useFocusEffect, useNavigation } from '@react-navigation/native'; import { RematchDispatch, Models } from '@rematch/core'; import { ScreenNavigationProp } from '../../interface'; import WhenFocusStatusBar from '../../components/WhenFocusStatusBar'; import Loading from '../../components/Loading'; import Empty from '../../components/Empty'; import Price from '../../components/Price'; import CaiNiao from '../../icon/CaiNiao'; import { color } from '../../constants'; import { RootState } from '../../store'; import styles from './style'; interface IHistoryCardProps { data?:any; onCardPress(id:number):void } const HistoryCard:React.FC = ({ data, onCardPress }) => { return ( onCardPress(data.id)} underlayColor='#f9f9f9' style={styles.cardContainer}> <> {data.ctnNo} { data.eir && / {data.eir} } 箱主 {data.ctnOwner} 箱型尺寸 {data.ctnSizeType} 车牌 {data.numberPlate} {data.applyTime} ) } export default ():React.ReactElement => { const { history, inspection } = useDispatch>(); const { navigate } = useNavigation>(); const [ refreshing, setRefreshing ] = React.useState(false); const { data } = useSelector((state:RootState) => state.history); const loading = useSelector((state:RootState) => state.loading); const fetchHistorying:boolean = loading.effects.history.fetchHistory; useFocusEffect( React.useCallback(() => { history.fetchHistory() }, []) ); const handleCardPress = React.useCallback((id:number) => { inspection.reset(); function getCurrentRow() { const currentRow = data.filter((item:any) => item.ctnApply.id === id)[0]; const newCtnRepairParamsList = [...currentRow.ctnRepairParamsList] currentRow.ctnRepairParamsList = newCtnRepairParamsList.map(item => ({ ...item, _photos: [...item.photos] })); inspection.save(currentRow); if(currentRow.ctnApply.ctnOwner) { inspection.fetchRateByCtnOwner(currentRow.ctnApply.ctnOwner) } } setTimeout(getCurrentRow, 0) navigate('EditInspectContainer', { type: 'put' }); },[navigate, inspection, data]); const handleHistoryRefresh = React.useCallback(() => { setRefreshing(true); history.fetchHistory({ callback() { setRefreshing(false); } }) }, [setRefreshing]) return ( { fetchHistorying && !refreshing ? : data.length ? item.ctnApply.id+''} style={{flex: 1}} data={data} refreshing={refreshing} onRefresh={handleHistoryRefresh} renderItem={({item}) => ( )} contentContainerStyle={{paddingHorizontal: 12, paddingBottom: 12}} /> : history.fetchHistory()}/> } ) }