FormAndFilesNode.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { Card, Col, Input, Row, Modal, Empty, Collapse } from 'antd';
  2. import { Form } from '@ant-design/compatible';
  3. import { useForm } from 'antd/lib/form/Form';
  4. import React, { useMemo, useState } from 'react';
  5. import { connect } from 'dva';
  6. import CommentContent from '@/components/CommentContent';
  7. import AttachmentTable from '@/components/AttachmentTable';
  8. import DIYTable from '@/components/DDComponents/DIYTable';
  9. const { confirm } = Modal;
  10. const { Panel } = Collapse;
  11. const FormAndFilesNode = props => {
  12. const { formData, excelFileList, comment, version, loading } = props;
  13. const FormContent = useMemo(() => {
  14. return renderFrom(formData);
  15. }, [formData]);
  16. if (formData) {
  17. return (
  18. <Card title="审批信息">
  19. <Row gutter={20}>
  20. <Col span={12}>{FormContent}</Col>
  21. <Col span={12}>
  22. <AttachmentTable version={version} canDelete={version.last_version == 0} />
  23. </Col>
  24. </Row>
  25. </Card>
  26. );
  27. }
  28. if (excelFileList?.length > 0) {
  29. return (
  30. <Card title="附件信息">
  31. <AttachmentTable version={version} canDelete={version.last_version == 0} />
  32. </Card>
  33. );
  34. }
  35. return null;
  36. };
  37. const renderFrom = data => {
  38. if (!data) return <Empty description="没有表单信息" />;
  39. try {
  40. const ding_schema = JSON.parse(data)[0];
  41. const formData = JSON.parse(ding_schema)?.formComponentValues;
  42. formData.forEach(item => {
  43. if (item.type === 'DIYTable') {
  44. item.value = item.value.map(row => JSON.parse(row));
  45. }
  46. });
  47. if (formData.length == 0) return <Empty description="没有表单信息" />;
  48. return (
  49. <>
  50. {formData.map((item, idx) => {
  51. if (item.type === 'DIYTable') {
  52. return (
  53. <Form.Item
  54. key={`FormAndFilesNode_${item.id}`}
  55. labelCol={{ span: 4 }}
  56. wrapperCol={{ span: 14 }}
  57. label={item.name}
  58. >
  59. <DIYTable key={item.id} table={item} columns={item.value} displayOnly />
  60. </Form.Item>
  61. );
  62. }
  63. const value = item.value.join(',');
  64. return (
  65. <Form.Item
  66. key={`FormAndFilesNode_${item.id}`}
  67. labelCol={{ span: 4 }}
  68. wrapperCol={{ span: 14 }}
  69. label={item.name}
  70. >
  71. <div
  72. style={{
  73. width: '100%',
  74. paddingLeft: '20px',
  75. backgroundColor: '#ececef',
  76. border: '1px solid #bcb9b9',
  77. borderRadius: '4px',
  78. minHeight: '40px',
  79. }}
  80. >
  81. {value}
  82. </div>
  83. </Form.Item>
  84. );
  85. })}
  86. </>
  87. );
  88. } catch {
  89. return <Empty description="没有表单信息" />;
  90. }
  91. };
  92. export default connect(({ detail, loading }) => ({
  93. comment: detail.comment,
  94. loading,
  95. }))(FormAndFilesNode);