import React,{Component} from "react";
import {Alert, Button, Input, message, Modal, Spin} from "antd";
import $ from "jquery/src/ajax";

const confirm = Modal.confirm;

class PublicSupplement extends Component{
    constructor(props) {
        super(props);
        this.state={
            visible:false,
            loading:false,
            supplement:''
        }
        this.addSupplement = this.addSupplement.bind(this)
    }

    addSupplement(e){
        e.stopPropagation();
        if(!this.state.supplement){
            message.info('指导意见不能为空')
            return;
        }
        this.setState({
            loading: true,
        });
        $.ajax({
            method: "post",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/admin/release/addSupplement",
            data: {
                id:this.props.infor.prid,
                supplement:(this.props.infor.supplement ? this.props.infor.supplement : '')+this.state.supplement
            },
        }).done(function(data) {
            if(!data.error.length) {
                message.success("发布成功");
                this.setState({
                    loading: false,
                    visible: false,
                    supplement:''
                });
                this.props.onCancel && this.props.onCancel();
            } else {
                message.warning(data.error[0].message);
            }
        }.bind(this));
    }

    render() {
        return (
            <div>
                <Button size="small" type="primary" onClick={(e)=>{
                    e.stopPropagation();
                    this.setState({
                        visible:true
                    })
                }}>补写公出补充</Button>
                <Modal
                    className="customeDetails"
                    title="公出补充"
                    width='500px'
                    visible={this.state.visible}
                    onOk={()=>{
                        this.setState({
                            visible: false,
                        })
                    }}
                    onCancel={()=>{
                        this.setState({
                            visible: false,
                        })
                    }}
                    footer=''
                >
                    <Spin spinning={this.state.loading}>
                        <div style={{
                            display:'flex',
                            flexFlow:'column',
                        }}>
                            <Input
                                value={this.state.supplement}
                                style={{ height:'100px' }}
                                placeholder="请输入公出补充"
                                type={'textarea'}
                                onChange={(e)=>{
                                    this.setState({
                                        supplement: e.target.value,
                                    })
                                }}
                            />
                            <div style={{paddingTop:'5px',color:'#F00',paddingBottom:'15px',fontSize:'10px'}}>面谈总结，沟通完后记录今天交流的情况。计划下一次什么时候再面谈？该如何面谈？该如何跟进？</div>
                            <Button
                                type="primary"
                                style={{ marginTop: "10px", marginBottom: '10px' }}
                                onClick={(e)=>{
                                    let _this = this;
                                    confirm({
                                        title: '确定要提交公出补充吗?',
                                        content: '公出补充提交成功后无法删除',
                                        onOk() {
                                            _this.addSupplement(e);
                                        },
                                        onCancel() {},
                                    });
                                }}
                            >
                                保存
                            </Button>
                        </div>
                    </Spin>
                </Modal>
            </div>
        );
    }
}

export default PublicSupplement;