EditPage.js 1.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
import React, { useState, useEffect } from 'react';
import { Form, Spin } from 'antd';
import Shell from '@/baseComponent/Shell';
import { getHistoryFormDetail } from '../../Services';
import withGoBack from '@/highOrderComponent/withGoBack';
import SubmitButton from '@/webPublic/one_stop_public/AffairButton/SumbitButton';
import { ModalInfo } from '@/baseComponent/Modal';
import RenderForm from '../RenderForm';

function submitCb(res) {
11
	ModalInfo(`提交${res ? '成功' : '失败'}!`);
12 13
}

14 15
// 编辑草稿,传入应用id和草稿code
let EditPage = ({ form, appId, draftCode }) => {
16 17
	const [data, setData] = useState(null);
	const [loading, setLoading] = useState(false);
18

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

30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
	return (
		<Shell styleShell={{ marginTop: 0 }}>
			<Spin spinning={loading}>
				{data && (
					<>
						<RenderForm postData={data} form={form} isCg="yes" />
						<div style={{ padding: 16, textAlign: 'center' }}>
							<SubmitButton
								form={form}
								appId={appId}
								draftCode={draftCode}
								text="提交"
								openDraftButton
								DraftButtonText="暂存"
								callback={submitCb}
							/>
						</div>
					</>
				)}
			</Spin>
		</Shell>
	);
52 53 54 55 56
};

EditPage = Form.create()(EditPage);

export default ({ hasGoBack = true, ...rest }) => {
57 58
	const WithGoBack = withGoBack(EditPage);
	return hasGoBack ? <WithGoBack {...rest} /> : <EditPage {...rest} />;
59
};