contractAdd.jsx 19 KB

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