patentAdd.jsx 9.1 KB

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