import React from 'react';
import { Input, Button, Form, Select, Upload, Icon, Spin, message, Radio, InputNumber, Cascader } from 'antd';
import './pfs.less';
import ajax from 'jquery/src/ajax/xhr.js'
import $ from 'jquery/src/ajax';
import YearSelect from '../../yearSelect.jsx';
import { getBase64, beforeUpload } from '../../tools.js';
import { jingli_yuanxiao, jingli_shehui, chengjiu_yuanxiao, chengjiu_shehui } from '../../dataDic.js';
import { techFieldList } from '../../DicTechFieldList';
const FormItem = Form.Item;
const RadioButton = Radio.Button;
const RadioGroup = Radio.Group;
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 PfsFrom = Form.create()(React.createClass({
    getData() {
        this.props.spinState(true);
        $.ajax({
            method: "get",
            dataType: "json",
            url: globalConfig.context + "/api/user/job",
            success: function (data) {
                if (data.data) {
                    this.setState({
                        id: data.data.id,
                        field: data.data.engagedField ? data.data.engagedField.split(',') : [],
                        gongling: data.data.workingAge,
                        zhichengname: data.data.professionalTitle,
                        zhichengyear: data.data.professionalTitleGettime,
                        zhichengPicUrl: data.data.professionalCertificateUrl,
                        zigename: data.data.qualification,
                        zigeyear: data.data.qualificationGettime,
                        zigePicUrl: data.data.qualificationCertificateUrl,
                        danwei: data.data.workUnit,
                        touxian: data.data.position,
                        jingli: data.data.experiences,
                        chengjiu: data.data.achievement
                    });
                };
            }.bind(this),
        }).always(function () {
            this.props.spinState(false);
        }.bind(this));
    },
    getInitialState() {
        return {
            loading: false,
            zigePicUrl: '',
            zhichengPicUrl: ''
        };
    },
    componentWillMount() {
        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/userCareer",
                    data: {
                        "id": this.state.id,
                        "engagedField": values.field ? values.field.join(',') : '',
                        "workingAge": values.gongling,
                        "professionalTitle": values.zhichengname,
                        "professionalTitleGettime": this.state.zhichengyear,
                        "professionalCertificateUrl": this.state.zhichengPicUrl,
                        "qualification": values.zigename,
                        "qualificationGettime": this.state.zigeyear,
                        "qualificationCertificateUrl": this.state.zigePicUrl,
                        "workUnit": values.danwei,
                        "position": values.touxian,
                        "experiences": values.jingli,
                        "achievement": values.chengjiu
                    }
                }).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));
            }
        });
    },
    zhichengPic(e) {
        this.state.zhichengPicUrl = e;
    },
    zhichengyear(e) {
        this.state.zhichengyear = e;
    },
    zigePic(e) {
        this.state.zigePicUrl = e;
    },
    zigeyear(e) {
        this.state.zigeyear = e;
    },
    jingliChange(e) {
        if (e.target.value == "a") {
            this.props.form.setFieldsValue({ 'jingli': this.state.jingli || '' })
        } else if (e.target.value == "b") {
            this.props.form.setFieldsValue({
                'jingli': jingli_yuanxiao
            })
        } else if (e.target.value == "c") {
            this.props.form.setFieldsValue({
                'jingli': jingli_shehui
            })
        }
    },
    chengjiuChange(e) {
        if (e.target.value == "a") {
            this.props.form.setFieldsValue({ 'chengjiu': this.state.chengjiu || '' })
        } else if (e.target.value == "b") {
            this.props.form.setFieldsValue({
                'chengjiu': chengjiu_yuanxiao
            })
        } else if (e.target.value == "c") {
            this.props.form.setFieldsValue({
                'chengjiu': chengjiu_shehui
            })
        }
    },
    downloadPic(type) {
        window.open(globalConfig.context + "/open/downLoadPicture?path=" + type)
    },
    render() {
        const { getFieldDecorator } = this.props.form;
        const formItemLayout = {
            labelCol: { span: 3 },
            wrapperCol: { span: 12 },
        };
        const _me = this;
        return (
 :
                        
                }
            
        );
    }
};
const PfsFrom = Form.create()(React.createClass({
    getData() {
        this.props.spinState(true);
        $.ajax({
            method: "get",
            dataType: "json",
            url: globalConfig.context + "/api/user/job",
            success: function (data) {
                if (data.data) {
                    this.setState({
                        id: data.data.id,
                        field: data.data.engagedField ? data.data.engagedField.split(',') : [],
                        gongling: data.data.workingAge,
                        zhichengname: data.data.professionalTitle,
                        zhichengyear: data.data.professionalTitleGettime,
                        zhichengPicUrl: data.data.professionalCertificateUrl,
                        zigename: data.data.qualification,
                        zigeyear: data.data.qualificationGettime,
                        zigePicUrl: data.data.qualificationCertificateUrl,
                        danwei: data.data.workUnit,
                        touxian: data.data.position,
                        jingli: data.data.experiences,
                        chengjiu: data.data.achievement
                    });
                };
            }.bind(this),
        }).always(function () {
            this.props.spinState(false);
        }.bind(this));
    },
    getInitialState() {
        return {
            loading: false,
            zigePicUrl: '',
            zhichengPicUrl: ''
        };
    },
    componentWillMount() {
        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/userCareer",
                    data: {
                        "id": this.state.id,
                        "engagedField": values.field ? values.field.join(',') : '',
                        "workingAge": values.gongling,
                        "professionalTitle": values.zhichengname,
                        "professionalTitleGettime": this.state.zhichengyear,
                        "professionalCertificateUrl": this.state.zhichengPicUrl,
                        "qualification": values.zigename,
                        "qualificationGettime": this.state.zigeyear,
                        "qualificationCertificateUrl": this.state.zigePicUrl,
                        "workUnit": values.danwei,
                        "position": values.touxian,
                        "experiences": values.jingli,
                        "achievement": values.chengjiu
                    }
                }).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));
            }
        });
    },
    zhichengPic(e) {
        this.state.zhichengPicUrl = e;
    },
    zhichengyear(e) {
        this.state.zhichengyear = e;
    },
    zigePic(e) {
        this.state.zigePicUrl = e;
    },
    zigeyear(e) {
        this.state.zigeyear = e;
    },
    jingliChange(e) {
        if (e.target.value == "a") {
            this.props.form.setFieldsValue({ 'jingli': this.state.jingli || '' })
        } else if (e.target.value == "b") {
            this.props.form.setFieldsValue({
                'jingli': jingli_yuanxiao
            })
        } else if (e.target.value == "c") {
            this.props.form.setFieldsValue({
                'jingli': jingli_shehui
            })
        }
    },
    chengjiuChange(e) {
        if (e.target.value == "a") {
            this.props.form.setFieldsValue({ 'chengjiu': this.state.chengjiu || '' })
        } else if (e.target.value == "b") {
            this.props.form.setFieldsValue({
                'chengjiu': chengjiu_yuanxiao
            })
        } else if (e.target.value == "c") {
            this.props.form.setFieldsValue({
                'chengjiu': chengjiu_shehui
            })
        }
    },
    downloadPic(type) {
        window.open(globalConfig.context + "/open/downLoadPicture?path=" + type)
    },
    render() {
        const { getFieldDecorator } = this.props.form;
        const formItemLayout = {
            labelCol: { span: 3 },
            wrapperCol: { span: 12 },
        };
        const _me = this;
        return (
            
        );
    },
}));
const Pfs = React.createClass({
    getInitialState() {
        return {
            loading: false
        };
    },
    spinChange(e) {
        this.setState({
            loading: e
        });
    },
    render() {
        return (
            
                
            
        )
    }
});
export default Pfs;