import React, {useState} from 'react';
import { createForm } from 'rc-form';
import axiosRequest from "../../../utils/request";
import {DatePicker, List, TextareaItem, WhiteSpace, WingBlank, Picker, InputItem} from "antd-mobile";
import MailA from '../../../components/Adjunct/MailA'
import Upload from 'rc-upload';
import './index.less'

const Send = (props) => {
    const {getFieldProps} = props.form;

    const onSubmit = () => {
        props.form.validateFields({ force: true }, (error) => {
            if (!error) {
                const values = props.form.getFieldsValue();
                console.log(values);
                axiosRequest({
                    method: 'post',
                    url: '/idtAppServiceV6/application/interfaces/addCalendar.jsp',
                    body: values,
                }).then(res => {});
            }
        });
    };

    const district = [
        {label: '111', value: '111'}
    ];


    const [upload, setUpload] = useState([]);
    const [upload2, setUpload2] = useState([]);
    const uploaderProps = {
        multiple: true,
        beforeUpload(file) {
            const newUpload = [...upload, file];
            setUpload(newUpload);
            return false
        }
    };
    const uploadDelete = uid => {
        const newData = [...upload];
        const Index = newData.findIndex(item => item.uid === uid);
        Index > -1 && newData.splice(Index, 1);
        setUpload(newData)
    };
    const uploaderProps2 = {
        multiple: true,
        beforeUpload(file) {
            const newUpload = [...upload2, file];
            setUpload2(newUpload);
            return false
        }
    };
    const uploadDelete2 = uid => {
        const newData = [...upload2];
        const Index = newData.findIndex(item => item.uid === uid);
        Index > -1 && newData.splice(Index, 1);
        setUpload2(newData)
    }
    return (
        <div>
            <form>
                <List className="send-content">
                    <Picker data={district} cols={1} {...getFieldProps('ss11')}>
                        <List.Item arrow="horizontal">来文单位</List.Item>
                    </Picker>

                    <InputItem {...getFieldProps('s1111')}>文件字号</InputItem>
                    <InputItem {...getFieldProps('s2')}>文件标题</InputItem>
                    <Picker data={district} cols={1} {...getFieldProps('ss1')}>
                        <List.Item arrow="horizontal">文件类别</List.Item>
                    </Picker>

                    <DatePicker className="send-date-style"{...getFieldProps('endtime')}>
                        <List.Item arrow="horizontal">收文日期</List.Item>
                    </DatePicker>
                    <InputItem {...getFieldProps('s121')}>收文编号</InputItem>
                    <InputItem {...getFieldProps('s1')}>份数</InputItem>

                    <Picker data={district} cols={1} {...getFieldProps('ss1')}>
                        <List.Item arrow="horizontal">文件密级</List.Item>
                    </Picker>
                    <Picker data={district} cols={1} {...getFieldProps('ss2')}>
                        <List.Item arrow="horizontal">紧急程度</List.Item>
                    </Picker>
                    <Picker data={district} cols={1} {...getFieldProps('ss3')}>
                        <List.Item arrow="horizontal">经办人</List.Item>
                    </Picker>
                    <Picker data={district} cols={1} {...getFieldProps('ss4')}>
                        <List.Item arrow="horizontal">联系电话</List.Item>
                    </Picker>



                    <TextareaItem
                        title="拟办意见"
                        placeholder="请输入拟办意见"
                        {...getFieldProps('_mail_editor_text')}
                        rows={4}
                    />
                    {/*正文*/}
                    <div className="am-textarea-label upload-title">正文：</div>
                    <WingBlank>
                        {upload.length > 0 && upload.map((item, index) => (
                            <MailA key={index} data={item} onDelete={uploadDelete}/>
                        ))}
                    </WingBlank>
                    <Upload className="auto-upload" {...uploaderProps}>
                        <a className="auto-upload">上传正文 +</a>
                    </Upload>
                    {/*<WhiteSpace/>*/}
                    {/*附件*/}
                    <div className="am-textarea-label upload-title">附件：</div>
                    <WingBlank>
                        {upload2.length > 0 && upload2.map((item, index) => (
                            <MailA key={index} data={item} onDelete={uploadDelete2}/>
                        ))}
                    </WingBlank>
                    <Upload className="auto-upload" {...uploaderProps2}>
                        <a className="auto-upload">上传附件 +</a>
                    </Upload>
                    <WhiteSpace/>
                </List>
                <div className="event-footer">
                    <div className="event-footer-button" onClick={onSubmit}>发送</div>
                </div>
            </form>
        </div>
    );
};

export default createForm()(Send);
