import React, { useState } from 'react';
import { Form, message } from 'antd';
import { Modal, Input } from 'antd';
import { audit } from '@/services/boom';

// 审批意见
function AuditModal(props) {
  const { visible, onClose, onOk, id } = props;
  const [loading, setLoading] = useState(false);
  const [form] = Form.useForm();

  const handleOk = async () => {
    const fieldsValue = await form.validateFields();
    setLoading(true);
    try {
      await audit({
        id,
        status: visible,
        ...fieldsValue,
      });
      message.success('操作成功');
      onClose();
      onOk?.();
    } catch (error) {}
    setLoading(false);
  };

  return (
    <Modal
      confirmLoading={loading}
      destroyOnClose
      title={visible == 1 ? '是否确认通过审批？' : '是否确认拒绝审批？'}
      open={visible}
      onCancel={onClose}
      onOk={handleOk}
    >
      <Form form={form}>
        <Form.Item
          labelCol={{ span: 5 }}
          wrapperCol={{ span: 15 }}
          name="desc"
          label="审批意见"
        >
          <Input.TextArea />
        </Form.Item>
      </Form>
    </Modal>
  );
}

export default AuditModal;
