import { Form, Button, Switch, Input, Radio, Space, Row } from 'antd';
import React, { useMemo, useState, useEffect } from 'react';
import { DeleteOutlined } from '@ant-design/icons';
function ItemAttribute(props) {
const { item, onChange, onRelClick } = props;
if (!item) return null;
const renderForm = () => {
let FormContent;
const formProps = {
btns: (
),
item,
onFinish: (values) => {
console.log(values);
onChange?.(values);
},
};
switch (item.componentName) {
case 'InnerContactField':
FormContent = ;
break;
case 'DepartmentField':
FormContent = ;
break;
case 'ProjectField':
FormContent = ;
break;
case 'ManufacturerField':
FormContent = ;
break;
case 'TextField':
FormContent = ;
break;
case 'TextareaField':
FormContent = ;
break;
case 'DDSelectField':
FormContent = ;
break;
case 'DDMultiSelectField':
FormContent = ;
break;
case 'NumberField':
FormContent = ;
break;
case 'TextNote':
FormContent = ;
break;
case 'DDAttachment':
FormContent = ;
break;
case 'DDDateField':
FormContent = ;
break;
}
return FormContent;
};
return (
{renderForm()}
);
}
export default ItemAttribute;
function InnerContactField(props) {
const { item, btns, onFinish } = props;
const [form] = Form.useForm();
const onSwitchChange = (checked) => {
form.setFieldValue('choice', checked ? 1 : 0);
};
return (
只能选择一人
可同时选择多人
{btns}
);
}
function DepartmentField(props) {
const { item, btns, onFinish } = props;
const [form] = Form.useForm();
return (
只能选择一人
可同时选择多人
{btns}
);
}
function ProjectField(props) {
const { item, btns, onFinish } = props;
const [form] = Form.useForm();
return (
{btns}
);
}
function ManufacturerField(props) {
const { item, btns, onFinish } = props;
const [form] = Form.useForm();
return (
{btns}
);
}
function TextField(props) {
const { item, btns, onFinish } = props;
const [form] = Form.useForm();
const onReset = () => {
form.resetFields();
};
return (
{btns}
);
}
function DDAttachment(props) {
const { item, btns, onFinish } = props;
const [form] = Form.useForm();
return (
{btns}
);
}
function TextNote(props) {
const { item, btns, onFinish } = props;
const [form] = Form.useForm();
return (
{btns}
);
}
function DDDateField(props) {
const { item, btns, onFinish } = props;
const [form] = Form.useForm();
return (
{btns}
);
}
function TextareaField(props) {
const { item, btns, onFinish } = props;
const [form] = Form.useForm();
return (
{btns}
);
}
function DDSelectField(props) {
const { item, btns, onFinish, onRelClick } = props;
const [form] = Form.useForm();
const handleFinish = (value) => {
let tempValue = { ...value };
let arr = [];
tempValue.options.map((item) => {
arr.push(item.value);
});
if (arr) {
arr = arr.filter((item) => item);
arr = [...new Set(arr)];
tempValue.options = arr;
}
onFinish?.(tempValue);
};
return (
{btns}
);
}
function DDMultiSelectField(props) {
const { item, btns, onFinish } = props;
const [form] = Form.useForm();
const handleFinish = (value) => {
let tempValue = { ...value };
let arr = [];
tempValue.options.map((item) => {
arr.push(item.value);
});
if (arr) {
arr = arr.filter((item) => item);
arr = [...new Set(arr)];
tempValue.options = arr;
}
onFinish?.(tempValue);
};
return (
{btns}
);
}
function SelectItem(props) {
const { value, onChange, onRelClick } = props;
const [localValue, setLocalValue] = useState([]);
const pushItem = (item) => {
let tempValue = [
...localValue,
{
id: item,
value: item,
},
];
setLocalValue(tempValue);
onChange(tempValue);
};
const handleDelete = (index) => {
let tempValue = [...localValue];
tempValue.splice(index, 1);
setLocalValue(tempValue);
onChange(tempValue);
};
const handleInputOnChange = (targetValue, index) => {
let tempValue = [...localValue];
tempValue[index].value = targetValue;
setLocalValue(tempValue);
onChange(tempValue);
};
useEffect(() => {
let tempValue = value.map((item) => ({ id: item, value: item }));
setLocalValue(tempValue);
onChange(tempValue);
}, []);
return (
{
pushItem('');
}}
>
添加选项
{onRelClick && (
选项关联
)}
{localValue.map((item, index) => (
handleInputOnChange(e.target.value, index)}
/>
handleDelete(index)} />
))}
);
}
function NumberField(props) {
const { item, btns, onFinish } = props;
const [form] = Form.useForm();
return (
{btns}
);
}