FormAndFilesNode.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { Card, Col, Row, Empty } from 'antd';
  2. import { Form, Table } from 'antd';
  3. import { useMemo, useState } from 'react';
  4. import { useModel } from 'umi';
  5. import AttachmentTable from '@/components/AttachmentTable';
  6. import InnerContactField from '@/components/DDComponents/InnerContactField';
  7. import DepartmentField from '@/components/DDComponents/DepartmentField';
  8. import ProjectField from '@/components/DDComponents/ProjectField';
  9. import DIYTable from '../../../components/DDComponents/DIYTable';
  10. const FormAndFilesNode = (props) => {
  11. const { formData, fileList } = props;
  12. const renderFormItem = (type, value, item) => {
  13. switch (type) {
  14. case 'InnerContactField':
  15. return <InnerContactField value={value} disabled={true} />;
  16. case 'DepartmentField':
  17. return <DepartmentField value={value} disabled={true} />;
  18. case 'ProjectField':
  19. return <ProjectField value={value} disabled={true} />;
  20. default:
  21. return (
  22. <div
  23. style={{
  24. width: '100%',
  25. padding: '4px 12px',
  26. backgroundColor: 'rgb(0,0,0,0.04)',
  27. border: '1px solid #D9D9D9',
  28. borderRadius: '6px',
  29. color: 'rgb(0,0,0,0.25) ',
  30. }}
  31. >
  32. {value}
  33. </div>
  34. );
  35. }
  36. };
  37. const renderForm = (data) => {
  38. if (!data) return <Empty description="没有表单信息" />;
  39. try {
  40. const formData = JSON.parse(data);
  41. if (formData.length === 0) return <Empty description="没有表单信息" />;
  42. return (
  43. <>
  44. {formData.map((item, idx) => {
  45. const value = item.value.join(',');
  46. return (
  47. <>
  48. {item.type !== 'DIYTable' ? (
  49. <Form.Item
  50. key={`FormAndFilesNode_${idx}`}
  51. labelCol={{ span: 4 }}
  52. wrapperCol={{ span: 14 }}
  53. label={item.name}
  54. labelAlign="left"
  55. >
  56. {renderFormItem(item.type, value, item)}
  57. </Form.Item>
  58. ) : (
  59. <div style={{ marginBottom: '24px' }}>
  60. <DIYTable
  61. table={item}
  62. columns={item.value}
  63. displayOnly={true}
  64. ></DIYTable>
  65. </div>
  66. )}
  67. </>
  68. );
  69. })}
  70. </>
  71. );
  72. } catch {
  73. return <Empty description="没有表单信息" />;
  74. }
  75. };
  76. const FormContent = useMemo(() => {
  77. return renderForm(formData);
  78. }, [formData]);
  79. return (
  80. <Card title="审批信息">
  81. <Row gutter={20}>
  82. <Col span={12}>{FormContent}</Col>
  83. <Col span={12}>
  84. <AttachmentTable excelFileList={fileList} />
  85. </Col>
  86. </Row>
  87. </Card>
  88. );
  89. };
  90. export default FormAndFilesNode;