AuditDetailed.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import DDComponents from '@/components/DDComponents';
  2. import React, { useMemo, useState } from 'react';
  3. import { Form } from '@ant-design/compatible';
  4. import '@ant-design/compatible/assets/index.css';
  5. const layout = {
  6. labelCol: {
  7. span: 8,
  8. },
  9. wrapperCol: {
  10. span: 16,
  11. },
  12. };
  13. const AuditDetailed = props => {
  14. // const [form] = Form.useForm();
  15. const { items, form } = props;
  16. const behavior = useMemo(() => {
  17. let data = {};
  18. items.forEach(d => {
  19. const item = d.props;
  20. if (item.behaviorLinkage) {
  21. const key = item.id;
  22. const options = item.options.map(o => {
  23. let data;
  24. try {
  25. data = JSON.parse(o);
  26. } catch (error) {
  27. data = { key: o, value: o };
  28. }
  29. return data;
  30. });
  31. item.behaviorLinkage.forEach(b => {
  32. const value = b.value;
  33. b.targets.forEach(t => {
  34. data[t.fieldId] = { key, value: options.find(o => o.key == value)?.value };
  35. });
  36. });
  37. }
  38. });
  39. return data;
  40. }, [items]);
  41. const onFinish = values => {
  42. console.log(values);
  43. };
  44. const GetComponent = item => {
  45. const {
  46. id,
  47. label,
  48. bizAlias,
  49. required,
  50. placeholder,
  51. options,
  52. align,
  53. statField,
  54. hideLabel,
  55. objOptions,
  56. format,
  57. pushToAttendance,
  58. labelEditableFreeze,
  59. requiredEditableFreeze,
  60. unit,
  61. extract,
  62. link,
  63. payEnable,
  64. bizType,
  65. childFieldVisible,
  66. notPrint,
  67. verticalPrint,
  68. hiddenInApprovalDetail,
  69. disabled,
  70. notUpper,
  71. children, // 子控件
  72. } = item.props;
  73. // 判断是否属于关联项
  74. if (behavior[id]) {
  75. const { key, value } = behavior[id];
  76. let currentValue = form.getFieldValue(key);
  77. try {
  78. currentValue = JSON.parse(currentValue);
  79. } catch (error) {}
  80. // 判断是否需要渲染
  81. if (currentValue instanceof Array) {
  82. if (currentValue?.indexOf(value) == -1) return null;
  83. } else {
  84. if (currentValue != value) return null;
  85. }
  86. }
  87. let formLabel;
  88. if (bizAlias) {
  89. formLabel = bizAlias;
  90. } else {
  91. try {
  92. // 判断label是否为JSON数组
  93. formLabel = JSON.parse(label).join(',');
  94. } catch (error) {
  95. formLabel = label;
  96. }
  97. }
  98. const component = DDComponents({ item });
  99. if (!component) return null;
  100. return (
  101. <Form.Item label={formLabel}>
  102. {form.getFieldDecorator(id, {
  103. rules: [{ required }],
  104. })(component)}
  105. {notUpper == 1 && <p>大写</p>}
  106. </Form.Item>
  107. );
  108. };
  109. return (
  110. <Form layout="vertical" autoComplete="off">
  111. {items.map(item => GetComponent(item))}
  112. </Form>
  113. );
  114. };
  115. export default AuditDetailed;