import React, { useContext } from 'react'; import { Form, Input, Button, message, Space } from 'antd'; import apiObj from '@api/index'; import { getCookie,setCookie } from '@utils/index'; import DrugContext from './Drug-context'; const { post, api } = apiObj; function AddDrug(props) { const [form] = Form.useForm(); const { type, formData} = useContext(DrugContext); const initialValues = formData; const onFinish = values => { let params = values if (type == 3) { params.id=initialValues.id upDrugById(params) } else { addDrug(params) } }; function addDrug(param) { const hisId = getCookie("hospitalId"); const params ={ hospitalId:hisId, ...param } post(api.addDrug, params).then((res) => { if (res.data.code === 200) { props.DrugChange() message.success(res.data.message); } else { message.error(res.data.message); } }) } function upDrugById(param) { const hisId = getCookie("hospitalId"); const params ={ hospitalId:hisId, ...param } post(api.upDrugById, params).then((res) => { if (res.data.code === 200) { props.DrugChange() message.success(res.data.message); } else { message.error(res.data.message); } }) } function cancel() { props.cancel() } function onValuesChange() { props.isChange(form.isFieldsTouched()) } return ( <>