import React,{Component} from "react"; import {Form, Input, Button, Checkbox, Select, Spin} from 'antd'; import $ from "jquery/src/ajax"; import {message, Modal} from "antd"; class AddPatentPrice extends Component{ constructor(props) { super(props); this.state={ loading: false } } //增加 修改 addSoftWritingPriceFn(e) { e.preventDefault(); this.props.form.validateFields((err, values) => { if (!err) { this.setState({ loading: true }); let api ; if(Object.keys(this.props.infor).length){ api = '/api/admin/company/updatePatentPrice'; values.id = this.props.infor.id; } else { api = '/api/admin/company/addPatentPrice'; } $.ajax({ method: "post", dataType: "json", crossDomain: false, url:globalConfig.context + api, data:values, }).done(function (data) { this.setState({ loading: false }); if (!data.error.length) { message.success(Object.keys(this.props.infor).length ? '修改成功!' : '新增成功!'); this.props.successFn(); } else { message.warning(data.error[0].message); } }.bind(this)); } }); } render() { const { getFieldDecorator } = this.props.form; return ( <Modal maskClosable={false} className="customeDetails" title={Object.keys(this.props.infor).length ? "修改" : "新增"} width='350px' visible={this.props.visible} onCancel={this.props.onCancel} footer={null} > <Spin spinning={this.state.loading}> <Form onSubmit={(e)=>{ this.addSoftWritingPriceFn(e) }}> <Form.Item label="公司名称"> {getFieldDecorator('companyName', { initialValue: this.props.infor.companyName, rules: [{ required: true, message: '请输入公司名称!' }], })( <Input disabled={Object.keys(this.props.infor).length !== 0} placeholder="请输入公司名称" style={{width:'250px'}}/> )} </Form.Item> <Form.Item label="实用新型(万元)"> {getFieldDecorator('utilityModel', { initialValue: this.props.infor.utilityModel, rules: [{ required: true, message: '请输入实用新型的金额!' }], })( <Input placeholder="请输入实用新型的金额" type={'number'} style={{width:'250px'}}/> )} </Form.Item> <Form.Item label="外观专利(万元)"> {getFieldDecorator('appearancePatent', { initialValue: this.props.infor.appearancePatent, rules: [{ required: true, message: '请输入外观专利的金额!' }], })( <Input placeholder="请输入外观专利的金额" type={'number'} style={{width:'250px'}}/> )} </Form.Item> <Form.Item label="发明专利(万元)"> {getFieldDecorator('inventionPatent', { initialValue: this.props.infor.inventionPatent, rules: [{ required: true, message: '请输入发明专利的金额!' }], })( <Input placeholder="请输入发明专利的金额" type={'number'} style={{width:'250px'}}/> )} </Form.Item> <Form.Item label="备注"> {getFieldDecorator('remarks', { initialValue: this.props.infor.remarks, rules: [{ required: false, message: '请输入备注!' }], })( <Input placeholder="请输入备注" type={'textarea'} style={{width:'250px'}}/> )} </Form.Item> <Form.Item> <Button style={{ width: '100%', marginTop: '18px', }} type="primary" htmlType="submit"> { Object.keys(this.props.infor).length ? '确定修改' : '确定添加' } </Button> </Form.Item> </Form> </Spin> </Modal> ) } } const WrappedHorizontalLoginForm = Form.create()(AddPatentPrice); export default WrappedHorizontalLoginForm