contractAdd.jsx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. import React from 'react';
  2. import { Icon, Modal, Button, Form, message, AutoComplete,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 Option = AutoComplete.Option;
  8. const ContractAddFrom = Form.create()(React.createClass({
  9. getContactsList(theUid) {
  10. $.ajax({
  11. method: "get",
  12. dataType: "json",
  13. crossDomain: false,
  14. url: globalConfig.context + "/api/admin/getContacts",
  15. data: {
  16. uid: theUid
  17. },
  18. success: function (data) {
  19. let theOption = [];
  20. if (!data.data) {
  21. if (data.error && data.error.length) {
  22. message.warning(data.error[0].message);
  23. return;
  24. };
  25. };
  26. for (let item in data.data) {
  27. let theData = data.data[item];
  28. theOption.push(
  29. <Select.Option value={item} key={theData}>{theData}</Select.Option>
  30. );
  31. };
  32. this.setState({
  33. contactsOption: theOption
  34. });
  35. }.bind(this),
  36. });
  37. },
  38. getInitialState() {
  39. return {
  40. loading: false,
  41. companyOption: [],
  42. accelerated: 0,
  43. acceleratedDate: 0,
  44. visible: "visible"
  45. };
  46. },
  47. loadData(id) {
  48. this.setState({
  49. loading: true
  50. });
  51. $.ajax({
  52. method: "get",
  53. dataType: "json",
  54. crossDomain: false,
  55. cache: false,
  56. url: globalConfig.context + "/api/admin/contract/detail",
  57. data: {
  58. id: id || this.props.data.id
  59. }
  60. }).done((data) => {
  61. if (!data.data) {
  62. if (data.error && data.error.length) {
  63. message.warning(data.error[0].message);
  64. };
  65. } else {
  66. this.setState({
  67. data: data.data,
  68. patentCheck: data.data.patentNum ? true : false,
  69. copyrightCheck: data.data.copyrightNum ? true : false,
  70. highTechCheck: data.data.cognizanceYear ? true : false,
  71. techProjectCheck: data.data.techProjectNum ? true : false,
  72. });
  73. };
  74. }).always(function () {
  75. this.setState({
  76. loading: false
  77. });
  78. }.bind(this));
  79. },
  80. componentWillMount() {
  81. let d = new Date(), _me = this, theArr = [];
  82. d = d.getFullYear() - 1;
  83. for (let i = d; i < d + 20; i++) {
  84. theArr.push(
  85. <Select.Option value={i.toString()} key={i}>{i}</Select.Option>
  86. )
  87. };
  88. this.state.yearOption = theArr;
  89. if (this.props.data && this.props.data.uid && this.props.data.id) {
  90. this.getContactsList(this.props.data.uid);
  91. this.loadData(this.props.data.id);
  92. } else {
  93. this.state.data = {};
  94. this.state.patentCheck = false;
  95. this.state.copyrightCheck = false;
  96. this.state.highTechCheck = false;
  97. this.state.techProjectCheck = false;
  98. };
  99. },
  100. componentWillReceiveProps(nextProps) {
  101. if (!this.props.visible && nextProps.visible) {
  102. if (nextProps.data && nextProps.data.uid && nextProps.data.id) {
  103. this.getContactsList(nextProps.data.uid);
  104. this.loadData(nextProps.data.id);
  105. } else {
  106. this.state.data = {};
  107. this.state.patentCheck = false;
  108. this.state.copyrightCheck = false;
  109. this.state.highTechCheck = false;
  110. this.state.techProjectCheck = false;
  111. };
  112. this.props.form.resetFields();
  113. };
  114. },
  115. handleSave(e) {
  116. e.preventDefault();
  117. this.props.form.validateFields((err, values) => {
  118. if (!err) {
  119. if (!(this.state.data.uid || this.state.khId) || !this.state.contacts) {
  120. message.warning('请选择一个公司和联系人!');
  121. return;
  122. }
  123. if (!values.patentNum && !values.copyrightNum && !values.cognizanceYear && !values.techProjectNum) {
  124. message.warning('请至少选择一个申报项目!');
  125. return;
  126. };
  127. let thed='';
  128. let conts=this.state.contacts;
  129. this.state.orderStatusOption.map(function(itam){
  130. if(itam.name==conts){
  131. thed=itam.ocbId
  132. }
  133. return thed;
  134. })
  135. this.props.spinState(true);
  136. $.ajax({
  137. method: "POST",
  138. dataType: "json",
  139. crossDomain: false,
  140. url: globalConfig.context + "/api/admin/contract/apply",
  141. data: {
  142. "uid": this.state.data.uid || this.state.khId,
  143. "id": this.state.data.id,
  144. "contacts": thed, //联系人
  145. "type": values.type, //合同类型
  146. "depict": values.depict, // "合同描述",
  147. "patentNum": this.state.patentCheck ? values.patentNum : 0,
  148. "copyrightNum": this.state.copyrightCheck ? values.copyrightNum : 0,
  149. "cognizanceYear": this.state.highTechCheck ? values.cognizanceYear : undefined,
  150. "techProjectNum": this.state.techProjectCheck ? values.techProjectNum : 0,
  151. "previousFee": values.previousFee,
  152. "comment": values.comment //"备注"
  153. }
  154. }).done(function (data) {
  155. if (!data.error.length) {
  156. message.success('保存成功!');
  157. this.props.okClick();
  158. this.props.closeModal();
  159. this.props.form.resetFields();
  160. } else {
  161. message.warning(data.error[0].message);
  162. }
  163. }.bind(this)).always(function () {
  164. this.props.spinState(false);
  165. }.bind(this));
  166. }
  167. });
  168. },
  169. handleSubmit() {
  170. this.props.form.validateFields((err, values) => {
  171. if (!err) {
  172. if (!values.principals || !values.recordTime) {
  173. message.warning('请填写审核信息!');
  174. return;
  175. };
  176. let thed='';
  177. let conts=this.state.contacts;
  178. this.state.orderStatusOption.map(function(itam){
  179. if(itam.name==conts){
  180. thed=itam.ocbId
  181. }
  182. return thed;
  183. })
  184. this.props.spinState(true);
  185. $.ajax({
  186. method: "POST",
  187. dataType: "json",
  188. crossDomain: false,
  189. url: globalConfig.context + "/api/admin/contract/submit",
  190. data: {
  191. "uid": this.state.data.uid || this.state.khId,
  192. "id": this.state.data.id,
  193. "contacts": thed, //联系人
  194. "type": values.type, //合同类型
  195. "depict": values.depict, // "合同描述",
  196. "patentNum": this.state.patentCheck ? values.patentNum : 0,
  197. "copyrightNum": this.state.copyrightCheck ? values.copyrightNum : 0,
  198. "cognizanceYear": this.state.highTechCheck ? values.cognizanceYear : undefined,
  199. "techProjectNum": this.state.techProjectCheck ? values.techProjectNum : 0,
  200. "principals": values.principals,
  201. "previousFee": values.previousFee,
  202. "signDateFormattedDate": values.recordTime ? values.recordTime.format("YYYY-MM-DD HH:mm:ss") : undefined,
  203. "comment": values.comment //"备注"
  204. }
  205. }).done(function (data) {
  206. if (!data.error.length) {
  207. message.success('提交成功!');
  208. this.props.okClick();
  209. this.props.closeModal();
  210. this.props.form.resetFields();
  211. } else {
  212. message.warning(data.error[0].message);
  213. }
  214. }.bind(this)).always(function () {
  215. this.props.spinState(false);
  216. }.bind(this));
  217. }
  218. });
  219. },
  220. //客户名称初始加载
  221. customerList(e){
  222. $.ajax({
  223. method: "get",
  224. dataType: "json",
  225. crossDomain: false,
  226. url: globalConfig.context + "/api/admin/customer/findCustomerByName",
  227. data:{
  228. name:e
  229. },
  230. success: function (data) {
  231. let thedata=data.data;
  232. if (!thedata) {
  233. if (data.error && data.error.length) {
  234. message.warning(data.error[0].message);
  235. };
  236. thedata = {};
  237. };
  238. this.setState({
  239. customerArr:thedata,
  240. });
  241. }.bind(this),
  242. }).always(function () {
  243. this.setState({
  244. loading: false
  245. });
  246. }.bind(this));
  247. },
  248. //值改变时请求客户名称
  249. httpChange(e){
  250. if(e.length>=2){
  251. this.customerList(e);
  252. return;
  253. }
  254. },
  255. //客户输入框失去焦点是判断客户是否存在
  256. blurChange(e){
  257. let theType='';
  258. let contactLists=this.state.customerArr||[];
  259. if (e) {
  260. contactLists.map(function (item) {
  261. if (item.name == e.toString()) {
  262. theType = item.id;
  263. }
  264. });
  265. }
  266. if(!theType){
  267. return message.warning('当前客户名不存在')
  268. };
  269. this.setState({
  270. khId:theType
  271. })
  272. },
  273. //获取联系人下拉框
  274. getNewWoman(ids) {
  275. $.ajax({
  276. method: "get",
  277. dataType: "json",
  278. crossDomain: false,
  279. url: globalConfig.context + "/api/admin/customer/findCustomerContacts",
  280. data:{
  281. uid:ids,
  282. },
  283. success: function (data) {
  284. console.log(data)
  285. let theArr = [];
  286. let thedata=data.data;
  287. if (!thedata) {
  288. if (data.error && data.error.length) {
  289. message.warning(data.error[0].message);
  290. };
  291. thedata = {};
  292. };
  293. thedata.map(function (item) {
  294. theArr.push(<Select.Option value={item.id}>{item.name}</Select.Option>)
  295. });
  296. this.setState({
  297. contacts:thedata[0].name||'',
  298. orderStatusOption: theArr,
  299. });
  300. }.bind(this),
  301. }).always(function () {
  302. this.setState({
  303. loading: false
  304. });
  305. }.bind(this));
  306. },
  307. //选择值时值匹配及联系人函数加载
  308. autoChange(e){
  309. let theType='';
  310. let contactLists=this.state.customerArr||[];
  311. if (e) {
  312. contactLists.map(function (item) {
  313. if (item.name == e.toString()) {
  314. theType = item.id;
  315. }
  316. });
  317. }
  318. this.getNewWoman(theType)
  319. },
  320. render() {
  321. const FormItem = Form.Item;
  322. const { getFieldDecorator } = this.props.form;
  323. const theData = this.state.data || {};
  324. const formItemLayout = {
  325. labelCol: { span: 6 },
  326. wrapperCol: { span: 14 },
  327. };
  328. const dataSources=this.state.customerArr || [];
  329. const options = dataSources.map((group) =>
  330. <Option key={group.id} value={group.name}>{group.name}</Option>
  331. );
  332. const _me = this;
  333. return (
  334. <Form horizontal onSubmit={this.handleSave} id="CopyrightDesc-form">
  335. <div className="clearfix">
  336. {theData.uid ? <FormItem className="half-item"
  337. {...formItemLayout}
  338. label="公司名称" >
  339. <span>{theData.unitName}</span>
  340. </FormItem> : <FormItem className="half-item"
  341. {...formItemLayout}
  342. label="公司名称" >
  343. <AutoComplete
  344. className="certain-category-search"
  345. dropdownClassName="certain-category-search-dropdown"
  346. dropdownMatchSelectWidth={false}
  347. dropdownStyle={{ width: 300 }}
  348. size="large"
  349. style={{ width: '100%' }}
  350. dataSource={options}
  351. placeholder="输入名称"
  352. optionLabelProp="value"
  353. onChange={this.httpChange}
  354. onSelect={this.autoChange}
  355. filterOption={true}
  356. onBlur={this.blurChange}
  357. >
  358. <Input />
  359. </AutoComplete>
  360. </FormItem>
  361. }
  362. <FormItem className="half-item"
  363. {...formItemLayout}
  364. label="联系人" >
  365. <Select placeholder="请选择联系人" value={this.state.contacts} onChange={(e)=>{this.setState({contacts:e})}}
  366. style={{ width: 260 }}
  367. notFoundContent="未获取到联系人列表">
  368. {this.state.orderStatusOption}
  369. </Select>
  370. </FormItem>
  371. <FormItem className="half-item"
  372. {...formItemLayout}
  373. label="合同类型" >
  374. {getFieldDecorator('type', {
  375. initialValue: theData.type
  376. })(
  377. <Select placeholder="请选择合同类型"
  378. style={{ width: 260 }}>
  379. {this.props.typeOption}
  380. </Select>
  381. )}
  382. </FormItem>
  383. <FormItem className="half-item"
  384. {...formItemLayout}
  385. label="前期费用" >
  386. {getFieldDecorator('previousFee', {
  387. initialValue: theData.previousFee
  388. })(
  389. <InputNumber min={0} max={999999} step={0.01} style={{ width: '80px', marginRight: '20px' }} />
  390. )}
  391. <span>万元</span>
  392. </FormItem>
  393. </div>
  394. <FormItem
  395. labelCol={{ span: 3 }}
  396. wrapperCol={{ span: 19 }}
  397. label="合同描述" >
  398. {getFieldDecorator('depict', {
  399. initialValue: theData.depict
  400. })(
  401. <Input type="textarea"
  402. placeholder="多行输入"
  403. rows={4} />
  404. )}
  405. </FormItem>
  406. <div className="clearfix">
  407. <span style={{ float: "left", lineHeight: '32px', marginLeft: '50px' }}>
  408. <Checkbox checked={this.state.highTechCheck} onChange={(e) => {
  409. this.setState({ highTechCheck: e.target.checked });
  410. }}></Checkbox>
  411. </span>
  412. <FormItem className="half-item"
  413. {...formItemLayout}
  414. label={"高企申请"} >
  415. {getFieldDecorator('cognizanceYear', {
  416. initialValue: theData.cognizanceYear ? String(theData.cognizanceYear) : null
  417. })(
  418. <Select placeholder="请选择年份"
  419. style={{ width: 120 }}
  420. onSelect={(e, n) => { this.setState({ year: e }); }}>
  421. {this.state.yearOption}
  422. </Select>
  423. )}
  424. </FormItem>
  425. </div>
  426. <div className="clearfix">
  427. <span style={{ float: "left", lineHeight: '32px', marginLeft: '50px' }}>
  428. <Checkbox checked={this.state.patentCheck} onChange={(e) => {
  429. this.setState({ patentCheck: e.target.checked });
  430. }}></Checkbox>
  431. </span>
  432. <FormItem className="half-item"
  433. {...formItemLayout}
  434. label={"专利申请"} >
  435. {getFieldDecorator('patentNum', {
  436. initialValue: theData.patentNum
  437. })(
  438. <InputNumber />
  439. )}
  440. </FormItem>
  441. </div>
  442. <div className="clearfix">
  443. <span style={{ float: "left", lineHeight: '32px', marginLeft: '50px' }}>
  444. <Checkbox checked={this.state.copyrightCheck} onChange={(e) => {
  445. this.setState({ copyrightCheck: e.target.checked });
  446. }}></Checkbox>
  447. </span>
  448. <FormItem className="half-item"
  449. {...formItemLayout}
  450. label={"软著申请"} >
  451. {getFieldDecorator('copyrightNum', {
  452. initialValue: theData.copyrightNum
  453. })(
  454. <InputNumber />
  455. )}
  456. </FormItem>
  457. </div>
  458. <div className="clearfix">
  459. <span style={{ float: "left", lineHeight: '32px', marginLeft: '50px' }}>
  460. <Checkbox checked={this.state.techProjectCheck} onChange={(e) => {
  461. this.setState({ techProjectCheck: e.target.checked });
  462. }}></Checkbox>
  463. </span>
  464. <FormItem className="half-item"
  465. {...formItemLayout}
  466. label={"科技项目申请"} >
  467. {getFieldDecorator('techProjectNum', {
  468. initialValue: theData.techProjectNum
  469. })(
  470. <InputNumber />
  471. )}
  472. </FormItem>
  473. </div>
  474. <div className="clearfix">
  475. <FormItem className="half-item"
  476. {...formItemLayout}
  477. label={"审核人"} >
  478. {getFieldDecorator('principals')(
  479. <Select
  480. placeholder="请选择审核人"
  481. notFoundContent="未找到"
  482. style={{ width: 260 }}
  483. showSearch
  484. multiple
  485. filterOption={companySearch} >
  486. {this.props.authorOption}
  487. </Select>
  488. )}
  489. </FormItem>
  490. <FormItem className="half-item"
  491. {...formItemLayout}
  492. label="处理时间"
  493. >
  494. {getFieldDecorator('recordTime')(
  495. <DatePicker />
  496. )}
  497. </FormItem>
  498. </div>
  499. <FormItem
  500. labelCol={{ span: 3 }}
  501. wrapperCol={{ span: 19 }}
  502. label="备注" >
  503. {getFieldDecorator('comment', {
  504. initialValue: theData.comment
  505. })(
  506. <Input type="textarea"
  507. placeholder="多行输入"
  508. rows={2} />
  509. )}
  510. </FormItem>
  511. <p style={{ color: '#ea0862', paddingLeft: '40px', marginBottom: '20px' }}>合同提交以后无法修改,请确认提交内容的正确性!</p>
  512. <FormItem style={{ paddingLeft: '40px' }}>
  513. <Button className="set-submit" type="primary" htmlType="submit">保存草稿</Button>
  514. <Button onClick={this.handleSubmit} type="ghost" style={{ marginLeft: '20px' }}>提交</Button>
  515. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  516. </FormItem>
  517. </Form >
  518. );
  519. },
  520. }));
  521. const ContractAdd = React.createClass({
  522. getInitialState() {
  523. return {
  524. visible: false,
  525. loading: false
  526. };
  527. },
  528. showModal() {
  529. this.setState({
  530. visible: true,
  531. data: {}
  532. });
  533. },
  534. handleCancel(e) {
  535. this.setState({
  536. visible: false,
  537. });
  538. this.props.closeAdd(false);
  539. },
  540. componentWillReceiveProps(nextProps) {
  541. if (nextProps.showAdd && nextProps.data) {
  542. this.state.data = nextProps.data;
  543. };
  544. this.state.visible = nextProps.showAdd;
  545. },
  546. spinChange(e) {
  547. this.setState({
  548. loading: e
  549. });
  550. },
  551. render() {
  552. return (
  553. <div className="patent-addNew">
  554. <Button className="patent-addNew" type="primary" onClick={this.showModal}>申请合同<Icon type="plus" /></Button>
  555. <Modal maskClosable={false} title="合同详情"
  556. visible={this.state.visible}
  557. onCancel={this.handleCancel}
  558. width='800px'
  559. footer='' >
  560. <Spin spinning={this.state.loading} className='spin-box'>
  561. <ContractAddFrom
  562. spinState={this.spinChange}
  563. closeModal={this.handleCancel}
  564. visible={this.state.visible}
  565. data={this.state.data}
  566. okClick={() => { this.props.closeAdd(false, true) }}
  567. companyOption={this.props.companyOption}
  568. authorOption={this.props.authorOption}
  569. typeOption={this.props.typeOption} />
  570. </Spin>
  571. </Modal>
  572. </div>
  573. );
  574. },
  575. });
  576. export default ContractAdd;