import type { TypeResult } from '@/pages/ApplyList/hooks'; import useUrlState from '@ahooksjs/use-url-state'; import { ProForm } from '@ant-design/pro-form'; import { Alert, Button, Input, Modal, Space, Typography } from 'antd'; import { useForm } from 'antd/es/form/Form'; import { useEffect, useRef, useState } from 'react'; import { history, useIntl } from 'umi'; import { auditPreview, multipleApplyBatch, multipleAuditPreview, postApplybatch } from './api'; import PreviewTable from './components/previewTable'; import style from './index.less'; import { getPreviewParams, getSubmitParams } from './util'; const { TextArea } = Input; const { Text } = Typography; type TMultipleDataSource = { appId: number; name: string; data: any; }[]; export type OpenType = { isopen?: boolean; appId?: number; data?: D; otherUsers?: U; packageData?: TypeResult; }; export interface AuditPreviewProps { openObj: OpenType; setOpenObj: (o: OpenType) => void; type?: 'single' | 'multiple'; } const AuditPreview = (props: AuditPreviewProps) => { const { openObj, setOpenObj, type = 'single' } = props; const { formatMessage } = useIntl(); const [submit, setSubmit] = useState(false); const [query] = useUrlState(); const [tableList, setTableList] = useState([]); const [multipleDataSource, setMultipleDataSource] = useState([]); const submitbtm = useRef(true); const [formReason] = useForm(); const { isopen: open, data: parentData, otherUsers, appId: parentAppId, packageData, } = openObj || {}; // 仅适用单应用申请(type === 'single') const { appId: urlAppId } = query || {}; const appId = parentAppId || urlAppId; const onCancel = () => { setOpenObj({ isopen: false }); setTableList([]); setMultipleDataSource([]); }; const requestPreview = async (value: any) => { try { if (type === 'single') { const { data } = await auditPreview(value); setTableList(data); } else { // 多组应用权限审批预览 const { data } = await multipleAuditPreview(value, packageData?.id); setMultipleDataSource(data); } } catch (e) { onCancel(); } }; const onSubmit = async () => { try { await formReason.validateFields(); const reason = formReason.getFieldValue('reason'); const proxyUserIds = type === 'single' ? parentData?.otherUsers?.map((item: any) => item.id) : otherUsers?.map((item: any) => item.id); if (type === 'single') { const params = { reason, proxyUserIds, ...getSubmitParams(parentData, appId), }; const { data } = await postApplybatch(params); history.push(`/applyDetail?chainId=${data?.chainIds?.[0]}`); } else if (Array.isArray(parentData)) { // 权限包 const submitData = parentData.map((item: any) => { return { proxyUserIds, ...getSubmitParams(item), }; }); const { data } = await multipleApplyBatch({ data: submitData, reason, multiAuditId: packageData?.id, }); history.push(`/batchApplyDetail?batchAuditId=${data?.batchAuditId}`); } setSubmit(false); submitbtm.current = true; } catch (e) { setSubmit(false); submitbtm.current = true; } }; useEffect(() => { formReason.resetFields(); if (open) { if (type === 'single') { requestPreview(getPreviewParams(parentData, appId)); return; } else if (type === 'multiple' && Array.isArray(parentData)) { requestPreview(parentData.map((item) => getPreviewParams(item))); } } // eslint-disable-next-line react-hooks/exhaustive-deps }, [open, appId]); return ( <> } > {open && ( )} {/* {open && type === 'single' ? ( ) : ( {multipleDataSource.map((item) => { return ( ); })} )} */} { if (!val) return true; return undefined; }, }, ]} label={formatMessage({ id: 'base.apply.reason' })} name={'reason'} >