import React from 'react'; import { Icon, Modal, Button, Form, message, Input, Spin, Select, Checkbox, InputNumber } 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({ getContactsList(theUid) { $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/getContacts", data: { uid: theUid || this.state.uid }, success: function (data) { let theOption = []; if (!data.data) { if (data.error && data.error.length) { message.warning(data.error[0].message); return; }; }; for (let item in data.data) { let theData = data.data[item]; theOption.push( {theData} ); }; this.setState({ contactsOption: theOption }); }.bind(this), }); }, getInitialState() { return { loading: false, companyOption: [], accelerated: 0, acceleratedDate: 0, visible: "visible" }; }, 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; }, componentWillReceiveProps(nextProps) { if (!this.props.visible && nextProps.visible) { 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 (!values.uid || values.uid === "") { message.warning('请先选择公司!'); return; }; if (!err) { this.props.spinState(true); $.ajax({ method: "POST", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/contract/apply", data: { "uid": values.uid, "contacts": values.contacts, //联系人 "type": values.type, //合同类型 "depict": values.depict, // "合同描述", "patentNum": this.state.patentCheck ? values.patentNum : undefined, "copyrightNum": this.state.copyrightCheck ? values.copyrightNum : undefined, "cognizanceYear": this.state.highTechCheck ? values.cognizanceYear : undefined, "techProjectNum": this.state.techProjectCheck ? values.techProjectNum : undefined, "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)); } }); }, handleSubmit() { this.props.form.validateFields((err, values) => { if (!values.uid || values.uid === "") { message.warning('请先选择公司!'); return; }; if (!err) { this.props.spinState(true); $.ajax({ method: "POST", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/contract/submit", data: { "uid": values.uid, "contacts": values.contacts, //联系人 "type": values.type, //合同类型 "depict": values.depict, // "合同描述", "patentNum": this.state.patentCheck ? values.patentNum : undefined, "copyrightNum": this.state.copyrightCheck ? values.copyrightNum : undefined, "cognizanceYear": this.state.highTechCheck ? values.cognizanceYear : undefined, "techProjectNum": this.state.techProjectCheck ? values.techProjectNum : undefined, "principals": values.principals, "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 formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 }, }; const _me = this; return (
{getFieldDecorator('uid')( )} {getFieldDecorator('contacts')( )} {getFieldDecorator('type')( )}
{getFieldDecorator('depict')( )}
{ this.setState({ highTechCheck: e.target.checked }); }}> {getFieldDecorator('cognizanceYear')( )}
{ this.setState({ patentCheck: e.target.checked }); }}> {getFieldDecorator('patentNum')( )}
{ this.setState({ copyrightCheck: e.target.checked }); }}> {getFieldDecorator('copyrightNum')( )}
{ this.setState({ techProjectCheck: e.target.checked }); }}> {getFieldDecorator('techProjectNum')( )}
{getFieldDecorator('principals')( )}
{getFieldDecorator('comment')( )}
); }, })); const ContractAdd = React.createClass({ getInitialState() { return { visible: false, loading: false }; }, showModal() { this.setState({ visible: true, }); }, handleCancel(e) { this.setState({ visible: false, }); this.props.closeAdd(false); }, spinChange(e) { this.setState({ loading: e }); }, render() { return (
{ this.props.closeAdd(false, true) }} companyOption={this.props.companyOption} authorOption={this.props.authorOption} typeOption={this.props.typeOption} />
); }, }); export default ContractAdd;