patentAdd.jsx 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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 + "/api/user/patent/upload"}
  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. }.bind(this));
  96. }
  97. });
  98. },
  99. firstInventorCheck(e) {
  100. if ( e.target.checked == true ) {
  101. this.state.firstCheck = 1;
  102. } else if ( e.target.checked == false ) {
  103. this.state.firstCheck = 0;
  104. }
  105. },
  106. secondInventorCheck(e) {
  107. if ( e.target.checked == true ) {
  108. this.state.secondCheck = 1;
  109. } else if ( e.target.checked == false ) {
  110. this.state.secondCheck = 0;
  111. };
  112. },
  113. thirdInventorCheck(e) {
  114. if ( e.target.checked == true ) {
  115. this.state.thirdCheck = 1;
  116. } else if ( e.target.checked == false ) {
  117. this.state.thirdCheck = 0;
  118. };
  119. },
  120. avatarUrl(e){
  121. this.state.avatarUrl = e;
  122. },
  123. render() {
  124. const FormItem = Form.Item;
  125. const { getFieldDecorator } = this.props.form;
  126. const formItemLayout = {
  127. labelCol: { span: 3 },
  128. wrapperCol: { span: 12 },
  129. };
  130. const _me = this;
  131. return (
  132. <Form horizontal onSubmit={this.handleSubmit} className="person-form">
  133. <FormItem
  134. labelCol={{ span: 24 }}
  135. wrapperCol={{ span: 18 }}
  136. label="专利简要描述"
  137. >
  138. {getFieldDecorator('intro', {
  139. initialValue: this.state.intro || null
  140. })(
  141. <Input type="textarea"
  142. placeholder="多行"
  143. rows={6} />
  144. )}
  145. </FormItem>
  146. <p>第一发明人</p>
  147. <FormItem
  148. {...formItemLayout}
  149. label="姓名"
  150. >
  151. {getFieldDecorator('firstInventorName', {
  152. rules: [{ required: true, message: 'Please input name!' }]
  153. })(
  154. <Input className="mini-input"/>
  155. )}
  156. <Checkbox onChange={this.firstInventorCheck}>是否公布</Checkbox>
  157. </FormItem>
  158. <FormItem
  159. {...formItemLayout}
  160. label="身份证"
  161. >
  162. {getFieldDecorator('firstInventorID', {
  163. rules: [{ required: true, message: 'Please input ID!' }]
  164. })(
  165. <Input className="mini-input"/>
  166. )}
  167. </FormItem>
  168. <p>第二发明人</p>
  169. <FormItem
  170. {...formItemLayout}
  171. label="姓名"
  172. >
  173. {getFieldDecorator('secondInventorName')(
  174. <Input className="mini-input"/>
  175. )}
  176. <Checkbox onChange={this.secondInventorCheck}>是否公布</Checkbox>
  177. </FormItem>
  178. <p>第三发明人</p>
  179. <FormItem
  180. {...formItemLayout}
  181. label="姓名"
  182. >
  183. {getFieldDecorator('thirdInventorName')(
  184. <Input className="mini-input"/>
  185. )}
  186. <Checkbox onChange={this.thirdInventorCheck}>是否公布</Checkbox>
  187. </FormItem>
  188. <FormItem
  189. {...formItemLayout}
  190. label="上传代理委托书"
  191. labelCol={{ span: 24 }}
  192. wrapperCol={{ span: 12 }}
  193. >
  194. {getFieldDecorator('avatar')(
  195. <Avatar urlData={this.avatarUrl} name='patent_prory_statement' />
  196. )}
  197. <span>请上传专利代理委托书</span><a href="">模板下载</a>
  198. </FormItem>
  199. <FormItem>
  200. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  201. <Button type="ghost" style={{marginLeft:'20px'}} onClick={this.props.closeBtn}>取消</Button>
  202. </FormItem>
  203. </Form >
  204. );
  205. },
  206. }));
  207. const PatentAdd = React.createClass({
  208. getInitialState() {
  209. return {
  210. visible: false,
  211. loading: false
  212. };
  213. },
  214. showModal() {
  215. this.setState({
  216. visible: true,
  217. });
  218. },
  219. handleOk() {
  220. this.setState({
  221. visible: false,
  222. });
  223. },
  224. handleCancel(e) {
  225. this.setState({
  226. visible: false,
  227. });
  228. },
  229. spinChange(e) {
  230. this.setState({
  231. loading: e
  232. });
  233. },
  234. render() {
  235. return (
  236. <div className="patent-addNew">
  237. <Button className="patent-addNew" type="primary" onClick={this.showModal}>申请新专利<Icon type="plus" /></Button>
  238. <Spin spinning={this.state.loading} className='spin-box'>
  239. <Modal title="新专利申请" visible={this.state.visible}
  240. onOk={this.handleOk} onCancel={this.handleCancel}
  241. width='800px'
  242. footer=''
  243. >
  244. <PatentAddFrom spinState={this.spinChange} closeBtn={this.handleCancel}/>
  245. </Modal>
  246. </Spin>
  247. </div>
  248. );
  249. },
  250. });
  251. export default PatentAdd;