import React from 'react';
import { Input, InputNumber, Button, Form, Icon, Spin, message, Table, Modal, Upload, Select } from 'antd';
import { beforeUploadFile, newDownloadFile } from '../../tools.js';
import './hrSituation.less'
import ajax from 'jquery/src/ajax/xhr.js'
import $ from 'jquery/src/ajax';
const HrSituationDescFrom = Form.create()(React.createClass({
    getInitialState() {
        return {
            loading: false,
            yearOption: []
        };
    },
    handleSubmit(e) {
        e.preventDefault();
        this.props.form.validateFields((err, values) => {
            if (values.firmTotal < values.firmInService + values.firmPartTime + values.firmTemporary) {
                message.warning("总体情况的在职人员数、兼职人员数、临时聘用人员数相加小于等于企业职工总数!");
                return;
            };
            if (values.firmTotal < values.techTotal) {
                message.warning("科技人员数小于等于企业职工总数!");
                return;
            };
            if (values.firmInService < values.techInService || values.firmPartTime < values.techPartTime || values.firmTemporary < values.techTemporary ||
                values.firmForeign < values.techForeign || values.firmAbroad < values.techAbroad || values.firmCore < values.techCore) {
                message.warning("科技人员各项人数小于等于企业职工各项人数!");
                return;
            };
            if (values.firmTotal < values.doctor + values.master + values.undergraduate + values.college) {
                message.warning("全体人员结构中学历一栏人数总和小于等于职工人数!");
                return;
            };
            if (values.firmTotal < values.belowThirty + values.thirtyoneToThirtyfour + values.fortyoneToFifty + values.aboveFifty) {
                message.warning("全体人员结构中年龄一栏人数总和小于等于职工人数!");
                return;
            };
            if (!this.state.year && !this.props.data.year) {
                message.warning("请选择一个年份!")
                return;
            };
            if (!err) {
                this.props.spinState(true);
                $.ajax({
                    method: "POST",
                    dataType: "json",
                    crossDomain: false,
                    url: globalConfig.context + "/api/user/SaveHumanResource",
                    data: {
                        id: this.props.data.id,
                        year: this.state.year || this.props.data.year,
                        aboveFifty: values.aboveFifty,
                        belowThirty: values.belowThirty,
                        college: values.college,
                        doctor: values.doctor,
                        firmAbroad: values.firmAbroad,
                        firmCore: values.firmCore,
                        firmForeign: values.firmForeign,
                        firmInService: values.firmInService,
                        firmPartTime: values.firmPartTime,
                        firmTemporary: values.firmTemporary,
                        firmTotal: values.firmTotal,
                        fortyoneToFifty: values.fortyoneToFifty,
                        intermediateTitle: values.intermediateTitle,
                        juniorTitle: values.juniorTitle,
                        master: values.master,
                        seniorMechanic: values.seniorMechanic,
                        seniorTitle: values.seniorTitle,
                        techAbroad: values.techAbroad,
                        techCore: values.techCore,
                        techForeign: values.techForeign,
                        techInService: values.techInService,
                        techPartTime: values.techPartTime,
                        techTemporary: values.techTemporary,
                        techTotal: values.techTotal,
                        thirtyoneToThirtyfour: values.thirtyoneToThirtyfour,
                        undergraduate: values.undergraduate,
                        rosterUrl: this.state.rosterUrl,
                        socialSecurityUrl: this.state.socialSecurityUrl,
                        newEmployment: values.newEmployment,
                        graduateNumber: values.graduateNumber
                    }
                }).done(function (data) {
                    if (!data.error.length) {
                        message.success('保存成功!');
                        this.props.clickOk();
                        this.props.form.resetFields();
                    } else {
                        message.warning(data.error[0].message);
                    };
                    this.props.spinState(false);
                }.bind(this));
            }
        });
    },
    componentWillMount() {
        let d = new Date();
        let _me = this;
        d = d.getFullYear();
        for (let i = d; i > d - 20; i--) {
            _me.state.yearOption.push(