patentAdd.jsx 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. import React from 'react';
  2. import { Icon, Modal, Button, Form, Upload, message, Input, Spin, Checkbox } from 'antd';
  3. import './patent.less';
  4. import ajax from 'jquery/src/ajax/xhr.js'
  5. import $ from 'jquery/src/ajax';
  6. function getBase64(img, callback) {
  7. const reader = new FileReader();
  8. reader.addEventListener('load', () => callback(reader.result));
  9. reader.readAsDataURL(img);
  10. };
  11. function beforeUpload(file) {
  12. const isJPG = file.type === 'image/jpeg';
  13. if (!isJPG) {
  14. message.error('You can only upload JPG file!');
  15. }
  16. const isLt2M = file.size / 1024 / 1024 < 2;
  17. if (!isLt2M) {
  18. message.error('Image must smaller than 2MB!');
  19. }
  20. return isJPG && isLt2M;
  21. };
  22. class Avatar extends React.Component {
  23. constructor(props) {
  24. super(props);
  25. this.state = {
  26. imageUrl: ''
  27. }
  28. }
  29. handleChange(info) {
  30. if (info.file.status === 'done') {
  31. // Get this url from response in real world.
  32. getBase64(info.file.originFileObj, imageUrl => this.setState({ imageUrl }));
  33. this.props.urlData(info.file.response.data);
  34. }
  35. }
  36. render() {
  37. const imageUrl = this.state.imageUrl;
  38. return (
  39. <Upload
  40. className="avatar-uploader"
  41. name="avatar"
  42. showUploadList={false}
  43. action={globalConfig.context + "/techservice/patent/patentFile"}
  44. data={{ 'sign': this.props.name }}
  45. beforeUpload={beforeUpload}
  46. onChange={this.handleChange.bind(this)}
  47. >
  48. {
  49. imageUrl ?
  50. <img src={imageUrl} role="presentation" className="avatar" /> :
  51. <Icon type="plus" className="avatar-uploader-trigger" />
  52. }
  53. </Upload>
  54. );
  55. }
  56. };
  57. const PatentAddFrom = Form.create()(React.createClass({
  58. getInitialState() {
  59. return {
  60. loading: false,
  61. firstCheck: 0,
  62. secondCheck: 0,
  63. thirdCheck: 0
  64. };
  65. },
  66. handleSubmit(e) {
  67. e.preventDefault();
  68. this.props.form.validateFields((err, values) => {
  69. if (!err) {
  70. this.props.spinState(true);
  71. $.ajax({
  72. method: "POST",
  73. dataType: "json",
  74. crossDomain: false,
  75. url: globalConfig.context + "/techservice/patent/clientApplyPatent",
  76. data: {
  77. 'firstInventorIdNumber': values.firstInventorID,
  78. 'firstInventorName': values.firstInventorName,
  79. 'patentDes': values.intro,
  80. 'secondInventorName': values.secondInventorName,
  81. 'thirdInventorName': values.thirdInventorName,
  82. 'firstInventorIsPublish': this.state.firstCheck,
  83. 'secondInventorIsPublish': this.state.secondCheck,
  84. 'thirdInventorIsPublish': this.state.thirdCheck,
  85. 'patentProryStatementUrl': this.state.avatarUrl
  86. }
  87. }).done(function (data) {
  88. if (!data.error.length) {
  89. message.success('保存成功!');
  90. } else {
  91. message.warning(data.error[0].message);
  92. }
  93. }.bind(this)).always(function () {
  94. this.props.spinState(false);
  95. this.props.closeModal();
  96. this.props.form.resetFields();
  97. }.bind(this));
  98. }
  99. });
  100. },
  101. firstInventorCheck(e) {
  102. if (e.target.checked == true) {
  103. this.state.firstCheck = 1;
  104. } else if (e.target.checked == false) {
  105. this.state.firstCheck = 0;
  106. }
  107. },
  108. secondInventorCheck(e) {
  109. if (e.target.checked == true) {
  110. this.state.secondCheck = 1;
  111. } else if (e.target.checked == false) {
  112. this.state.secondCheck = 0;
  113. };
  114. },
  115. thirdInventorCheck(e) {
  116. if (e.target.checked == true) {
  117. this.state.thirdCheck = 1;
  118. } else if (e.target.checked == false) {
  119. this.state.thirdCheck = 0;
  120. };
  121. },
  122. avatarUrl(e) {
  123. this.state.avatarUrl = e;
  124. },
  125. checkIdcardnum(rule, value, callback) {
  126. if (!/(^\d{15}$)|(^\d{17}(\d|X)$)/.test(value)) {
  127. callback('请输入正确的身份证号!');
  128. } else {
  129. callback();
  130. }
  131. },
  132. render() {
  133. const FormItem = Form.Item;
  134. const { getFieldDecorator } = this.props.form;
  135. const formItemLayout = {
  136. labelCol: { span: 3 },
  137. wrapperCol: { span: 16 },
  138. };
  139. const _me = this;
  140. return (
  141. <Form horizontal onSubmit={this.handleSubmit} className="person-form">
  142. <FormItem
  143. labelCol={{ span: 24 }}
  144. wrapperCol={{ span: 24 }}
  145. label="专利简要描述"
  146. >
  147. {getFieldDecorator('intro', {
  148. initialValue: this.state.intro || null
  149. })(
  150. <Input type="textarea"
  151. placeholder="多行输入"
  152. rows={6} />
  153. )}
  154. </FormItem>
  155. <p>第一发明人</p>
  156. <FormItem
  157. {...formItemLayout}
  158. label="姓名"
  159. >
  160. {getFieldDecorator('firstInventorName', {
  161. rules: [{ required: true, message: 'Please input name!' }]
  162. })(
  163. <Input className="mini-input" />
  164. )}
  165. <Checkbox onChange={this.firstInventorCheck}>是否同意专利局公布</Checkbox>
  166. </FormItem>
  167. <FormItem
  168. {...formItemLayout}
  169. label="身份证"
  170. >
  171. {getFieldDecorator('firstInventorID', {
  172. rules: [{ required: true, validator: this.checkIdcardnum, message: '请输入正确的身份证号!' }]
  173. })(
  174. <Input className="mini-input" />
  175. )}
  176. </FormItem>
  177. <p>第二发明人</p>
  178. <FormItem
  179. {...formItemLayout}
  180. label="姓名"
  181. >
  182. {getFieldDecorator('secondInventorName')(
  183. <Input className="mini-input" />
  184. )}
  185. <Checkbox onChange={this.secondInventorCheck}>是否同意专利局公布</Checkbox>
  186. </FormItem>
  187. <p>第三发明人</p>
  188. <FormItem
  189. {...formItemLayout}
  190. label="姓名"
  191. >
  192. {getFieldDecorator('thirdInventorName')(
  193. <Input className="mini-input" />
  194. )}
  195. <Checkbox onChange={this.thirdInventorCheck}>是否同意专利局公布</Checkbox>
  196. </FormItem>
  197. <FormItem
  198. {...formItemLayout}
  199. label="上传代理委托书"
  200. labelCol={{ span: 24 }}
  201. wrapperCol={{ span: 12 }}
  202. >
  203. {getFieldDecorator('avatar')(
  204. <Avatar urlData={this.avatarUrl} name='patent_prory_statement' />
  205. )}
  206. <span>请上传专利代理委托书</span><a onClick={() => { window.open(globalConfig.context + "/techservice/patent/downloadTemplate") }}>模板下载</a>
  207. </FormItem>
  208. <FormItem>
  209. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  210. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  211. </FormItem>
  212. </Form >
  213. );
  214. },
  215. }));
  216. const PatentAdd = React.createClass({
  217. getInitialState() {
  218. return {
  219. visible: false,
  220. loading: false
  221. };
  222. },
  223. showModal() {
  224. this.setState({
  225. visible: true,
  226. });
  227. },
  228. handleOk() {
  229. this.setState({
  230. visible: false,
  231. });
  232. this.props.closeDesc(false);
  233. },
  234. handleCancel(e) {
  235. this.setState({
  236. visible: false,
  237. });
  238. this.props.closeDesc(false);
  239. },
  240. spinChange(e) {
  241. this.setState({
  242. loading: e
  243. });
  244. },
  245. render() {
  246. return (
  247. <div className="patent-addNew">
  248. <Button className="patent-addNew" type="primary" onClick={this.showModal}>申请新专利<Icon type="plus" /></Button>
  249. <Spin spinning={this.state.loading} className='spin-box'>
  250. <Modal title="新专利申请" visible={this.state.visible}
  251. onOk={this.handleOk} onCancel={this.handleCancel}
  252. width='720px'
  253. footer=''
  254. >
  255. <PatentAddFrom spinState={this.spinChange} closeModal={this.handleCancel} />
  256. </Modal>
  257. </Spin>
  258. </div>
  259. );
  260. },
  261. });
  262. export default PatentAdd;