AuditDetailed.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. let watchList = {};
  19. items.forEach(d => {
  20. const item = d.props;
  21. if (item.behaviorLinkage) {
  22. const key = item.id;
  23. item.behaviorLinkage.forEach(b => {
  24. const value = b.value;
  25. b.targets.forEach(t => {
  26. data[t.fieldId] = { key, value };
  27. });
  28. watchList[key] = true;
  29. });
  30. }
  31. });
  32. return data;
  33. }, [items]);
  34. const onFinish = values => {
  35. console.log(values);
  36. };
  37. const GetComponent = item => {
  38. const {
  39. id,
  40. label,
  41. bizAlias,
  42. required,
  43. placeholder,
  44. options,
  45. align,
  46. statField,
  47. hideLabel,
  48. objOptions,
  49. format,
  50. pushToAttendance,
  51. labelEditableFreeze,
  52. requiredEditableFreeze,
  53. unit,
  54. extract,
  55. link,
  56. payEnable,
  57. bizType,
  58. childFieldVisible,
  59. notPrint,
  60. verticalPrint,
  61. hiddenInApprovalDetail,
  62. disabled,
  63. notUpper,
  64. children, // 子控件
  65. } = item.props;
  66. // 判断是否属于关联项
  67. if (behavior[id]) {
  68. const { key, value } = behavior[id];
  69. let currentValue = form.getFieldValue(key);
  70. // 判断是否需要渲染
  71. if (currentValue instanceof Array) {
  72. if (currentValue?.indexOf(value) == -1) return null;
  73. } else {
  74. if (currentValue != value) return null;
  75. }
  76. }
  77. const component = DDComponents({ item });
  78. if (!component) return null;
  79. return (
  80. <Form.Item label={bizAlias || label}>
  81. {form.getFieldDecorator(id, {
  82. rules: [{ required }],
  83. })(component)}
  84. {notUpper == 1 && <p>大写</p>}
  85. </Form.Item>
  86. );
  87. };
  88. return (
  89. <Form layout="vertical" autoComplete="off">
  90. {items.map(item => GetComponent(item))}
  91. </Form>
  92. );
  93. };
  94. export default AuditDetailed;