import { Button, Card, Col, Form, Input, InputNumber, Modal, Row, Select, } from 'antd'; import { useEffect, useState } from 'react'; const { Option } = Select; export default function ThresholdModal(props) { const { data, onOk, visible, onClose, form, edit = false, loading } = props; const [jsonNumThreshold, setJsonNumThreshold] = useState({}); const renderThresholdItem = (item, index, key) => { // const { ThresholdType } = this.state; const ThresholdType = form.getFieldValue(`JsonNumThreshold[${key}][${index}].ThresholdType`) || item?.ThresholdType; return ( {ThresholdType !== 0 && ( )} {ThresholdType >= 4 && ThresholdType < 12 && ( )} ); }; const addThreshold = (key) => { if (!jsonNumThreshold[key]) jsonNumThreshold[key] = []; jsonNumThreshold[key].push({}); setJsonNumThreshold({ ...jsonNumThreshold }); }; const deleteThreshold = (index, key) => { jsonNumThreshold[key].splice(index, 1); setJsonNumThreshold({ ...jsonNumThreshold }); }; const handleOk = () => { form.validateFields((err, fieldsValue) => { if (err) return; onOk(fieldsValue.JsonNumThreshold); }); }; useEffect(() => { // console.log(data); setJsonNumThreshold(JSON.parse(JSON.stringify(data || {}))); }, [data]); return ( {edit && ( )} {jsonNumThreshold.exception?.map((item, index) => renderThresholdItem(item, index, 'exception'), )} {edit && ( )} {jsonNumThreshold.breakdown?.map((item, index) => renderThresholdItem(item, index, 'breakdown'), )} ); }