patentAdd.jsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. import React from 'react';
  2. import { Icon, Modal, Button, Form, Upload, message, Input, Spin, Select } from 'antd';
  3. import { beforeUploadFile, downloadFile, setUserContactsList } from '../../tools.js';
  4. import './patent.less';
  5. import ajax from 'jquery/src/ajax/xhr.js'
  6. import $ from 'jquery/src/ajax';
  7. const PatentAddFrom = Form.create()(React.createClass({
  8. getInitialState() {
  9. return {
  10. loading: false
  11. };
  12. },
  13. componentWillMount() {
  14. let theOption = [];
  15. $.ajax({
  16. method: "get",
  17. dataType: "json",
  18. crossDomain: false,
  19. url: globalConfig.context + '/api/user/getContacts',
  20. success: function (data) {
  21. if (!data.data) {
  22. if (data.error && data.error.length) {
  23. message.warning(data.error[0].message);
  24. };
  25. } else {
  26. for (let item in data.data) {
  27. let theData = data.data[item];
  28. theOption.push(
  29. <Select.Option value={item} key={theData}>{theData}</Select.Option>
  30. );
  31. };
  32. };
  33. }
  34. });
  35. this.setState({ contactsOption: theOption });
  36. },
  37. handleSubmit(e) {
  38. e.preventDefault();
  39. if (!this.state.patentProryStatementUrl) {
  40. message.warning('未上传代理委托书!');
  41. return;
  42. };
  43. this.props.form.validateFields((err, values) => {
  44. if (!err) {
  45. this.props.spinState(true);
  46. $.ajax({
  47. method: "POST",
  48. dataType: "json",
  49. crossDomain: false,
  50. url: globalConfig.context + "/api/user/patent/clientApplyPatent",
  51. data: {
  52. 'firstInventorIdNumber': values.firstInventorID,
  53. 'firstInventorName': values.firstInventorName,
  54. 'patentDes': values.intro,
  55. 'patentName': values.patentName,
  56. 'contacts': values.contacts,
  57. 'secondInventorName': values.secondInventorName,
  58. 'thirdInventorName': values.thirdInventorName,
  59. 'patentProryStatementUrl': this.state.patentProryStatementUrl
  60. }
  61. }).done(function (data) {
  62. if (!data.error.length) {
  63. message.success('保存成功!');
  64. } else {
  65. message.warning(data.error[0].message);
  66. }
  67. }.bind(this)).always(function () {
  68. this.props.spinState(false);
  69. this.props.clickOk();
  70. this.props.form.resetFields();
  71. }.bind(this));
  72. }
  73. });
  74. },
  75. avatarUrl(e) {
  76. this.state.avatarUrl = e;
  77. },
  78. checkIdcardnum(rule, value, callback) {
  79. if (!/(^\d{15}$)|(^\d{17}(\d|X)$)/.test(value)) {
  80. callback('请输入正确的身份证号!');
  81. } else {
  82. callback();
  83. }
  84. },
  85. render() {
  86. const FormItem = Form.Item;
  87. const { getFieldDecorator } = this.props.form;
  88. const formItemLayout = {
  89. labelCol: { span: 3 },
  90. wrapperCol: { span: 16 },
  91. };
  92. const _me = this;
  93. return (
  94. <Form horizontal onSubmit={this.handleSubmit} className="patent-form">
  95. <FormItem
  96. {...formItemLayout}
  97. label="专利名称"
  98. >
  99. {getFieldDecorator('patentName', {
  100. rules: [{ required: true, message: '请输入姓名!' }]
  101. })(
  102. <Input placeholder="请输入专利名称" style={{ width: 200 }} />
  103. )}
  104. </FormItem>
  105. <FormItem
  106. {...formItemLayout}
  107. label="选择联系人"
  108. >
  109. {getFieldDecorator('contacts', {
  110. rules: [{ required: true, message: '请选择一个联系人!' }]
  111. })(
  112. <Select placeholder="请选择联系人" style={{ width: 200 }}
  113. notFoundContent="未获取到联系人列表"
  114. onSelect={(e, n) => { this.setState({ contacts: e }); }}>
  115. {this.state.contactsOption}
  116. </Select>
  117. )}
  118. </FormItem>
  119. <FormItem
  120. labelCol={{ span: 24 }}
  121. wrapperCol={{ span: 24 }}
  122. label="专利简要描述"
  123. >
  124. {getFieldDecorator('intro', {
  125. initialValue: this.state.intro || null
  126. })(
  127. <Input type="textarea"
  128. placeholder="多行输入"
  129. rows={6} />
  130. )}
  131. </FormItem>
  132. <p>第一发明人</p>
  133. <FormItem
  134. {...formItemLayout}
  135. label="姓名"
  136. >
  137. {getFieldDecorator('firstInventorName', {
  138. rules: [{ required: true, message: '请输入姓名!' }]
  139. })(
  140. <Input className="mini-input" />
  141. )}
  142. </FormItem>
  143. <FormItem
  144. {...formItemLayout}
  145. label="身份证"
  146. >
  147. {getFieldDecorator('firstInventorID', {
  148. rules: [{ required: true, validator: this.checkIdcardnum, message: '请输入正确的身份证号!' }]
  149. })(
  150. <Input className="mini-input" />
  151. )}
  152. </FormItem>
  153. <p>第二发明人</p>
  154. <FormItem
  155. {...formItemLayout}
  156. label="姓名"
  157. >
  158. {getFieldDecorator('secondInventorName')(
  159. <Input className="mini-input" />
  160. )}
  161. </FormItem>
  162. <p>第三发明人</p>
  163. <FormItem
  164. {...formItemLayout}
  165. label="姓名"
  166. >
  167. {getFieldDecorator('thirdInventorName')(
  168. <Input className="mini-input" />
  169. )}
  170. </FormItem>
  171. <div className="hrSituation-roster">
  172. <Upload
  173. name="ratepay"
  174. action={globalConfig.context + "/api/user/patent/upload"}
  175. data={{ 'sign': 'patent_prory_statement' }}
  176. beforeUpload={beforeUploadFile}
  177. fileList={this.state.fileList}
  178. onChange={(info) => {
  179. if (info.file.status !== 'uploading') {
  180. console.log(info.file, info.fileList);
  181. }
  182. if (info.file.status === 'done') {
  183. if (!info.file.response.error.length) {
  184. message.success(`${info.file.name} 文件上传成功!`);
  185. } else {
  186. message.warning(info.file.response.error[0].message);
  187. return;
  188. };
  189. this.state.patentProryStatementUrl = info.file.response.data;
  190. } else if (info.file.status === 'error') {
  191. message.error(`${info.file.name} 文件上传失败。`);
  192. };
  193. this.setState({ fileList: info.fileList.slice(-1) });
  194. }}
  195. >
  196. <Button><Icon type="upload" /> 上传专利代理委托书 </Button>
  197. </Upload>
  198. <p style={{ paddingLeft: '10px', marginTop: '10px' }}>
  199. <a onClick={() => { window.open(globalConfig.context + "/api/user/patent/downloadTemplateFile?sign=patent_prory_statement") }}>专利代理委托书模板下载</a>
  200. </p>
  201. </div>
  202. <FormItem style={{ marginTop: '20px' }}>
  203. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  204. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  205. </FormItem>
  206. </Form >
  207. );
  208. },
  209. }));
  210. const PatentAdd = React.createClass({
  211. getInitialState() {
  212. return {
  213. visible: false,
  214. loading: false
  215. };
  216. },
  217. showModal() {
  218. this.setState({
  219. visible: true,
  220. });
  221. },
  222. handleOk() {
  223. this.setState({
  224. visible: false,
  225. });
  226. this.props.closeDesc(false, true);
  227. },
  228. handleCancel(e) {
  229. this.setState({
  230. visible: false,
  231. });
  232. this.props.closeDesc(false);
  233. },
  234. spinChange(e) {
  235. this.setState({
  236. loading: e
  237. });
  238. },
  239. render() {
  240. return (
  241. <div className="patent-addNew">
  242. <Button disabled={this.props.ButtonDisabled} className="patent-addNew" type="primary" onClick={this.showModal}>申请新专利<Icon type="plus" /></Button>
  243. <Modal maskClosable={false} title="新专利申请" visible={this.state.visible}
  244. onOk={this.handleOk} onCancel={this.handleCancel}
  245. width='720px'
  246. footer=''>
  247. <Spin spinning={this.state.loading} className='spin-box'>
  248. <PatentAddFrom spinState={this.spinChange} closeModal={this.handleCancel} clickOk={this.handleOk} />
  249. </Spin>
  250. </Modal>
  251. </div>
  252. );
  253. },
  254. });
  255. export default PatentAdd;