FormAndFilesNode.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 => {
  45. const sss = JSON.parse(row);
  46. const s = JSON.parse(sss);
  47. return s;
  48. });
  49. }
  50. });
  51. if (formData.length == 0) return <Empty description="没有表单信息" />;
  52. return (
  53. <>
  54. {formData.map((item, idx) => {
  55. if (item.type === 'DIYTable') {
  56. return (
  57. <Form.Item
  58. key={`FormAndFilesNode_${item.id}`}
  59. labelCol={{ span: 4 }}
  60. wrapperCol={{ span: 14 }}
  61. label={item.name}
  62. >
  63. <DIYTable key={item.id} table={item} columns={item.value} displayOnly />
  64. </Form.Item>
  65. );
  66. }
  67. const value = item.value.join(',');
  68. return (
  69. <Form.Item
  70. key={`FormAndFilesNode_${item.id}`}
  71. labelCol={{ span: 4 }}
  72. wrapperCol={{ span: 14 }}
  73. label={item.name}
  74. >
  75. <div
  76. style={{
  77. width: '100%',
  78. paddingLeft: '20px',
  79. backgroundColor: '#ececef',
  80. border: '1px solid #bcb9b9',
  81. borderRadius: '4px',
  82. minHeight: '40px',
  83. }}
  84. >
  85. {value}
  86. </div>
  87. </Form.Item>
  88. );
  89. })}
  90. </>
  91. );
  92. } catch {
  93. return <Empty description="没有表单信息" />;
  94. }
  95. };
  96. export default connect(({ detail, loading }) => ({
  97. comment: detail.comment,
  98. loading,
  99. }))(FormAndFilesNode);