import React from 'react';
import { Icon, InputNumber, Form, Button, Input, Radio, Select, Spin, Table, message, Cascader, Modal } from 'antd';
import { cognizanceStateList } from '../../dataDic.js';
import { techFieldList } from '../../DicTechFieldList.js';
import { getTime, getCognizanceState } from '../../tools.js';
import ajax from 'jquery/src/ajax/xhr.js';
import $ from 'jquery/src/ajax';
import moment from 'moment';
import './cognizance.less';
const CognizanceDescFrom = Form.create()(React.createClass({
    loadData(theCid, theYear) {
        this.setState({
            loading: true
        });
        $.ajax({
            method: "post",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/user/cognizance/cognizanceDetail",
            data: {
                cid: theCid || this.props.data.cid,
                year: theYear || this.props.data.year
            },
            success: function (data) {
                if (data.error.length || !data.data) {
                    message.warning(data.error[0].message);
                    return;
                };
                this.state.data = data.data;
                this.state.cid = this.props.data.cid;
                this.state.year = this.props.data.year;
                this.state.moneyTable = [{
                    key: 1,
                    year: '前一年',
                    netAsset: data.data.netAsset1,
                    salesRevenue: data.data.salesRevenue1,
                    grossProfit: data.data.grossProfit1
                }, {
                    key: 2,
                    year: '前二年',
                    netAsset: data.data.netAsset2,
                    salesRevenue: data.data.salesRevenue2,
                    grossProfit: data.data.grossProfit2
                }, {
                    key: 3,
                    year: '前三年',
                    netAsset: data.data.netAsset3,
                    salesRevenue: data.data.salesRevenue3,
                    grossProfit: data.data.grossProfit3
                }];
                if (data.data.netAsset2 == 0) {
                    this.state.netAssetRate = 0;
                } else if (data.data.netAsset3 == 0) {
                    this.state.netAssetRate = (data.data.netAsset1 / data.data.netAsset2) - 1;
                } else {
                    this.state.netAssetRate = 1 / 2 * (data.data.netAsset2 / data.data.netAsset3 + data.data.netAsset1 / data.data.netAsset2) - 1;
                };
                if (this.state.netAssetRate < 0 || isNaN(this.state.netAssetRate)) {
                    this.state.netAssetRate = 0
                };
                if (data.data.salesRevenue2 == 0) {
                    this.state.salesRevenueRate = 0;
                } else if (data.data.salesRevenue3 == 0) {
                    this.state.salesRevenueRate = (data.data.salesRevenue1 / data.data.salesRevenue2) - 1;
                } else {
                    this.state.salesRevenueRate = 1 / 2 * (data.data.salesRevenue2 / data.data.salesRevenue3 + data.data.salesRevenue1 / data.data.salesRevenue2) - 1;
                };
                if (this.state.salesRevenueRate < 0 || isNaN(this.state.salesRevenueRate)) {
                    this.state.salesRevenueRate = 0
                };
            }.bind(this),
        }).always(function () {
            this.setState({
                loading: false
            });
        }.bind(this));
    },
    getStateData(theCid) {
        this.setState({
            loading: true
        });
        $.ajax({
            method: "post",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/user/cognizance/cognizanceLog",
            data: {
                cid: theCid || this.props.data.cid
            },
            success: function (data) {
                if (data.error.length || !data.data) {
                    message.warning(data.error[0].message);
                    return;
                };
                this.state.stateTable = [];
                for (let i = 0; i < data.data.length; i++) {
                    this.state.stateTable.push({
                        key: i,
                        recordTimeFormattedDate: data.data[i].recordTimeFormattedDate,
                        state: String(data.data[i].state),
                        principal: data.data[i].principal,
                        operator: data.data[i].operator,
                        comment: data.data[i].comment
                    });
                };
            }.bind(this),
        }).always(function () {
            this.setState({
                loading: false
            });
        }.bind(this));
    },
    getInitialState() {
        return {
            loading: false,
            stateOption: [],
            moneyColumns: [{
                title: '',
                dataIndex: 'year',
                key: 'year',
            }, {
                title: '净资产',
                dataIndex: 'netAsset',
                key: 'netAsset',
            }, {
                title: '销售收入',
                dataIndex: 'salesRevenue',
                key: 'salesRevenue',
            }, {
                title: '利润总额',
                dataIndex: 'grossProfit',
                key: 'grossProfit',
            }],
            stateColumns: [{
                title: '状态',
                dataIndex: 'state',
                key: 'state',
                render: (text) => { return getCognizanceState(text) }
            }, {
                title: '处理时间',
                dataIndex: 'recordTimeFormattedDate',
                key: 'recordTimeFormattedDate',
            }, {
                title: '负责人',
                dataIndex: 'principal',
                key: 'principal',
            }, {
                title: '操作人',
                dataIndex: 'operator',
                key: 'operator',
            }, {
                title: '备注',
                dataIndex: 'comment',
                key: 'comment',
            }]
        };
    },
    componentWillMount() {
        let _me = this;
        cognizanceStateList.map(function (item) {
            _me.state.stateOption.push(
                
备注:
{ this.state.comment = e.target.value; }} />