import * as React from 'react';
import { Button, Drawer, Input, Form,message } from 'kts-xui';
import { FormInstance } from 'kts-components-antd-x4/lib/form';
import agent from '../Server';
/** Props接口 */
interface IProps {
    onClose: () => void;
    onSuccess: () => void;
    /**被选中id列表 */
    list: any[];
}
/**
 * 申诉页面
 */
export default class UIComponents extends React.Component<IProps, any> {
    formRef:any = React.createRef<FormInstance>();
    constructor(props) {
        super(props);
        this.state = {
            list: this.props.list
        }
    }
    onClose = () => {
        this.props.onClose();
    }
    onSubmit = () => {
        this.formRef.current!.submit();
    }
    onFinish = async values => {
        const data = this.state.list.map((item) => {
            return {
                goodsUuid: item.goodsUuid,
                detailNo: item.detailNo,
                ...values
            }
        })
        const res: any = await agent.post('/asset/submit/appealGoods', data, this);
        if (res.err) {
            return;
        } else {
            message.success('操作成功');
            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='appealReason'
                            label='填写申诉原因'
                            
                            rules={[
                                { required: false, max:80 }
                            ]}
                        >
                            <Input placeholder='最多输入80个字符'/>
                        </Form.Item>
                    </Form>
                </Drawer>

            </div>
        );
    }
}
