contractAdd.jsx 23 KB

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