import * as React from 'react';
import { Button, Drawer, Input, Form } from 'kts-xui';
import { FormInstance } from 'kts-components-antd-x4/lib/form';
import agent from '../Server';
/** Props接口 */
interface IProps {
    onClose: () => void;
    onSuccess: () => void;
    id: string;
}

export default class UIComponents extends React.Component<IProps, any> {
    formRef:any = React.createRef<FormInstance>();
    constructor(props) {
        super(props);
        this.state = {
            id: props.id
        }
    }
    onClose = () => {
        this.props.onClose();
    }
    onSubmit = () => {
        this.formRef.current?.submit();
    }
    onFinish = async values => {
        const data = {
            ...values,
            taskUuid: this.state.id
        }
        const res: any = await agent.post('/web/verifierTask/closeTask', data, this);
        if (res.er) {
            return;
        } else if (res.res) {
            this.props.onSuccess();
        }

    }
    render() {
        return (
            <div>
                <Drawer
                    title="关闭"
                    onClose={this.onClose}
                    visible={true}
                    footer={
                        <div
                            style={{
                                textAlign: 'right',
                            }}
                        >
                            <Button style={{ marginRight: 8 }} key='1' type="primary" onClick={this.onSubmit}>提交</Button>
                            <Button key='2' onClick={this.onClose}>取消</Button>
                        </div>}
                >
                    <Form
                        ref={this.formRef}
                        layout='vertical'
                        onFinish={this.onFinish}
                    >
                        <Form.Item
                            name='closeReason'
                            label='关闭原因'
                            rules={[
                                { required: true, max: 80 }
                            ]}
                        >
                            <Input />
                        </Form.Item>
                    </Form>
                </Drawer>

            </div>
        );
    }
}
