comPatentAdd.jsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. import React from 'react';
  2. import { Icon, Modal, Button, Form, Upload, message, Input, Spin, Checkbox, Select } from 'antd';
  3. import './comprehensive.less';
  4. import ajax from 'jquery/src/ajax/xhr.js'
  5. import $ from 'jquery/src/ajax';
  6. import { getBase64, beforeUpload, companySearch } from '../../../tools.js';
  7. class Avatar extends React.Component {
  8. constructor(props) {
  9. super(props);
  10. this.state = {
  11. imageUrl: ''
  12. }
  13. }
  14. handleChange(info) {
  15. if (!this.props.oid || this.props.oid === "") {
  16. message.warning('请先选择公司!');
  17. return;
  18. };
  19. if (info.file.status === 'done') {
  20. // Get this url from response in real world.
  21. getBase64(info.file.originFileObj, imageUrl => this.setState({ imageUrl }));
  22. this.props.urlData(info.file.response.data);
  23. }
  24. }
  25. render() {
  26. return (
  27. <Upload
  28. className="avatar-uploader"
  29. name="avatar"
  30. showUploadList={false}
  31. action={globalConfig.context + "/api/admin/patent/upload"}
  32. data={{ 'sign': this.props.name, 'uid': this.props.oid }}
  33. beforeUpload={beforeUpload}
  34. onChange={this.handleChange.bind(this)}
  35. >
  36. <Button><Icon type="upload" />上传专利代理委托书</Button>
  37. </Upload>
  38. );
  39. }
  40. };
  41. const PatentAddFrom = Form.create()(React.createClass({
  42. getCompanyList() {
  43. this.setState({
  44. loading: true
  45. });
  46. $.ajax({
  47. method: "get",
  48. dataType: "json",
  49. crossDomain: false,
  50. url: globalConfig.context + "/api/admin/getUnitNames",
  51. success: function (data) {
  52. if (data.error.length || !data.data) {
  53. return;
  54. };
  55. let _me = this;
  56. for (var item in data.data) {
  57. _me.state.companyOption.push(
  58. <Select.Option value={item} key={item}>{data.data[item]}</Select.Option>
  59. )
  60. };
  61. }.bind(this),
  62. }).always(function () {
  63. this.setState({
  64. loading: false
  65. });
  66. }.bind(this));
  67. },
  68. getContactsList(theUid) {
  69. $.ajax({
  70. method: "get",
  71. dataType: "json",
  72. crossDomain: false,
  73. url: globalConfig.context + "/api/admin/getContacts",
  74. data: {
  75. uid: theUid || this.state.uid
  76. },
  77. success: function (data) {
  78. let theOption = [];
  79. if (data.error.length || !data.data) {
  80. return;
  81. };
  82. for (let item in data.data) {
  83. let theData = data.data[item];
  84. theOption.push(
  85. <Select.Option value={item} key={theData}>{theData}</Select.Option>
  86. );
  87. };
  88. this.setState({
  89. contactsOption: theOption
  90. });
  91. }.bind(this),
  92. });
  93. },
  94. getInitialState() {
  95. return {
  96. loading: false,
  97. companyOption: [],
  98. firstCheck: 0,
  99. secondCheck: 0,
  100. thirdCheck: 0
  101. };
  102. },
  103. componentWillMount() {
  104. this.getCompanyList();
  105. },
  106. handleSubmit(e) {
  107. e.preventDefault();
  108. this.props.form.validateFields((err, values) => {
  109. if (!err) {
  110. this.props.spinState(true);
  111. $.ajax({
  112. method: "POST",
  113. dataType: "json",
  114. crossDomain: false,
  115. url: globalConfig.context + "/api/admin/patent/apply",
  116. data: {
  117. 'uid': values.companyName,
  118. 'contacts': values.contacts,
  119. 'firstInventorIdNumber': values.firstInventorID,
  120. 'firstInventorName': values.firstInventorName,
  121. 'patentDes': values.intro,
  122. 'secondInventorName': values.secondInventorName,
  123. 'thirdInventorName': values.thirdInventorName,
  124. 'firstInventorIsPublish': this.state.firstCheck,
  125. 'secondInventorIsPublish': this.state.secondCheck,
  126. 'thirdInventorIsPublish': this.state.thirdCheck,
  127. 'patentProryStatementUrl': this.state.avatarUrl
  128. }
  129. }).done(function (data) {
  130. if (!data.error.length) {
  131. message.success('保存成功!');
  132. this.props.okClick();
  133. this.props.closeModal();
  134. } else {
  135. message.warning(data.error[0].message);
  136. }
  137. }.bind(this)).always(function () {
  138. this.props.spinState(false);
  139. this.props.form.resetFields();
  140. }.bind(this));
  141. }
  142. });
  143. },
  144. firstInventorCheck(e) {
  145. if (e.target.checked == true) {
  146. this.state.firstCheck = 1;
  147. } else if (e.target.checked == false) {
  148. this.state.firstCheck = 0;
  149. }
  150. },
  151. secondInventorCheck(e) {
  152. if (e.target.checked == true) {
  153. this.state.secondCheck = 1;
  154. } else if (e.target.checked == false) {
  155. this.state.secondCheck = 0;
  156. };
  157. },
  158. thirdInventorCheck(e) {
  159. if (e.target.checked == true) {
  160. this.state.thirdCheck = 1;
  161. } else if (e.target.checked == false) {
  162. this.state.thirdCheck = 0;
  163. };
  164. },
  165. avatarUrl(e) {
  166. this.state.avatarUrl = e;
  167. },
  168. render() {
  169. const FormItem = Form.Item;
  170. const { getFieldDecorator } = this.props.form;
  171. const formItemLayout = {
  172. labelCol: { span: 3 },
  173. wrapperCol: { span: 14 },
  174. };
  175. const _me = this;
  176. return (
  177. <Form horizontal onSubmit={this.handleSubmit} className="person-form">
  178. <FormItem
  179. {...formItemLayout}
  180. label="申请公司"
  181. >
  182. {getFieldDecorator('companyName', {
  183. rules: [{ required: true, message: '请选择一个公司!' }],
  184. initialValue: this.state.companyName || null
  185. })(
  186. <Select placeholder="选择公司"
  187. showSearch
  188. filterOption={companySearch}
  189. onChange={(e) => { this.setState({ companyName: e }); this.getContactsList(e); }}
  190. showSearch={true} style={{ width: 200 }} >
  191. {this.state.companyOption}
  192. </Select>
  193. )}
  194. </FormItem>
  195. <FormItem
  196. {...formItemLayout}
  197. label="联系人"
  198. >
  199. {getFieldDecorator('contacts', {
  200. rules: [{ required: true, message: '请选择一个联系人!' }],
  201. initialValue: this.state.contacts || null
  202. })(
  203. <Select placeholder="选择联系人"
  204. style={{ width: 200 }} >
  205. {this.state.contactsOption}
  206. </Select>
  207. )}
  208. </FormItem>
  209. <FormItem
  210. labelCol={{ span: 24 }}
  211. wrapperCol={{ span: 18 }}
  212. label="专利简要描述"
  213. >
  214. {getFieldDecorator('intro', {
  215. initialValue: this.state.intro || null
  216. })(
  217. <Input type="textarea"
  218. placeholder="多行输入"
  219. rows={6} />
  220. )}
  221. </FormItem>
  222. <p>第一发明人</p>
  223. <FormItem
  224. {...formItemLayout}
  225. label="姓名"
  226. >
  227. {getFieldDecorator('firstInventorName', {
  228. rules: [{ required: true, message: 'Please input name!' }]
  229. })(
  230. <Input className="mini-input" />
  231. )}
  232. <Checkbox onChange={this.firstInventorCheck}>告知专利局是否公布</Checkbox>
  233. </FormItem>
  234. <FormItem
  235. {...formItemLayout}
  236. label="身份证"
  237. >
  238. {getFieldDecorator('firstInventorID', {
  239. rules: [{ required: true, message: 'Please input ID!' }]
  240. })(
  241. <Input className="mini-input" />
  242. )}
  243. </FormItem>
  244. <p>第二发明人</p>
  245. <FormItem
  246. {...formItemLayout}
  247. label="姓名"
  248. >
  249. {getFieldDecorator('secondInventorName')(
  250. <Input className="mini-input" />
  251. )}
  252. <Checkbox onChange={this.secondInventorCheck}>告知专利局是否公布</Checkbox>
  253. </FormItem>
  254. <p>第三发明人</p>
  255. <FormItem
  256. {...formItemLayout}
  257. label="姓名"
  258. >
  259. {getFieldDecorator('thirdInventorName')(
  260. <Input className="mini-input" />
  261. )}
  262. <Checkbox onChange={this.thirdInventorCheck}>告知专利局是否公布</Checkbox>
  263. </FormItem>
  264. <FormItem
  265. {...formItemLayout}
  266. label="上传代理委托书"
  267. labelCol={{ span: 24 }}
  268. wrapperCol={{ span: 12 }}
  269. >
  270. {getFieldDecorator('avatar')(
  271. <Avatar urlData={this.avatarUrl} name='patent_prory_statement' oid={this.state.companyName} />
  272. )}
  273. <p>
  274. <a onClick={() => { window.open(globalConfig.context + "/api/admin/patent/downloadTemplateFile?sign=patent_prory_statement") }}>模板下载</a>
  275. </p>
  276. </FormItem>
  277. <FormItem>
  278. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  279. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  280. </FormItem>
  281. </Form >
  282. );
  283. },
  284. }));
  285. const PatentAdd = React.createClass({
  286. getInitialState() {
  287. return {
  288. visible: false,
  289. loading: false
  290. };
  291. },
  292. showModal() {
  293. this.setState({
  294. visible: true,
  295. });
  296. },
  297. handleOk() {
  298. this.setState({
  299. visible: false,
  300. });
  301. },
  302. handleCancel(e) {
  303. this.setState({
  304. visible: false,
  305. });
  306. this.props.closeDesc(false);
  307. },
  308. spinChange(e) {
  309. this.setState({
  310. loading: e
  311. });
  312. },
  313. render() {
  314. return (
  315. <div className="patent-addNew">
  316. <Button className="patent-addNew" type="primary" onClick={this.showModal}>申请新专利<Icon type="plus" /></Button>
  317. <Spin spinning={this.state.loading} className='spin-box'>
  318. <Modal title="新专利申请" visible={this.state.visible}
  319. onOk={this.handleOk} onCancel={this.handleCancel}
  320. width='800px'
  321. footer=''
  322. >
  323. <PatentAddFrom
  324. spinState={this.spinChange}
  325. closeModal={this.handleCancel}
  326. okClick={() => { this.props.closeDesc(false, true) }} />
  327. </Modal>
  328. </Spin>
  329. </div>
  330. );
  331. },
  332. });
  333. export default PatentAdd;