comPatentAdd.jsx 12 KB

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