import { Button, Typography } from 'antd'; import { Flex } from 'antd5'; import qs from 'querystring'; import { useMemo } from 'react'; import { history, useIntl, useRequest } from 'umi'; export interface SwitchApplyDetailProps { batchAuditId?: string | null; currentChainId?: string; } const SwitchApplyDetail = (props: SwitchApplyDetailProps) => { const { batchAuditId, currentChainId } = props; const { formatMessage } = useIntl(); const { data, loading } = useRequest(() => ({ url: '/goapi/audit/pending/list', method: 'POST', data: { condition: { state: 2, }, pagination: { page: 1, size: 999999, }, }, })); const { list, pagination } = data ?? {}; const currentIndex = useMemo(() => { if (Array.isArray(list)) { return list.findIndex((o) => { if (batchAuditId) { return batchAuditId === o.batchAuditId; } return o.chainId === currentChainId; }); } return -1; }, [batchAuditId, currentChainId, list]); const goDetail = (record: any) => { const o: Record = { showSwitch: true, }; if (record.batchAuditId) { o.batchAuditId = record.batchAuditId; history.replace({ pathname: '/batchApplyDetail', search: qs.stringify(o), state: { fromApply: true }, }); } else { o.chainId = record.chainId; history.replace({ pathname: '/applyDetail', search: qs.stringify(o), state: { fromApply: true }, }); } }; const onPrev = () => { goDetail(list?.[currentIndex - 1]); }; const onNext = () => { goDetail(list?.[currentIndex + 1]); }; return ( {formatMessage( { id: 'public.switch.apply.detail.title' }, { index: currentIndex >= 0 ? currentIndex + 1 : 1, count: pagination?.total ?? 0 }, )} ); }; export default SwitchApplyDetail;