contract.jsx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. import React from 'react';
  2. import { AutoComplete,Icon, Button, Input, Select, Spin, Table, DatePicker, message, Cascader, Switch, Modal } from 'antd';
  3. import { contractStateList, contractTypeList } from '../../../dataDic.js';
  4. import { provinceSelect, getProvince } from '../../../NewDicProvinceList';
  5. import { companySearch, getContractState, getContractType, getSearchUrl } from '../../../tools.js';
  6. import ajax from 'jquery/src/ajax/xhr.js';
  7. import $ from 'jquery/src/ajax';
  8. import ContractAdd from './contractAdd.jsx';
  9. import ContractDetail from './contractDetail.jsx';
  10. const Option = AutoComplete.Option;
  11. import moment from 'moment';
  12. import './contract.less';
  13. const Contract = React.createClass({
  14. loadData(pageNo) {
  15. this.state.data = [];
  16. this.setState({
  17. loading: true
  18. });
  19. $.ajax({
  20. method: "get",
  21. dataType: "json",
  22. crossDomain: false,
  23. url: globalConfig.context + "/api/admin/contract/list",
  24. data: {
  25. pageNo: pageNo || 1,
  26. pageSize: this.state.pagination.pageSize,
  27. province: this.state.province ? this.state.province[0] : undefined,
  28. uid: this.state.khId,
  29. type: this.state.contractType,
  30. status: this.state.contractState,
  31. contractId: this.state.contractId,
  32. startDateFormattedDate: this.state.startDateFormattedDate,
  33. endDateFormattedDate: this.state.endDateFormattedDate,
  34. },
  35. success: function (data) {
  36. if (data.error.length || !data.data || !data.data.list) {
  37. message.warning(data.error[0].message);
  38. return;
  39. };
  40. for (let i = 0; i < data.data.list.length; i++) {
  41. let thisdata = data.data.list[i];
  42. this.state.data.push({
  43. key: i,
  44. completeDate: thisdata.completeDate,
  45. completeDateFormattedDate: thisdata.completeDateFormattedDate,
  46. contacts: thisdata.contacts,
  47. depict: thisdata.depict,
  48. founder: thisdata.founder,
  49. id: thisdata.id,
  50. province: thisdata.province,
  51. serialNumber: thisdata.serialNumber,
  52. signDate: thisdata.signDate,
  53. signDateFormattedDate: thisdata.signDateFormattedDate,
  54. status: thisdata.status,
  55. type: thisdata.type,
  56. uid: thisdata.uid,
  57. unitName: thisdata.unitName,
  58. });
  59. };
  60. this.state.pagination.defaultCurrent = data.data.pageNo;
  61. this.state.pagination.total = data.data.totalCount;
  62. this.setState({
  63. dataSource: this.state.data,
  64. pagination: this.state.pagination
  65. });
  66. }.bind(this),
  67. }).always(function () {
  68. this.setState({
  69. loading: false
  70. });
  71. }.bind(this));
  72. },
  73. getAuthorList() {
  74. this.setState({
  75. loading: true
  76. });
  77. $.ajax({
  78. method: "get",
  79. dataType: "json",
  80. crossDomain: false,
  81. url: globalConfig.context + "/api/admin/contract/principal",
  82. success: function (data) {
  83. if (!data.data) {
  84. if (data.error && data.error.length) {
  85. message.warning(data.error[0].message);
  86. };
  87. return;
  88. };
  89. let _me = this, theArr = [];
  90. for (var item in data.data) {
  91. theArr.push(
  92. <Select.Option value={item} key={item}>{data.data[item]}</Select.Option>
  93. )
  94. };
  95. this.setState({
  96. authorOption: theArr
  97. });
  98. }.bind(this),
  99. }).always(function () {
  100. this.setState({
  101. loading: false
  102. });
  103. }.bind(this));
  104. },
  105. getCompanyList() {
  106. this.setState({
  107. loading: true
  108. });
  109. $.ajax({
  110. method: "get",
  111. dataType: "json",
  112. crossDomain: false,
  113. url: globalConfig.context + "/api/admin/getUnitNames",
  114. success: function (data) {
  115. if (data.error.length || !data.data) {
  116. return;
  117. };
  118. let _me = this, theArr = [];
  119. for (var item in data.data) {
  120. theArr.push(
  121. <Select.Option value={item} key={item}>{data.data[item]}</Select.Option>
  122. )
  123. };
  124. this.setState({
  125. companyOption: theArr
  126. });
  127. }.bind(this),
  128. }).always(function () {
  129. this.setState({
  130. loading: false
  131. });
  132. }.bind(this));
  133. },
  134. getStateList() {
  135. this.setState({
  136. loading: true
  137. });
  138. $.ajax({
  139. method: "get",
  140. dataType: "json",
  141. crossDomain: false,
  142. url: globalConfig.context + "/api/admin/contract/status",
  143. success: function (data) {
  144. if (!data.data) {
  145. if (data.error && data.error.length) {
  146. message.warning(data.error[0].message);
  147. return;
  148. };
  149. };
  150. let _me = this, theArr = [];
  151. for (var item in data.data) {
  152. theArr.push(
  153. <Select.Option value={item} key={item}>{data.data[item]}</Select.Option>
  154. )
  155. };
  156. this.setState({
  157. statusOption: theArr
  158. });
  159. }.bind(this),
  160. }).always(function () {
  161. this.setState({
  162. loading: false
  163. });
  164. }.bind(this));
  165. },
  166. getInitialState() {
  167. return {
  168. visible: false,
  169. data: [],
  170. loading: false,
  171. showAdd: false,
  172. showDesc: false,
  173. searchMore: true,
  174. selectedRowKeys: [],
  175. selectedRows: [],
  176. pagination: {
  177. defaultCurrent: 1,
  178. defaultPageSize: 10,
  179. showQuickJumper: true,
  180. pageSize: 10,
  181. onChange: function (page) {
  182. this.loadData(page);
  183. }.bind(this),
  184. showTotal: function (total) {
  185. return '共' + total + '条数据';
  186. }
  187. },
  188. columns: [
  189. {
  190. title: '编号',
  191. dataIndex: 'serialNumber',
  192. key: 'serialNumber',
  193. }, {
  194. title: '省份',
  195. dataIndex: 'province',
  196. key: 'province',
  197. render: text => { return getProvince(text); }
  198. }, {
  199. title: '公司名称',
  200. dataIndex: 'unitName',
  201. key: 'unitName',
  202. }, {
  203. title: '签订时间',
  204. dataIndex: 'signDateFormattedDate',
  205. key: 'signDateFormattedDate',
  206. }, {
  207. title: '合同状态',
  208. dataIndex: 'status',
  209. key: 'status',
  210. render: (text) => { return getContractState(text) }
  211. }, {
  212. title: '合同类型',
  213. dataIndex: 'type',
  214. key: 'type',
  215. render: (text) => { return getContractType(text) }
  216. }, {
  217. title: '创建人',
  218. dataIndex: 'founder',
  219. key: 'founder'
  220. }, {
  221. title: '技术员',
  222. dataIndex: 'techPrincipal',
  223. key: 'techPrincipal',
  224. }, {
  225. title: '描述',
  226. dataIndex: 'describe',
  227. key: 'describe',
  228. }
  229. ],
  230. dataSource: []
  231. };
  232. },
  233. getContractList() {
  234. this.setState({
  235. loading: true
  236. });
  237. $.ajax({
  238. method: "get",
  239. dataType: "json",
  240. crossDomain: false,
  241. url: globalConfig.context + "/api/admin/contract/serialNumber",
  242. success: function (data) {
  243. if (!data.data) {
  244. if (data.error && data.error.length) {
  245. message.warning(data.error[0].message);
  246. };
  247. return;
  248. };
  249. let theArr = [];
  250. for (let i = 0; i < data.data.length; i++) {
  251. let item = data.data[i];
  252. theArr.push(
  253. <Select.Option value={item.contractId} key={item.contractId}>{item.serialNumber}</Select.Option>
  254. );
  255. };
  256. this.setState({
  257. contractListOption: theArr
  258. });
  259. }.bind(this),
  260. }).always(function () {
  261. this.setState({
  262. loading: false
  263. });
  264. }.bind(this));
  265. },
  266. componentWillMount() {
  267. let _me = this, tArr = [], sArr = [];
  268. contractTypeList.map(function (item) {
  269. tArr.push(
  270. <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  271. )
  272. });
  273. contractStateList.map(function (item) {
  274. sArr.push(
  275. <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  276. )
  277. });
  278. this.setState({
  279. typeOption: tArr,
  280. stateOption: sArr
  281. });
  282. this.getAuthorList();
  283. this.getCompanyList();
  284. this.getStateList();
  285. this.getContractList();
  286. if (window.location.search) {
  287. let theObj = getSearchUrl(window.location.search);
  288. if (theObj.rid) {
  289. theObj.id = theObj.rid;
  290. if (theObj.rid != 'null' && theObj.uid != 'null') {
  291. this.tableRowClick(theObj);
  292. };
  293. };
  294. };
  295. this.loadData();
  296. },
  297. tableRowClick(record, index) {
  298. this.state.RowData = record;
  299. if (record.status === '0') {
  300. this.setState({
  301. showAdd: true
  302. });
  303. } else {
  304. if(index!=undefined){
  305. this.setState({
  306. showDesc: true
  307. });
  308. }
  309. };
  310. },
  311. delectRow() {
  312. let deletedIds = [];
  313. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  314. let rowItem = this.state.selectedRows[idx];
  315. if (rowItem.id) {
  316. deletedIds.push(rowItem.id)
  317. };
  318. };
  319. this.setState({
  320. selectedRowKeys: [],
  321. loading: deletedIds.length > 0
  322. });
  323. $.ajax({
  324. method: "POST",
  325. dataType: "json",
  326. crossDomain: false,
  327. url: globalConfig.context + "/api/admin/contract/delete",
  328. data: {
  329. ids: deletedIds
  330. }
  331. }).done(function (data) {
  332. if (!data.error.length) {
  333. message.success('删除成功!');
  334. this.setState({
  335. loading: false,
  336. });
  337. } else {
  338. message.warning(data.error[0].message);
  339. };
  340. this.loadData();
  341. }.bind(this));
  342. },
  343. closeDesc(e, s) {
  344. this.state.showDesc = e;
  345. if (s) {
  346. this.loadData();
  347. };
  348. },
  349. addClick() {
  350. this.setState({
  351. showAdd: true
  352. });
  353. },
  354. closeAdd(e, s) {
  355. this.setState({
  356. showAdd: e
  357. });
  358. if (s) {
  359. this.loadData();
  360. };
  361. },
  362. searchSwitch() {
  363. this.setState({
  364. searchMore: !this.state.searchMore
  365. });
  366. },
  367. search() {
  368. this.loadData();
  369. },
  370. reset() {
  371. this.state.names='';
  372. this.state.province = undefined;
  373. this.state.unitId = undefined;
  374. this.state.contractState = undefined;
  375. this.state.contractType = undefined;
  376. this.state.contractId = undefined;
  377. this.state.startDateFormattedDate = undefined;
  378. this.state.endDateFormattedDate = undefined;
  379. this.loadData();
  380. },
  381. //客户名称初始加载
  382. customerList(e){
  383. $.ajax({
  384. method: "get",
  385. dataType: "json",
  386. crossDomain: false,
  387. url: globalConfig.context + "/api/admin/customer/findCustomerByName",
  388. data:{
  389. name:e
  390. },
  391. success: function (data) {
  392. let thedata=data.data;
  393. if (!thedata) {
  394. if (data.error && data.error.length) {
  395. message.warning(data.error[0].message);
  396. };
  397. thedata = {};
  398. };
  399. this.setState({
  400. customerArr:thedata,
  401. });
  402. }.bind(this),
  403. }).always(function () {
  404. this.setState({
  405. loading: false
  406. });
  407. }.bind(this));
  408. },
  409. //值改变时请求客户名称
  410. httpChange(e){
  411. this.setState({
  412. names:e
  413. })
  414. if(e.length>=2){
  415. this.customerList(e);
  416. return false;
  417. }
  418. },
  419. //客户输入框失去焦点是判断客户是否存在
  420. blurChange(e){
  421. let theType='';
  422. let contactLists=this.state.customerArr||[];
  423. if (e) {
  424. contactLists.map(function (item) {
  425. if (item.name == e.toString()) {
  426. theType = item.id;
  427. }
  428. });
  429. }
  430. if(!theType){
  431. theType='';
  432. return message.warning('当前客户名不存在')
  433. };
  434. this.setState({
  435. khId:theType
  436. })
  437. },
  438. //获取联系人下拉框
  439. getNewWoman(ids) {
  440. $.ajax({
  441. method: "get",
  442. dataType: "json",
  443. crossDomain: false,
  444. url: globalConfig.context + "/api/admin/customer/findCustomerContacts",
  445. data:{
  446. uid:ids,
  447. },
  448. success: function (data) {
  449. let theArr = [];
  450. let thedata=data.data;
  451. if (!thedata) {
  452. if (data.error && data.error.length) {
  453. message.warning(data.error[0].message);
  454. };
  455. thedata = {};
  456. };
  457. thedata.map(function (item,index) {
  458. theArr.push(<Select.Option value={index}>{item.name}</Select.Option>)
  459. });
  460. let telNum=thedata.telNum;
  461. this.setState({
  462. telNumArr:thedata,
  463. nub:thedata.telNum?thedata[0].telNum:'',
  464. orderStatusOption: theArr,
  465. });
  466. }.bind(this),
  467. }).always(function () {
  468. this.setState({
  469. loading: false
  470. });
  471. }.bind(this));
  472. },
  473. render() {
  474. const rowSelection = {
  475. selectedRowKeys: this.state.selectedRowKeys,
  476. onChange: (selectedRowKeys, selectedRows) => {
  477. this.setState({
  478. selectedRows: selectedRows,
  479. selectedRowKeys: selectedRowKeys
  480. });
  481. }
  482. };
  483. const dataSources=this.state.customerArr || [];
  484. const options = dataSources.map((group) =>
  485. <Option key={group.id} value={group.name}>{group.name}</Option>
  486. );
  487. const hasSelected = this.state.selectedRowKeys.length > 0;
  488. return (
  489. <div className="foster-box">
  490. <div className="foster-content">
  491. <div className="content-title">
  492. <span>合同申请管理</span>
  493. <ContractAdd
  494. companyOption={this.state.companyOption}
  495. authorOption={this.state.authorOption}
  496. typeOption={this.state.typeOption}
  497. data={this.state.RowData}
  498. onClick={this.addClick}
  499. showAdd={this.state.showAdd}
  500. closeAdd={this.closeAdd} />
  501. </div>
  502. <div className="foster-query">
  503. <Cascader placeholder="选择省份"
  504. style={{ width: 100, marginTop: "-4px" }}
  505. value={this.state.province}
  506. options={provinceSelect()}
  507. showSearch
  508. filterOption={companySearch}
  509. onChange={(e) => { this.setState({ province: e }) }} />
  510. <AutoComplete
  511. className="certain-category-search"
  512. dropdownClassName="certain-category-search-dropdown"
  513. dropdownMatchSelectWidth={false}
  514. dropdownStyle={{ width: '150px' }}
  515. size="large"
  516. style={{ width: '150px' }}
  517. dataSource={options}
  518. placeholder="输入名称"
  519. optionLabelProp="value"
  520. onChange={this.httpChange}
  521. onSelect={this.autoChange}
  522. filterOption={true}
  523. onBlur={this.blurChange}
  524. value={this.state.names}
  525. >
  526. <Input />
  527. </AutoComplete>
  528. <Select placeholder="选择合同编号"
  529. style={{ width: 120 }}
  530. value={this.state.contractId}
  531. showSearch
  532. filterOption={companySearch}
  533. onChange={(e) => { this.setState({ contractId: e }) }}>
  534. {this.state.contractListOption}
  535. </Select>
  536. <Select placeholder="选择一个合同类型"
  537. style={{ width: 200 }}
  538. value={this.state.contractType}
  539. showSearch
  540. filterOption={companySearch}
  541. onChange={(e) => { this.setState({ contractType: e }) }}>
  542. {this.state.typeOption}
  543. </Select>
  544. <Select style={{ width: 120 }}
  545. value={this.state.contractState}
  546. onChange={(e) => { this.setState({ contractState: e }) }}
  547. placeholder="选择一个状态">
  548. {this.state.stateOption}
  549. </Select>
  550. <span>更多搜索 <Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  551. <Button type="primary" onClick={this.search}>搜索</Button>
  552. <Button onClick={this.reset}>重置</Button>
  553. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  554. disabled={!hasSelected}
  555. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  556. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  557. <span>签订时间:</span>
  558. <DatePicker style={{ width: '140px' }}
  559. allowClear={false}
  560. value={this.state.startDateFormattedDate ? moment(this.state.startDateFormattedDate) : null}
  561. onChange={(date, dateString) => { this.setState({ startDateFormattedDate: dateString }) }} />
  562. <span>到</span>
  563. <DatePicker style={{ width: '140px' }}
  564. allowClear={false}
  565. value={this.state.endDateFormattedDate ? moment(this.state.endDateFormattedDate) : null}
  566. onChange={(date, dateString) => { this.setState({ endDateFormattedDate: dateString }) }} />
  567. </div>
  568. </div>
  569. <div className="foster-table">
  570. <Spin spinning={this.state.loading}>
  571. <Table size="middle" columns={this.state.columns}
  572. dataSource={this.state.dataSource}
  573. rowSelection={rowSelection}
  574. style={{
  575. cursor: 'pointer',
  576. }}
  577. pagination={this.state.pagination}
  578. onRowClick={this.tableRowClick} />
  579. </Spin>
  580. </div>
  581. <ContractDetail
  582. data={this.state.RowData}
  583. authorOption={this.state.authorOption}
  584. statusOption={this.state.statusOption}
  585. showDesc={this.state.showDesc}
  586. closeDesc={this.closeDesc} />
  587. </div >
  588. </div>
  589. );
  590. }
  591. });
  592. export default Contract;