contractAdd.jsx 18 KB

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