contractAdd.jsx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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. "previousFee": values.previousFee,
  135. "comment": values.comment //"备注"
  136. }
  137. }).done(function (data) {
  138. if (!data.error.length) {
  139. message.success('保存成功!');
  140. this.props.okClick();
  141. this.props.closeModal();
  142. this.props.form.resetFields();
  143. } else {
  144. message.warning(data.error[0].message);
  145. }
  146. }.bind(this)).always(function () {
  147. this.props.spinState(false);
  148. }.bind(this));
  149. }
  150. });
  151. },
  152. handleSubmit() {
  153. this.props.form.validateFields((err, values) => {
  154. if (!err) {
  155. this.props.spinState(true);
  156. $.ajax({
  157. method: "POST",
  158. dataType: "json",
  159. crossDomain: false,
  160. url: globalConfig.context + "/api/admin/contract/submit",
  161. data: {
  162. "uid": this.state.data.uid || values.uid,
  163. "id": this.state.data.id,
  164. "contacts": values.contacts, //联系人
  165. "type": values.type, //合同类型
  166. "depict": values.depict, // "合同描述",
  167. "patentNum": this.state.patentCheck ? values.patentNum : 0,
  168. "copyrightNum": this.state.copyrightCheck ? values.copyrightNum : 0,
  169. "cognizanceYear": this.state.highTechCheck ? values.cognizanceYear : undefined,
  170. "techProjectNum": this.state.techProjectCheck ? values.techProjectNum : 0,
  171. "principals": values.principals,
  172. "previousFee": values.previousFee,
  173. "signDateFormattedDate": values.recordTime ? values.recordTime.format("YYYY-MM-DD HH:mm:ss") : undefined,
  174. "comment": values.comment //"备注"
  175. }
  176. }).done(function (data) {
  177. if (!data.error.length) {
  178. message.success('提交成功!');
  179. this.props.okClick();
  180. this.props.closeModal();
  181. this.props.form.resetFields();
  182. } else {
  183. message.warning(data.error[0].message);
  184. }
  185. }.bind(this)).always(function () {
  186. this.props.spinState(false);
  187. }.bind(this));
  188. }
  189. });
  190. },
  191. render() {
  192. const FormItem = Form.Item;
  193. const { getFieldDecorator } = this.props.form;
  194. const theData = this.state.data || {};
  195. const formItemLayout = {
  196. labelCol: { span: 6 },
  197. wrapperCol: { span: 14 },
  198. };
  199. const _me = this;
  200. return (
  201. <Form horizontal onSubmit={this.handleSave} id="CopyrightDesc-form">
  202. <div className="clearfix">
  203. {theData.uid ? <FormItem className="half-item"
  204. {...formItemLayout}
  205. label="公司名称" >
  206. <span>{theData.unitName}</span>
  207. </FormItem> : <FormItem className="half-item"
  208. {...formItemLayout}
  209. label="公司名称" >
  210. {getFieldDecorator('uid')(
  211. theData.uid ? <span>{theData.unitName}</span> : <Select
  212. placeholder="请选择公司"
  213. notFoundContent="未找到公司"
  214. style={{ width: 260 }}
  215. showSearch
  216. filterOption={companySearch}
  217. onSelect={(e, n) => { this.getContactsList(e); }}>
  218. {this.props.companyOption}
  219. </Select>
  220. )}
  221. </FormItem>
  222. }
  223. <FormItem className="half-item"
  224. {...formItemLayout}
  225. label="联系人" >
  226. {getFieldDecorator('contacts', {
  227. initialValue: theData.contacts
  228. })(
  229. <Select placeholder="请选择联系人"
  230. style={{ width: 260 }}
  231. notFoundContent="未获取到联系人列表">
  232. {this.state.contactsOption}
  233. </Select>
  234. )}
  235. </FormItem>
  236. <FormItem className="half-item"
  237. {...formItemLayout}
  238. label="合同类型" >
  239. {getFieldDecorator('type', {
  240. initialValue: theData.type
  241. })(
  242. <Select placeholder="请选择合同类型"
  243. style={{ width: 260 }}>
  244. {this.props.typeOption}
  245. </Select>
  246. )}
  247. </FormItem>
  248. <FormItem className="half-item"
  249. {...formItemLayout}
  250. label="前期费用" >
  251. {getFieldDecorator('previousFee', {
  252. initialValue: theData.previousFee
  253. })(
  254. <Input style={{ width: '80px', marginRight: '20px' }} />
  255. )}
  256. <span>元</span>
  257. </FormItem>
  258. </div>
  259. <FormItem
  260. labelCol={{ span: 3 }}
  261. wrapperCol={{ span: 19 }}
  262. label="合同描述" >
  263. {getFieldDecorator('depict', {
  264. initialValue: theData.depict
  265. })(
  266. <Input type="textarea"
  267. placeholder="多行输入"
  268. rows={4} />
  269. )}
  270. </FormItem>
  271. <div className="clearfix">
  272. <span style={{ float: "left", lineHeight: '32px', marginLeft: '50px' }}>
  273. <Checkbox checked={this.state.highTechCheck} onChange={(e) => {
  274. this.setState({ highTechCheck: e.target.checked });
  275. }}></Checkbox>
  276. </span>
  277. <FormItem className="half-item"
  278. {...formItemLayout}
  279. label={"高企申请"} >
  280. {getFieldDecorator('cognizanceYear', {
  281. initialValue: theData.cognizanceYear || undefined
  282. })(
  283. <Select placeholder="请选择年份"
  284. style={{ width: 120 }}
  285. onSelect={(e, n) => { this.setState({ year: e }); }}>
  286. {this.state.yearOption}
  287. </Select>
  288. )}
  289. </FormItem>
  290. </div>
  291. <div className="clearfix">
  292. <span style={{ float: "left", lineHeight: '32px', marginLeft: '50px' }}>
  293. <Checkbox checked={this.state.patentCheck} onChange={(e) => {
  294. this.setState({ patentCheck: e.target.checked });
  295. }}></Checkbox>
  296. </span>
  297. <FormItem className="half-item"
  298. {...formItemLayout}
  299. label={"专利申请"} >
  300. {getFieldDecorator('patentNum', {
  301. initialValue: theData.patentNum
  302. })(
  303. <InputNumber />
  304. )}
  305. </FormItem>
  306. </div>
  307. <div className="clearfix">
  308. <span style={{ float: "left", lineHeight: '32px', marginLeft: '50px' }}>
  309. <Checkbox checked={this.state.copyrightCheck} onChange={(e) => {
  310. this.setState({ copyrightCheck: e.target.checked });
  311. }}></Checkbox>
  312. </span>
  313. <FormItem className="half-item"
  314. {...formItemLayout}
  315. label={"软著申请"} >
  316. {getFieldDecorator('copyrightNum', {
  317. initialValue: theData.copyrightNum
  318. })(
  319. <InputNumber />
  320. )}
  321. </FormItem>
  322. </div>
  323. <div className="clearfix">
  324. <span style={{ float: "left", lineHeight: '32px', marginLeft: '50px' }}>
  325. <Checkbox checked={this.state.techProjectCheck} onChange={(e) => {
  326. this.setState({ techProjectCheck: e.target.checked });
  327. }}></Checkbox>
  328. </span>
  329. <FormItem className="half-item"
  330. {...formItemLayout}
  331. label={"科技项目申请"} >
  332. {getFieldDecorator('techProjectNum', {
  333. initialValue: theData.techProjectNum
  334. })(
  335. <InputNumber />
  336. )}
  337. </FormItem>
  338. </div>
  339. <div className="clearfix">
  340. <FormItem className="half-item"
  341. {...formItemLayout}
  342. label={"审核人"} >
  343. {getFieldDecorator('principals')(
  344. <Select
  345. placeholder="请选择审核人"
  346. notFoundContent="未找到"
  347. style={{ width: 260 }}
  348. showSearch
  349. multiple
  350. filterOption={companySearch} >
  351. {this.props.authorOption}
  352. </Select>
  353. )}
  354. </FormItem>
  355. <FormItem className="half-item"
  356. {...formItemLayout}
  357. label="处理时间"
  358. >
  359. {getFieldDecorator('recordTime')(
  360. <DatePicker />
  361. )}
  362. </FormItem>
  363. </div>
  364. <FormItem
  365. labelCol={{ span: 3 }}
  366. wrapperCol={{ span: 19 }}
  367. label="备注" >
  368. {getFieldDecorator('comment', {
  369. initialValue: theData.comment
  370. })(
  371. <Input type="textarea"
  372. placeholder="多行输入"
  373. rows={2} />
  374. )}
  375. </FormItem>
  376. <p style={{ color: '#ea0862', paddingLeft: '40px', marginBottom: '20px' }}>合同提交以后无法修改,请确认提交内容的正确性!</p>
  377. <FormItem style={{ paddingLeft: '40px' }}>
  378. <Button className="set-submit" type="primary" htmlType="submit">保存草稿</Button>
  379. <Button onClick={this.handleSubmit} type="ghost" style={{ marginLeft: '20px' }}>提交</Button>
  380. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  381. </FormItem>
  382. </Form >
  383. );
  384. },
  385. }));
  386. const ContractAdd = React.createClass({
  387. getInitialState() {
  388. return {
  389. visible: false,
  390. loading: false
  391. };
  392. },
  393. showModal() {
  394. this.setState({
  395. visible: true,
  396. data: {}
  397. });
  398. },
  399. handleCancel(e) {
  400. this.setState({
  401. visible: false,
  402. });
  403. this.props.closeAdd(false);
  404. },
  405. componentWillReceiveProps(nextProps) {
  406. if (nextProps.showAdd && nextProps.data) {
  407. this.state.data = nextProps.data;
  408. };
  409. this.state.visible = nextProps.showAdd;
  410. },
  411. spinChange(e) {
  412. this.setState({
  413. loading: e
  414. });
  415. },
  416. render() {
  417. return (
  418. <div className="patent-addNew">
  419. <Button className="patent-addNew" type="primary" onClick={this.showModal}>申请合同<Icon type="plus" /></Button>
  420. <Spin spinning={this.state.loading} className='spin-box'>
  421. <Modal maskClosable={false} title="合同详情"
  422. visible={this.state.visible}
  423. onCancel={this.handleCancel}
  424. width='800px'
  425. footer=''
  426. >
  427. <ContractAddFrom
  428. spinState={this.spinChange}
  429. closeModal={this.handleCancel}
  430. visible={this.state.visible}
  431. data={this.state.data}
  432. okClick={() => { this.props.closeAdd(false, true) }}
  433. companyOption={this.props.companyOption}
  434. authorOption={this.props.authorOption}
  435. typeOption={this.props.typeOption} />
  436. </Modal>
  437. </Spin>
  438. </div>
  439. );
  440. },
  441. });
  442. export default ContractAdd;