123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- import DDComponents from '@/components/DDComponents';
- import React, { useMemo, useState } from 'react';
- import { Form } from '@ant-design/compatible';
- import '@ant-design/compatible/assets/index.css';
- const layout = {
- labelCol: {
- span: 8,
- },
- wrapperCol: {
- span: 16,
- },
- };
- const AuditDetailed = props => {
- // const [form] = Form.useForm();
- const { items, form } = props;
- const behavior = useMemo(() => {
- let data = {};
- items.forEach(d => {
- const item = d.props;
- if (item.behaviorLinkage) {
- const key = item.id;
- const options = item.options.map(o => {
- let data;
- try {
- data = JSON.parse(o);
- } catch (error) {
- data = { key: o, value: o };
- }
- return data;
- });
- item.behaviorLinkage.forEach(b => {
- const value = b.value;
- b.targets.forEach(t => {
- data[t.fieldId] = { key, value: options.find(o => o.key == value)?.value };
- });
- });
- }
- });
- return data;
- }, [items]);
- const onFinish = values => {
- console.log(values);
- };
- const GetComponent = item => {
- const {
- id,
- label,
- bizAlias,
- required,
- placeholder,
- options,
- align,
- statField,
- hideLabel,
- objOptions,
- format,
- pushToAttendance,
- labelEditableFreeze,
- requiredEditableFreeze,
- unit,
- extract,
- link,
- payEnable,
- bizType,
- childFieldVisible,
- notPrint,
- verticalPrint,
- hiddenInApprovalDetail,
- disabled,
- notUpper,
- children, // 子控件
- } = item.props;
- // 判断是否属于关联项
- if (behavior[id]) {
- const { key, value } = behavior[id];
- let currentValue = form.getFieldValue(key);
- try {
- currentValue = JSON.parse(currentValue);
- } catch (error) {}
- // 判断是否需要渲染
- if (currentValue instanceof Array) {
- if (currentValue?.indexOf(value) == -1) return null;
- } else {
- if (currentValue != value) return null;
- }
- }
- let formLabel;
- if (bizAlias) {
- formLabel = bizAlias;
- } else {
- try {
- // 判断label是否为JSON数组
- formLabel = JSON.parse(label).join(',');
- } catch (error) {
- formLabel = label;
- }
- }
- const component = DDComponents({ item });
- if (!component) return null;
- return (
- <Form.Item label={formLabel}>
- {form.getFieldDecorator(id, {
- rules: [{ required }],
- })(component)}
- {notUpper == 1 && <p>大写</p>}
- </Form.Item>
- );
- };
- return (
- <Form layout="vertical" autoComplete="off">
- {items.map(item => GetComponent(item))}
- </Form>
- );
- };
- export default AuditDetailed;
|