EditPage.js 1.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
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) {
  ModalInfo(`提交${res ? '成功' : '失败'}!`);
}

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

  useEffect(() => {
20
    if (typeof draftCode === 'undefined') return;
21
    setLoading(true);
22
    getHistoryFormDetail({ code: draftCode }).then(res => {
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
      setLoading(false);
      if (res && !res.errMsg) {
        setData(res);
      }
    });
  }, []);


  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}
41
                draftCode={draftCode}
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
                text="提交"
                openDraftButton
                DraftButtonText="暂存"
                callback={submitCb}
              />
            </div>
          </>
        )}
      </Spin>
    </Shell>
  );
};

EditPage = Form.create()(EditPage);

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