/*
* 异常处理弹框
* */

import React, { Component } from 'react';
import {
    Input, Form, Select, Modal, Button, Progress, Upload, message, Icon, Table,
    Card, Row, Col, DatePicker, Popconfirm, Checkbox, Radio, Divider
} from 'antd';
import { Util, dayFormat } from 'tools/index';
import { $http } from 'containers/config/https';
import RangeDatePicker from 'components/rangePicker/index';
import '../style/index.less';
import moment from 'moment';

const Option = Select.Option;
const { TextArea } = Input;

class ShowDealExceptionModal extends Component {

    constructor(props) {
        super(props);
        var date = new Date();
        var userData = JSON.parse(sessionStorage.getItem('userData'));
        this.state = {
            leftData: [],
            rightData: [],
            userData: userData,
            ids: []
        }
    }
    componentWillReceiveProps(nextProp) {
        if (nextProp.isShow === true) {
            this.loadData()
        } else if (this.props.isShow === false) {
            this.cleanInput();
        }
    }

    componentDidMount() {
    }

    loadData() {
        var params = {
            params: [{}]
        }
        $http.post('urlDeault', this, {
            code: "03070075",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({
                        dataSource: res.result
                    })
                }
            }
        });
    }

    closeModal(name) {
        let { onHide } = this.props;
        onHide && onHide();
        this.cleanInput();
    }

    //清空输入框
    cleanInput() {
        this.props.form.resetFields();
        this.setState({
            dataSource: [],
            exceptionMethodID: undefined,
            exceptionNote: undefined,
        })
    }


    //提交
    onSubmit() {
        let { onSubmit } = this.props;
        onSubmit && onSubmit(this.state.exceptionMethodID, this.state.exceptionNote);
    }

    render() {

        var dataSourceOption = []
        this.state.dataSource && this.state.dataSource.map((item, index) => {
            dataSourceOption.push(<Radio key={index} value={item.id} style={{ marginLeft: 10 }}>{item.descripts}</Radio>)
        })

        return <div>
            <Modal
                title={'异常处理'}
                maskClosable={false}
                visible={this.props.isShow}
                onCancel={this.closeModal.bind(this)}
                onOk={this.onSubmit.bind(this)}>
                <Radio.Group value={this.state.exceptionMethodID} onChange={Util.commonInputChange.bind(this, 'exceptionMethodID')}>
                    {dataSourceOption}
                </Radio.Group>

                <div style={{ marginTop: 10 }}>
                    备注：<TextArea rows={4} value={this.state.exceptionNote}
                        placeholder='请输入异常备注'
                        onChange={Util.commonInputChange.bind(this, 'exceptionNote')} /></div>
            </Modal></div>
    }
}

export default Form.create()(ShowDealExceptionModal);