import React from 'react';
import { Input, Button, Form, Select, Upload, Icon, Spin, message, Cascader } from 'antd';
import './edu.less';
import { edulvlArr } from '../../dataDic.js';
import ajax from 'jquery/src/ajax/xhr.js'
import $ from 'jquery/src/ajax';
import { techFieldList } from '../../DicTechFieldList';
import { getBase64, beforeUpload } from '../../tools'
import YearSelect from '../../yearSelect.jsx';
const FormItem = Form.Item;
const Option = Select.Option;
class Avatar extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            imageUrl: '',
            propsbool: true,
        }
    }
    handleChange(info) {
        if (info.file.status === 'done') {
            // Get this url from response in real world.
            getBase64(info.file.originFileObj, imageUrl => this.setState({ imageUrl }));
            this.props.urlData(info.file.response.data);
        }
    }
    componentWillReceiveProps(nextProps) {
        if (nextProps.picUrl && this.state.propsbool) {
            this.state.imageUrl = globalConfig.avatarHost + "/upload" + nextProps.picUrl;
            this.state.propsbool = false;
        }
    }
    render() {
        const imageUrl = this.state.imageUrl;
        return (
            
                {
                    imageUrl ?
                         :
                        
                }
            
        );
    }
};
const EduFrom = Form.create()(React.createClass({
    getData() {
        this.props.spinState(true);
        $.ajax({
            method: "get",
            dataType: "json",
            url: globalConfig.context + "/api/user/educate",
            success: function (data) {
                if (data.error && data.error.length) {
                    message.warning(data.error[0].message);
                } else {
                    if (data.data) {
                        this.setState({
                            id: data.data.id,
                            edulvl: data.data.education,
                            eduPfs: data.data.majorCategory ? data.data.majorCategory.split(',') : [],
                            schoolname: data.data.graduateSchool,
                            graduationTimeYear: data.data.graduationTimeYear,
                            edunum: data.data.diplomaCode,
                            degreenum: data.data.degreeCode,
                            xueliPicUrl: data.data.diplomaUrl,
                            xueweiPicUrl: data.data.degreeDiplomaUrl
                        });
                    };
                };
            }.bind(this),
        }).always(function () {
            this.props.spinState(false);
        }.bind(this));
    },
    getInitialState() {
        return {
            loading: false,
            xueweiPicUrl: '',
            xueliPicUrl: '',
            eduPfs: []
        };
    },
    componentDidMount() {
        this.getData();
    },
    handleSubmit(e) {
        e.preventDefault();
        this.props.form.validateFields((err, values) => {
            if (!err) {
                this.props.spinState(true);
                $.ajax({
                    method: "POST",
                    dataType: "json",
                    crossDomain: false,
                    url: globalConfig.context + "/api/user/userEdu",
                    data: {
                        "id": this.state.id,
                        "education": values.edulvl,
                        "majorCategory": values.eduPfs.join(','),
                        "graduateSchool": values.schoolname,
                        "graduationTimeYear": this.state.graduationTimeYear,
                        "diplomaUrl": this.state.xueliPicUrl,
                        "diplomaCode": values.edunum,
                        "degreeDiplomaUrl": this.state.xueweiPicUrl,
                        "degreeCode": values.degreenum
                    }
                }).done(function (data) {
                    if (!data.error.length) {
                        message.success('保存成功!');
                        this.getData();
                    } else {
                        message.warning(data.error[0].message);
                    }
                }.bind(this)).always(function () {
                    this.props.spinState(false);
                }.bind(this));
            }
        });
    },
    downloadPic(type) {
        window.open(globalConfig.context + "/open/downLoadPicture?path=" + type)
    },
    handleyear(e) {
        this.state.graduationTimeYear = e;
    },
    xueliPicUrl(e) {
        this.state.xueliPicUrl = e;
    },
    xueweiPicUrl(e) {
        this.state.xueweiPicUrl = e;
    },
    render() {
        const { getFieldDecorator } = this.props.form;
        const formItemLayout = {
            labelCol: { span: 4 },
            wrapperCol: { span: 12 },
        };
        const _me = this;
        return (
 :
                        
                }
            
        );
    }
};
const EduFrom = Form.create()(React.createClass({
    getData() {
        this.props.spinState(true);
        $.ajax({
            method: "get",
            dataType: "json",
            url: globalConfig.context + "/api/user/educate",
            success: function (data) {
                if (data.error && data.error.length) {
                    message.warning(data.error[0].message);
                } else {
                    if (data.data) {
                        this.setState({
                            id: data.data.id,
                            edulvl: data.data.education,
                            eduPfs: data.data.majorCategory ? data.data.majorCategory.split(',') : [],
                            schoolname: data.data.graduateSchool,
                            graduationTimeYear: data.data.graduationTimeYear,
                            edunum: data.data.diplomaCode,
                            degreenum: data.data.degreeCode,
                            xueliPicUrl: data.data.diplomaUrl,
                            xueweiPicUrl: data.data.degreeDiplomaUrl
                        });
                    };
                };
            }.bind(this),
        }).always(function () {
            this.props.spinState(false);
        }.bind(this));
    },
    getInitialState() {
        return {
            loading: false,
            xueweiPicUrl: '',
            xueliPicUrl: '',
            eduPfs: []
        };
    },
    componentDidMount() {
        this.getData();
    },
    handleSubmit(e) {
        e.preventDefault();
        this.props.form.validateFields((err, values) => {
            if (!err) {
                this.props.spinState(true);
                $.ajax({
                    method: "POST",
                    dataType: "json",
                    crossDomain: false,
                    url: globalConfig.context + "/api/user/userEdu",
                    data: {
                        "id": this.state.id,
                        "education": values.edulvl,
                        "majorCategory": values.eduPfs.join(','),
                        "graduateSchool": values.schoolname,
                        "graduationTimeYear": this.state.graduationTimeYear,
                        "diplomaUrl": this.state.xueliPicUrl,
                        "diplomaCode": values.edunum,
                        "degreeDiplomaUrl": this.state.xueweiPicUrl,
                        "degreeCode": values.degreenum
                    }
                }).done(function (data) {
                    if (!data.error.length) {
                        message.success('保存成功!');
                        this.getData();
                    } else {
                        message.warning(data.error[0].message);
                    }
                }.bind(this)).always(function () {
                    this.props.spinState(false);
                }.bind(this));
            }
        });
    },
    downloadPic(type) {
        window.open(globalConfig.context + "/open/downLoadPicture?path=" + type)
    },
    handleyear(e) {
        this.state.graduationTimeYear = e;
    },
    xueliPicUrl(e) {
        this.state.xueliPicUrl = e;
    },
    xueweiPicUrl(e) {
        this.state.xueweiPicUrl = e;
    },
    render() {
        const { getFieldDecorator } = this.props.form;
        const formItemLayout = {
            labelCol: { span: 4 },
            wrapperCol: { span: 12 },
        };
        const _me = this;
        return (
            
        );
    },
}));
const Person = React.createClass({
    getInitialState() {
        return {
            loading: false
        };
    },
    spinChange(e) {
        this.setState({
            loading: e
        });
    },
    render() {
        return (
            
                
            
        )
    }
});
export default Person;