changePatent.jsx 10 KB

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