contractAdd.jsx 19 KB

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