contractAdd.jsx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  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. let theArr = [];
  285. let thedata=data.data;
  286. if (!thedata) {
  287. if (data.error && data.error.length) {
  288. message.warning(data.error[0].message);
  289. };
  290. thedata = {};
  291. };
  292. thedata.map(function (item) {
  293. theArr.push(<Select.Option value={item.id}>{item.name}</Select.Option>)
  294. });
  295. this.setState({
  296. contacts:thedata[0].name,
  297. orderStatusOption: theArr,
  298. });
  299. }.bind(this),
  300. }).always(function () {
  301. this.setState({
  302. loading: false
  303. });
  304. }.bind(this));
  305. },
  306. //选择值时值匹配及联系人函数加载
  307. autoChange(e){
  308. let theType='';
  309. let contactLists=this.state.customerArr||[];
  310. if (e) {
  311. contactLists.map(function (item) {
  312. if (item.name == e.toString()) {
  313. theType = item.id;
  314. }
  315. });
  316. }
  317. this.getNewWoman(theType)
  318. },
  319. render() {
  320. const FormItem = Form.Item;
  321. const { getFieldDecorator } = this.props.form;
  322. const theData = this.state.data || {};
  323. const formItemLayout = {
  324. labelCol: { span: 6 },
  325. wrapperCol: { span: 14 },
  326. };
  327. const dataSources=this.state.customerArr || [];
  328. const options = dataSources.map((group) =>
  329. <Option key={group.id} value={group.name}>{group.name}</Option>
  330. );
  331. const _me = this;
  332. return (
  333. <Form horizontal onSubmit={this.handleSave} id="CopyrightDesc-form">
  334. <div className="clearfix">
  335. {theData.uid ? <FormItem className="half-item"
  336. {...formItemLayout}
  337. label="公司名称" >
  338. <span>{theData.unitName}</span>
  339. </FormItem> : <FormItem className="half-item"
  340. {...formItemLayout}
  341. label="公司名称" >
  342. <AutoComplete
  343. className="certain-category-search"
  344. dropdownClassName="certain-category-search-dropdown"
  345. dropdownMatchSelectWidth={false}
  346. dropdownStyle={{ width: 300 }}
  347. size="large"
  348. style={{ width: '100%' }}
  349. dataSource={options}
  350. placeholder="输入名称"
  351. optionLabelProp="value"
  352. onChange={this.httpChange}
  353. onSelect={this.autoChange}
  354. filterOption={true}
  355. onBlur={this.blurChange}
  356. >
  357. <Input />
  358. </AutoComplete>
  359. </FormItem>
  360. }
  361. <FormItem className="half-item"
  362. {...formItemLayout}
  363. label="联系人" >
  364. <Select placeholder="请选择联系人" value={this.state.contacts} onChange={(e)=>{this.setState({contacts:e})}}
  365. style={{ width: 260 }}
  366. notFoundContent="未获取到联系人列表">
  367. {this.state.orderStatusOption}
  368. </Select>
  369. </FormItem>
  370. <FormItem className="half-item"
  371. {...formItemLayout}
  372. label="合同类型" >
  373. {getFieldDecorator('type', {
  374. initialValue: theData.type
  375. })(
  376. <Select placeholder="请选择合同类型"
  377. style={{ width: 260 }}>
  378. {this.props.typeOption}
  379. </Select>
  380. )}
  381. </FormItem>
  382. <FormItem className="half-item"
  383. {...formItemLayout}
  384. label="前期费用" >
  385. {getFieldDecorator('previousFee', {
  386. initialValue: theData.previousFee
  387. })(
  388. <InputNumber min={0} max={999999} step={0.01} style={{ width: '80px', marginRight: '20px' }} />
  389. )}
  390. <span>万元</span>
  391. </FormItem>
  392. </div>
  393. <FormItem
  394. labelCol={{ span: 3 }}
  395. wrapperCol={{ span: 19 }}
  396. label="合同描述" >
  397. {getFieldDecorator('depict', {
  398. initialValue: theData.depict
  399. })(
  400. <Input type="textarea"
  401. placeholder="多行输入"
  402. rows={4} />
  403. )}
  404. </FormItem>
  405. <div className="clearfix">
  406. <span style={{ float: "left", lineHeight: '32px', marginLeft: '50px' }}>
  407. <Checkbox checked={this.state.highTechCheck} onChange={(e) => {
  408. this.setState({ highTechCheck: e.target.checked });
  409. }}></Checkbox>
  410. </span>
  411. <FormItem className="half-item"
  412. {...formItemLayout}
  413. label={"高企申请"} >
  414. {getFieldDecorator('cognizanceYear', {
  415. initialValue: theData.cognizanceYear ? String(theData.cognizanceYear) : null
  416. })(
  417. <Select placeholder="请选择年份"
  418. style={{ width: 120 }}
  419. onSelect={(e, n) => { this.setState({ year: e }); }}>
  420. {this.state.yearOption}
  421. </Select>
  422. )}
  423. </FormItem>
  424. </div>
  425. <div className="clearfix">
  426. <span style={{ float: "left", lineHeight: '32px', marginLeft: '50px' }}>
  427. <Checkbox checked={this.state.patentCheck} onChange={(e) => {
  428. this.setState({ patentCheck: e.target.checked });
  429. }}></Checkbox>
  430. </span>
  431. <FormItem className="half-item"
  432. {...formItemLayout}
  433. label={"专利申请"} >
  434. {getFieldDecorator('patentNum', {
  435. initialValue: theData.patentNum
  436. })(
  437. <InputNumber />
  438. )}
  439. </FormItem>
  440. </div>
  441. <div className="clearfix">
  442. <span style={{ float: "left", lineHeight: '32px', marginLeft: '50px' }}>
  443. <Checkbox checked={this.state.copyrightCheck} onChange={(e) => {
  444. this.setState({ copyrightCheck: e.target.checked });
  445. }}></Checkbox>
  446. </span>
  447. <FormItem className="half-item"
  448. {...formItemLayout}
  449. label={"软著申请"} >
  450. {getFieldDecorator('copyrightNum', {
  451. initialValue: theData.copyrightNum
  452. })(
  453. <InputNumber />
  454. )}
  455. </FormItem>
  456. </div>
  457. <div className="clearfix">
  458. <span style={{ float: "left", lineHeight: '32px', marginLeft: '50px' }}>
  459. <Checkbox checked={this.state.techProjectCheck} onChange={(e) => {
  460. this.setState({ techProjectCheck: e.target.checked });
  461. }}></Checkbox>
  462. </span>
  463. <FormItem className="half-item"
  464. {...formItemLayout}
  465. label={"科技项目申请"} >
  466. {getFieldDecorator('techProjectNum', {
  467. initialValue: theData.techProjectNum
  468. })(
  469. <InputNumber />
  470. )}
  471. </FormItem>
  472. </div>
  473. <div className="clearfix">
  474. <FormItem className="half-item"
  475. {...formItemLayout}
  476. label={"审核人"} >
  477. {getFieldDecorator('principals')(
  478. <Select
  479. placeholder="请选择审核人"
  480. notFoundContent="未找到"
  481. style={{ width: 260 }}
  482. showSearch
  483. multiple
  484. filterOption={companySearch} >
  485. {this.props.authorOption}
  486. </Select>
  487. )}
  488. </FormItem>
  489. <FormItem className="half-item"
  490. {...formItemLayout}
  491. label="处理时间"
  492. >
  493. {getFieldDecorator('recordTime')(
  494. <DatePicker />
  495. )}
  496. </FormItem>
  497. </div>
  498. <FormItem
  499. labelCol={{ span: 3 }}
  500. wrapperCol={{ span: 19 }}
  501. label="备注" >
  502. {getFieldDecorator('comment', {
  503. initialValue: theData.comment
  504. })(
  505. <Input type="textarea"
  506. placeholder="多行输入"
  507. rows={2} />
  508. )}
  509. </FormItem>
  510. <p style={{ color: '#ea0862', paddingLeft: '40px', marginBottom: '20px' }}>合同提交以后无法修改,请确认提交内容的正确性!</p>
  511. <FormItem style={{ paddingLeft: '40px' }}>
  512. <Button className="set-submit" type="primary" htmlType="submit">保存草稿</Button>
  513. <Button onClick={this.handleSubmit} type="ghost" style={{ marginLeft: '20px' }}>提交</Button>
  514. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  515. </FormItem>
  516. </Form >
  517. );
  518. },
  519. }));
  520. const ContractAdd = React.createClass({
  521. getInitialState() {
  522. return {
  523. visible: false,
  524. loading: false
  525. };
  526. },
  527. showModal() {
  528. this.setState({
  529. visible: true,
  530. data: {}
  531. });
  532. },
  533. handleCancel(e) {
  534. this.setState({
  535. visible: false,
  536. });
  537. this.props.closeAdd(false);
  538. },
  539. componentWillReceiveProps(nextProps) {
  540. if (nextProps.showAdd && nextProps.data) {
  541. this.state.data = nextProps.data;
  542. };
  543. this.state.visible = nextProps.showAdd;
  544. },
  545. spinChange(e) {
  546. this.setState({
  547. loading: e
  548. });
  549. },
  550. render() {
  551. return (
  552. <div className="patent-addNew">
  553. <Button className="patent-addNew" type="primary" onClick={this.showModal}>申请合同<Icon type="plus" /></Button>
  554. <Modal maskClosable={false} title="合同详情"
  555. visible={this.state.visible}
  556. onCancel={this.handleCancel}
  557. width='800px'
  558. footer='' >
  559. <Spin spinning={this.state.loading} className='spin-box'>
  560. <ContractAddFrom
  561. spinState={this.spinChange}
  562. closeModal={this.handleCancel}
  563. visible={this.state.visible}
  564. data={this.state.data}
  565. okClick={() => { this.props.closeAdd(false, true) }}
  566. companyOption={this.props.companyOption}
  567. authorOption={this.props.authorOption}
  568. typeOption={this.props.typeOption} />
  569. </Spin>
  570. </Modal>
  571. </div>
  572. );
  573. },
  574. });
  575. export default ContractAdd;