AuditForm.js 1.9 KB
Newer Older
王绍森's avatar
王绍森 committed
1
import router from 'umi/router';
王绍森's avatar
王绍森 committed
2 3 4
import { Form, Spin } from 'antd';
import Shell from '@/baseComponent/Shell';
import { ModalInfo } from '@/baseComponent/Modal';
王绍森's avatar
王绍森 committed
5
import React, { useState, useEffect } from 'react';
王绍森's avatar
王绍森 committed
6 7
import { getHistoryFormDetail } from '../../Services';
import withGoBack from '@/highOrderComponent/withGoBack';
王绍森's avatar
王绍森 committed
8
import HistoryForm from '@/webPublic/FormInsertDiy/HistoryForm';
王绍森's avatar
王绍森 committed
9
import AuditButton from '../AuditButton';
10
import styles from '../RenderForm/index.less';
王绍森's avatar
王绍森 committed
11 12

let AuditForm = ({ code, isNewForm, form }) => {
13 14 15 16 17
	function submitCb(res) {
		ModalInfo(`提交${res ? '成功' : '失败'}!`, { onOk: () => router.goBack() });
	}
	const [data, setData] = useState(null);
	const [loading, setLoading] = useState(false);
王绍森's avatar
王绍森 committed
18

19 20 21 22 23 24 25 26 27 28
	useEffect(() => {
		if (typeof code === 'undefined') return;
		setLoading(true);
		getHistoryFormDetail({ code }).then((res) => {
			setLoading(false);
			if (res && !res.errMsg) {
				setData(res);
			}
		});
	}, []);
王绍森's avatar
王绍森 committed
29

30 31 32 33 34 35 36 37 38 39 40 41
	return (
		<Shell styleShell={{ marginTop: 0 }}>
			<Spin spinning={loading}>
				{data && (
					<>
						<div className={styles.zyd_onestop_style_class}>
							<HistoryForm
								data={data} // 'affair/getIdFormDetail' 接口返回数据
								form={form} // form控件
								isNewForm={!!isNewForm} // 是否渲染需要当前用户填写的审核表单 为false只会渲染历史回显表单
							/>
						</div>
42

43 44 45 46 47 48 49 50 51 52 53 54 55 56
						{isNewForm && (
							<div style={{ padding: 16, textAlign: 'center' }}>
								<AuditButton
									data={data} // 为 'affair/getIdFormDetail' 接口请求到的数据
									callback={submitCb} // 提交完成后回调函数
									form={form} // form表单控件
								/>
							</div>
						)}
					</>
				)}
			</Spin>
		</Shell>
	);
王绍森's avatar
王绍森 committed
57 58 59 60 61
};

AuditForm = Form.create()(AuditForm);

export default ({ hasGoBack = true, ...rest }) => {
62 63
	const WithGoBack = withGoBack(AuditForm);
	return hasGoBack ? <WithGoBack {...rest} /> : <AuditForm {...rest} />;
王绍森's avatar
王绍森 committed
64
};