import React from 'react';
import { Icon, Modal, Button, Form, message, Input, Spin, Select, Checkbox, InputNumber, DatePicker } from 'antd';
import './contract.less';
import { companySearch } from '../../../tools.js';
import ajax from 'jquery/src/ajax/xhr.js'
import $ from 'jquery/src/ajax';
const ContractAddFrom = Form.create()(React.createClass({
getInitialState() {
return {
loading: false,
companyOption: [],
accelerated: 0,
acceleratedDate: 0,
visible: "visible"
};
},
loadData(id) {
this.setState({
loading: true
});
$.ajax({
method: "get",
dataType: "json",
crossDomain: false,
cache: false,
url: globalConfig.context + "/api/user/contract/detail",
data: {
id: id || this.props.data.id
}
}).done((data) => {
if (!data.data) {
if (data.error && data.error.length) {
message.warning(data.error[0].message);
};
} else {
this.setState({
data: data.data,
patentCheck: data.data.patentNum ? true : false,
copyrightCheck: data.data.copyrightNum ? true : false,
highTechCheck: data.data.cognizanceYear ? true : false,
techProjectCheck: data.data.techProjectNum ? true : false,
});
};
}).always(function () {
this.setState({
loading: false
});
}.bind(this));
},
componentWillMount() {
let d = new Date(), _me = this, theArr = [];
d = d.getFullYear() - 1;
for (let i = d; i < d + 20; i++) {
theArr.push(
{i}
)
};
this.state.yearOption = theArr;
if (this.props.data && this.props.data.id) {
this.loadData(this.props.data.id);
} else {
this.state.data = {};
this.state.patentCheck = false;
this.state.copyrightCheck = false;
this.state.highTechCheck = false;
this.state.techProjectCheck = false;
};
},
componentWillReceiveProps(nextProps) {
if (!this.props.visible && nextProps.visible) {
if (nextProps.data && nextProps.data.id) {
this.loadData(nextProps.data.id);
} else {
this.state.data = {};
this.state.patentCheck = false;
this.state.copyrightCheck = false;
this.state.highTechCheck = false;
this.state.techProjectCheck = false;
};
this.props.form.resetFields();
};
},
handleSave(e) {
e.preventDefault();
this.props.form.validateFields((err, values) => {
if (!err) {
if (!values.patentNum && !values.copyrightNum && !values.cognizanceYear && !values.techProjectNum) {
message.warning('请至少选择一个申报项目!');
return;
};
this.props.spinState(true);
$.ajax({
method: "POST",
dataType: "json",
crossDomain: false,
url: globalConfig.context + (this.state.data.id ? "/api/user/contract/update" : "/api/user/contract/apply"),
data: {
"id": this.state.data.id,
"contacts": values.contacts, //联系人
"type": values.type, //合同类型
"depict": values.depict, // "合同描述",
"patentNum": this.state.patentCheck ? values.patentNum : 0,
"copyrightNum": this.state.copyrightCheck ? values.copyrightNum : 0,
"cognizanceYear": this.state.highTechCheck ? values.cognizanceYear : undefined,
"techProjectNum": this.state.techProjectCheck ? values.techProjectNum : 0,
"comment": values.comment //"备注"
}
}).done(function (data) {
if (!data.error.length) {
message.success('保存成功!');
this.props.okClick();
this.props.closeModal();
this.props.form.resetFields();
} else {
message.warning(data.error[0].message);
}
}.bind(this)).always(function () {
this.props.spinState(false);
}.bind(this));
}
});
},
render() {
const FormItem = Form.Item;
const { getFieldDecorator } = this.props.form;
const theData = this.state.data || {};
const formItemLayout = {
labelCol: { span: 6 },
wrapperCol: { span: 14 },
};
const _me = this;
return (
);
},
}));
const ContractAdd = React.createClass({
getInitialState() {
return {
visible: false,
loading: false
};
},
showModal() {
this.setState({
visible: true,
data: {}
});
},
handleCancel(e) {
this.setState({
visible: false,
});
this.props.closeAdd(false);
},
componentWillReceiveProps(nextProps) {
this.state.visible = nextProps.showAdd;
},
spinChange(e) {
this.setState({
loading: e
});
},
render() {
return (
{ this.props.closeAdd(false, true) }}
typeOption={this.props.typeOption}
contactsOption={this.props.contactsOption} />
);
},
});
export default ContractAdd;