contractAdd.jsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. import React from 'react';
  2. import { Icon, Modal, Button, Form, message, Input, Spin, Select, Checkbox, InputNumber, DatePicker } from 'antd';
  3. import './contract.less';
  4. import { companySearch } from '../../../tools.js';
  5. import ajax from 'jquery/src/ajax/xhr.js'
  6. import $ from 'jquery/src/ajax';
  7. const ContractAddFrom = Form.create()(React.createClass({
  8. getContactsList(theUid) {
  9. $.ajax({
  10. method: "get",
  11. dataType: "json",
  12. crossDomain: false,
  13. url: globalConfig.context + "/api/admin/getContacts",
  14. data: {
  15. uid: theUid
  16. },
  17. success: function (data) {
  18. let theOption = [];
  19. if (!data.data) {
  20. if (data.error && data.error.length) {
  21. message.warning(data.error[0].message);
  22. return;
  23. };
  24. };
  25. for (let item in data.data) {
  26. let theData = data.data[item];
  27. theOption.push(
  28. <Select.Option value={item} key={theData}>{theData}</Select.Option>
  29. );
  30. };
  31. this.setState({
  32. contactsOption: theOption
  33. });
  34. }.bind(this),
  35. });
  36. },
  37. getInitialState() {
  38. return {
  39. loading: false,
  40. companyOption: [],
  41. accelerated: 0,
  42. acceleratedDate: 0,
  43. visible: "visible"
  44. };
  45. },
  46. componentWillMount() {
  47. let d = new Date(), _me = this, theArr = [];
  48. d = d.getFullYear() - 1;
  49. for (let i = d; i < d + 20; i++) {
  50. theArr.push(
  51. <Select.Option value={i.toString()} key={i}>{i}</Select.Option>
  52. )
  53. };
  54. this.state.yearOption = theArr;
  55. if (this.props.data) {
  56. this.getContactsList(this.props.data.uid);
  57. this.state.data = this.props.data || {};
  58. };
  59. },
  60. componentWillReceiveProps(nextProps) {
  61. if (!this.props.visible && nextProps.visible) {
  62. this.state.patentCheck = false;
  63. this.state.copyrightCheck = false;
  64. this.state.highTechCheck = false;
  65. this.state.techProjectCheck = false;
  66. if (nextProps.data.uid) {
  67. this.getContactsList(nextProps.data.uid);
  68. };
  69. this.state.data = nextProps.data || {};
  70. this.props.form.resetFields();
  71. };
  72. },
  73. handleSave(e) {
  74. e.preventDefault();
  75. this.props.form.validateFields((err, values) => {
  76. if (!values.uid || values.uid === "") {
  77. message.warning('请先选择公司!');
  78. return;
  79. };
  80. if (!err) {
  81. this.props.spinState(true);
  82. $.ajax({
  83. method: "POST",
  84. dataType: "json",
  85. crossDomain: false,
  86. url: globalConfig.context + "/api/admin/contract/apply",
  87. data: {
  88. "uid": values.uid,
  89. "contacts": values.contacts, //联系人
  90. "type": values.type, //合同类型
  91. "depict": values.depict, // "合同描述",
  92. "patentNum": this.state.patentCheck ? values.patentNum : undefined,
  93. "copyrightNum": this.state.copyrightCheck ? values.copyrightNum : undefined,
  94. "cognizanceYear": this.state.highTechCheck ? values.cognizanceYear : undefined,
  95. "techProjectNum": this.state.techProjectCheck ? values.techProjectNum : undefined,
  96. "comment": values.comment //"备注"
  97. }
  98. }).done(function (data) {
  99. if (!data.error.length) {
  100. message.success('保存成功!');
  101. this.props.okClick();
  102. this.props.closeModal();
  103. this.props.form.resetFields();
  104. } else {
  105. message.warning(data.error[0].message);
  106. }
  107. }.bind(this)).always(function () {
  108. this.props.spinState(false);
  109. }.bind(this));
  110. }
  111. });
  112. },
  113. handleSubmit() {
  114. this.props.form.validateFields((err, values) => {
  115. if (!values.uid || values.uid === "") {
  116. message.warning('请先选择公司!');
  117. return;
  118. };
  119. if (!err) {
  120. this.props.spinState(true);
  121. $.ajax({
  122. method: "POST",
  123. dataType: "json",
  124. crossDomain: false,
  125. url: globalConfig.context + "/api/admin/contract/submit",
  126. data: {
  127. "uid": values.uid,
  128. "contacts": values.contacts, //联系人
  129. "type": values.type, //合同类型
  130. "depict": values.depict, // "合同描述",
  131. "patentNum": this.state.patentCheck ? values.patentNum : undefined,
  132. "copyrightNum": this.state.copyrightCheck ? values.copyrightNum : undefined,
  133. "cognizanceYear": this.state.highTechCheck ? values.cognizanceYear : undefined,
  134. "techProjectNum": this.state.techProjectCheck ? values.techProjectNum : undefined,
  135. "principals": values.principals,
  136. "comment": values.comment //"备注"
  137. }
  138. }).done(function (data) {
  139. if (!data.error.length) {
  140. message.success('提交成功!');
  141. this.props.okClick();
  142. this.props.closeModal();
  143. this.props.form.resetFields();
  144. } else {
  145. message.warning(data.error[0].message);
  146. }
  147. }.bind(this)).always(function () {
  148. this.props.spinState(false);
  149. }.bind(this));
  150. }
  151. });
  152. },
  153. render() {
  154. const FormItem = Form.Item;
  155. const { getFieldDecorator } = this.props.form;
  156. const theData = this.state.data || {};
  157. const formItemLayout = {
  158. labelCol: { span: 6 },
  159. wrapperCol: { span: 14 },
  160. };
  161. const _me = this;
  162. return (
  163. <Form horizontal onSubmit={this.handleSave} id="CopyrightDesc-form">
  164. <div className="clearfix">
  165. <FormItem className="half-item"
  166. {...formItemLayout}
  167. label="公司名称" >
  168. {getFieldDecorator('uid', {
  169. initialValue: theData.uid
  170. })(
  171. theData.uid ? <span>{theData.unitName}</span> : <Select
  172. placeholder="请选择公司"
  173. notFoundContent="未找到公司"
  174. style={{ width: 260 }}
  175. showSearch
  176. filterOption={companySearch}
  177. onSelect={(e, n) => { this.getContactsList(e); }}>
  178. {this.props.companyOption}
  179. </Select>
  180. )}
  181. </FormItem>
  182. <FormItem className="half-item"
  183. {...formItemLayout}
  184. label="联系人" >
  185. {getFieldDecorator('contacts', {
  186. initialValue: theData.contacts
  187. })(
  188. <Select placeholder="请选择联系人"
  189. style={{ width: 260 }}
  190. notFoundContent="未获取到联系人列表">
  191. {this.state.contactsOption}
  192. </Select>
  193. )}
  194. </FormItem>
  195. <FormItem className="half-item"
  196. {...formItemLayout}
  197. label="合同类型" >
  198. {getFieldDecorator('type', {
  199. initialValue: theData.type
  200. })(
  201. <Select placeholder="请选择合同类型"
  202. style={{ width: 260 }}>
  203. {this.props.typeOption}
  204. </Select>
  205. )}
  206. </FormItem>
  207. </div>
  208. <FormItem
  209. labelCol={{ span: 3 }}
  210. wrapperCol={{ span: 19 }}
  211. label="合同描述" >
  212. {getFieldDecorator('depict', {
  213. initialValue: theData.depict
  214. })(
  215. <Input type="textarea"
  216. placeholder="多行输入"
  217. rows={4} />
  218. )}
  219. </FormItem>
  220. <div className="clearfix">
  221. <span style={{ float: "left", lineHeight: '32px', marginLeft: '50px' }}>
  222. <Checkbox checked={this.state.highTechCheck} onChange={(e) => {
  223. this.setState({ highTechCheck: e.target.checked });
  224. }}></Checkbox>
  225. </span>
  226. <FormItem className="half-item"
  227. {...formItemLayout}
  228. label={"高企申请"} >
  229. {getFieldDecorator('cognizanceYear', {
  230. initialValue: theData.cognizanceYear
  231. })(
  232. <Select placeholder="请选择年份"
  233. style={{ width: 120 }}
  234. onSelect={(e, n) => { this.setState({ year: e }); }}>
  235. {this.state.yearOption}
  236. </Select>
  237. )}
  238. </FormItem>
  239. </div>
  240. <div className="clearfix">
  241. <span style={{ float: "left", lineHeight: '32px', marginLeft: '50px' }}>
  242. <Checkbox checked={this.state.patentCheck} onChange={(e) => {
  243. this.setState({ patentCheck: e.target.checked });
  244. }}></Checkbox>
  245. </span>
  246. <FormItem className="half-item"
  247. {...formItemLayout}
  248. label={"专利申请"} >
  249. {getFieldDecorator('patentNum', {
  250. initialValue: theData.patentNum
  251. })(
  252. <InputNumber />
  253. )}
  254. </FormItem>
  255. </div>
  256. <div className="clearfix">
  257. <span style={{ float: "left", lineHeight: '32px', marginLeft: '50px' }}>
  258. <Checkbox checked={this.state.copyrightCheck} onChange={(e) => {
  259. this.setState({ copyrightCheck: e.target.checked });
  260. }}></Checkbox>
  261. </span>
  262. <FormItem className="half-item"
  263. {...formItemLayout}
  264. label={"软著申请"} >
  265. {getFieldDecorator('copyrightNum', {
  266. initialValue: theData.copyrightNum
  267. })(
  268. <InputNumber />
  269. )}
  270. </FormItem>
  271. </div>
  272. <div className="clearfix">
  273. <span style={{ float: "left", lineHeight: '32px', marginLeft: '50px' }}>
  274. <Checkbox checked={this.state.techProjectCheck} onChange={(e) => {
  275. this.setState({ techProjectCheck: e.target.checked });
  276. }}></Checkbox>
  277. </span>
  278. <FormItem className="half-item"
  279. {...formItemLayout}
  280. label={"科技项目申请"} >
  281. {getFieldDecorator('techProjectNum', {
  282. initialValue: theData.techProjectNum
  283. })(
  284. <InputNumber />
  285. )}
  286. </FormItem>
  287. </div>
  288. <div className="clearfix">
  289. <FormItem className="half-item"
  290. {...formItemLayout}
  291. label={"审核人"} >
  292. {getFieldDecorator('principals')(
  293. <Select
  294. placeholder="请选择审核人"
  295. notFoundContent="未找到"
  296. style={{ width: 260 }}
  297. showSearch
  298. multiple
  299. filterOption={companySearch} >
  300. {this.props.authorOption}
  301. </Select>
  302. )}
  303. </FormItem>
  304. <FormItem className="half-item"
  305. {...formItemLayout}
  306. label="处理时间"
  307. >
  308. {getFieldDecorator('recordTime')(
  309. <DatePicker />
  310. )}
  311. </FormItem>
  312. </div>
  313. <FormItem
  314. labelCol={{ span: 3 }}
  315. wrapperCol={{ span: 19 }}
  316. label="备注" >
  317. {getFieldDecorator('comment', {
  318. initialValue: theData.comment
  319. })(
  320. <Input type="textarea"
  321. placeholder="多行输入"
  322. rows={2} />
  323. )}
  324. </FormItem>
  325. <FormItem style={{ paddingLeft: '40px' }}>
  326. <Button className="set-submit" type="primary" htmlType="submit">保存草稿</Button>
  327. <Button onClick={this.handleSubmit} type="ghost" style={{ marginLeft: '20px' }}>提交</Button>
  328. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  329. </FormItem>
  330. </Form >
  331. );
  332. },
  333. }));
  334. const ContractAdd = React.createClass({
  335. getInitialState() {
  336. return {
  337. visible: false,
  338. loading: false
  339. };
  340. },
  341. showModal() {
  342. this.setState({
  343. visible: true,
  344. data: {}
  345. });
  346. },
  347. handleCancel(e) {
  348. this.setState({
  349. visible: false,
  350. });
  351. this.props.closeAdd(false);
  352. },
  353. componentWillReceiveProps(nextProps) {
  354. if (nextProps.showAdd && nextProps.data) {
  355. this.state.data = nextProps.data;
  356. };
  357. this.state.visible = nextProps.showAdd;
  358. },
  359. spinChange(e) {
  360. this.setState({
  361. loading: e
  362. });
  363. },
  364. render() {
  365. return (
  366. <div className="patent-addNew">
  367. <Button className="patent-addNew" type="primary" onClick={this.showModal}>申请合同<Icon type="plus" /></Button>
  368. <Spin spinning={this.state.loading} className='spin-box'>
  369. <Modal title="申请新合同"
  370. visible={this.state.visible}
  371. onCancel={this.handleCancel}
  372. width='800px'
  373. footer=''
  374. >
  375. <ContractAddFrom
  376. spinState={this.spinChange}
  377. closeModal={this.handleCancel}
  378. visible={this.state.visible}
  379. data={this.state.data}
  380. okClick={() => { this.props.closeAdd(false, true) }}
  381. companyOption={this.props.companyOption}
  382. authorOption={this.props.authorOption}
  383. typeOption={this.props.typeOption} />
  384. </Modal>
  385. </Spin>
  386. </div>
  387. );
  388. },
  389. });
  390. export default ContractAdd;