comPatentAdd.jsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. getSalesmanList() {
  82. this.setState({
  83. loading: true
  84. });
  85. $.ajax({
  86. method: "get",
  87. dataType: "json",
  88. crossDomain: false,
  89. url: globalConfig.context + "/api/admin/salesman",
  90. success: function (data) {
  91. if (!data.data) {
  92. if (data.error && data.error.length) {
  93. message.warning(data.error[0].message);
  94. }
  95. return;
  96. };
  97. let _me = this, theArr = [];
  98. for (var item in data.data) {
  99. theArr.push(
  100. <Select.Option value={item} key={item}>{data.data[item]}</Select.Option>
  101. )
  102. };
  103. this.setState({
  104. salesmanOption: theArr
  105. });
  106. }.bind(this),
  107. }).always(function () {
  108. this.setState({
  109. loading: false
  110. });
  111. }.bind(this));
  112. },
  113. getContactsList(theUid) {
  114. $.ajax({
  115. method: "get",
  116. dataType: "json",
  117. crossDomain: false,
  118. url: globalConfig.context + "/api/admin/customer/findAllContacts",
  119. data: {
  120. uid: theUid || this.state.uid
  121. },
  122. success: function (data) {
  123. let theOption = [];
  124. if (data.error.length || !data.data) {
  125. return;
  126. };
  127. for (let item in data.data) {
  128. let theData = data.data[item];
  129. theOption.push(
  130. <Select.Option value={item} key={theData.name}>{theData.name}</Select.Option>
  131. );
  132. };
  133. this.setState({
  134. contactsOption: theOption
  135. });
  136. }.bind(this),
  137. });
  138. },
  139. getInitialState() {
  140. return {
  141. loading: false,
  142. companyOption: []
  143. // firstCheck: 0,
  144. // secondCheck: 0,
  145. // thirdCheck: 0
  146. };
  147. },
  148. componentWillMount() {
  149. this.getCompanyList();
  150. this.getSalesmanList();
  151. },
  152. handleSubmit(e) {
  153. e.preventDefault();
  154. this.props.form.validateFields((err, values) => {
  155. if (!err) {
  156. this.props.spinState(true);
  157. $.ajax({
  158. method: "POST",
  159. dataType: "json",
  160. crossDomain: false,
  161. url: globalConfig.context + "/api/admin/patent/apply",
  162. data: {
  163. 'uid': values.companyName,
  164. 'contacts': values.contacts,
  165. 'firstInventorIdNumber': values.firstInventorID,
  166. 'firstInventorName': values.firstInventorName,
  167. 'patentDes': values.intro,
  168. 'secondInventorName': values.secondInventorName,
  169. 'office': values.office,
  170. 'thirdInventorName': values.thirdInventorName,
  171. 'patentProryStatementUrl': this.state.avatarUrl,
  172. 'salesman': values.salesman
  173. }
  174. }).done(function (data) {
  175. if (data.error && !data.error.length) {
  176. message.success('保存成功!');
  177. this.props.okClick();
  178. this.props.closeModal();
  179. this.props.form.resetFields();
  180. } else {
  181. message.warning(data.error[0].message);
  182. }
  183. }.bind(this)).always(function () {
  184. this.props.spinState(false);
  185. }.bind(this));
  186. }
  187. });
  188. },
  189. avatarUrl(e) {
  190. this.state.avatarUrl = e;
  191. },
  192. render() {
  193. const FormItem = Form.Item;
  194. const { getFieldDecorator } = this.props.form;
  195. const formItemLayout = {
  196. labelCol: { span: 4 },
  197. wrapperCol: { span: 18 },
  198. };
  199. const _me = this;
  200. return (
  201. <Form horizontal onSubmit={this.handleSubmit} className="person-form">
  202. <FormItem
  203. {...formItemLayout}
  204. label="申请公司"
  205. >
  206. {getFieldDecorator('companyName', {
  207. rules: [{ required: true, message: '请选择一个公司!' }],
  208. initialValue: this.state.companyName || null
  209. })(
  210. <Select placeholder="选择公司"
  211. showSearch
  212. filterOption={companySearch}
  213. onChange={(e) => { this.setState({ companyName: e }); this.getContactsList(e); }}
  214. showSearch={true} style={{ width: 260 }} >
  215. {this.state.companyOption}
  216. </Select>
  217. )}
  218. </FormItem>
  219. <FormItem
  220. {...formItemLayout}
  221. label="联系人"
  222. >
  223. {getFieldDecorator('contacts', {
  224. rules: [{ required: true, message: '请选择一个联系人!' }],
  225. initialValue: this.state.contacts || null
  226. })(
  227. <Select placeholder="选择联系人"
  228. style={{ width: 260 }} >
  229. {this.state.contactsOption}
  230. </Select>
  231. )}
  232. </FormItem>
  233. <FormItem
  234. labelCol={{ span: 24 }}
  235. wrapperCol={{ span: 18 }}
  236. label="专利简要描述"
  237. >
  238. {getFieldDecorator('intro', {
  239. initialValue: this.state.intro || null
  240. })(
  241. <Input type="textarea"
  242. placeholder="多行输入"
  243. rows={6} />
  244. )}
  245. </FormItem>
  246. <FormItem
  247. {...formItemLayout}
  248. label="事务所"
  249. >
  250. {getFieldDecorator('office')(
  251. <Input className="mini-input" />
  252. )}
  253. </FormItem>
  254. <p>第一发明人</p>
  255. <FormItem
  256. {...formItemLayout}
  257. label="姓名"
  258. >
  259. {getFieldDecorator('firstInventorName')(
  260. <Input className="mini-input" />
  261. )}
  262. </FormItem>
  263. <FormItem
  264. {...formItemLayout}
  265. label="身份证"
  266. >
  267. {getFieldDecorator('firstInventorID')(
  268. <Input className="mini-input" />
  269. )}
  270. </FormItem>
  271. <p>第二发明人</p>
  272. <FormItem
  273. {...formItemLayout}
  274. label="姓名"
  275. >
  276. {getFieldDecorator('secondInventorName')(
  277. <Input className="mini-input" />
  278. )}
  279. </FormItem>
  280. <p>第三发明人</p>
  281. <FormItem
  282. {...formItemLayout}
  283. label="姓名"
  284. >
  285. {getFieldDecorator('thirdInventorName')(
  286. <Input className="mini-input" />
  287. )}
  288. </FormItem>
  289. <FormItem
  290. {...formItemLayout}
  291. label="上传代理委托书"
  292. labelCol={{ span: 24 }}
  293. wrapperCol={{ span: 12 }}
  294. >
  295. {getFieldDecorator('avatar')(
  296. <Avatar
  297. urlData={this.avatarUrl}
  298. name='patent_prory_statement'
  299. oid={this.state.companyName}
  300. visible={this.props.visible} />
  301. )}
  302. <p>
  303. <a onClick={() => { window.open(globalConfig.context + "/api/admin/patent/downloadTemplateFile?sign=patent_prory_statement") }}>模板下载</a>
  304. </p>
  305. </FormItem>
  306. <FormItem
  307. {...formItemLayout}
  308. label="营销员"
  309. >
  310. {getFieldDecorator('salesman', {
  311. rules: [{ required: true, message: '请选择一个营销员!' }],
  312. initialValue: this.state.salesman || null
  313. })(
  314. <Select placeholder="选择营销员"
  315. style={{ width: 260 }} >
  316. {this.state.salesmanOption}
  317. </Select>
  318. )}
  319. </FormItem>
  320. <FormItem>
  321. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  322. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  323. </FormItem>
  324. </Form >
  325. );
  326. },
  327. }));
  328. const PatentAdd = React.createClass({
  329. getInitialState() {
  330. return {
  331. visible: false,
  332. loading: false
  333. };
  334. },
  335. showModal() {
  336. this.setState({
  337. visible: true,
  338. });
  339. },
  340. handleOk() {
  341. this.setState({
  342. visible: false,
  343. });
  344. },
  345. handleCancel(e) {
  346. this.setState({
  347. visible: false,
  348. });
  349. this.props.closeDesc(false);
  350. },
  351. spinChange(e) {
  352. this.setState({
  353. loading: e
  354. });
  355. },
  356. render() {
  357. return (
  358. <div className="patent-addNew">
  359. <Button className="patent-addNew" type="primary" onClick={this.showModal}>申请新专利<Icon type="plus" /></Button>
  360. <Modal maskClosable={false} title="新专利申请" visible={this.state.visible}
  361. onOk={this.handleOk} onCancel={this.handleCancel}
  362. width='800px'
  363. footer='' >
  364. <Spin spinning={this.state.loading} className='spin-box'>
  365. <PatentAddFrom
  366. visible={this.state.visible}
  367. spinState={this.spinChange}
  368. closeModal={this.handleCancel}
  369. okClick={() => { this.props.closeDesc(false, true) }} />
  370. </Spin>
  371. </Modal>
  372. </div>
  373. );
  374. },
  375. });
  376. export default PatentAdd;
  377. // <Checkbox onChange={this.firstInventorCheck}>告知专利局是否公布</Checkbox>