contract.jsx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. import React from 'react';
  2. import { Icon, Button, Input, Select, Spin, Table, DatePicker, message, Cascader, Switch, Modal } from 'antd';
  3. import { provinceArr, contractStateList, contractTypeList } from '../../../dataDic.js';
  4. import { getTime, companySearch, getContractState, getContractType, getInUrgentTime, getSearchUrl } from '../../../tools.js';
  5. import ajax from 'jquery/src/ajax/xhr.js';
  6. import $ from 'jquery/src/ajax';
  7. import ContractAdd from './contractAdd.jsx';
  8. import ContractDetail from './contractDetail.jsx';
  9. import moment from 'moment';
  10. import './contract.less';
  11. const Contract = React.createClass({
  12. loadData(pageNo) {
  13. this.state.data = [];
  14. this.setState({
  15. loading: true
  16. });
  17. $.ajax({
  18. method: "get",
  19. dataType: "json",
  20. crossDomain: false,
  21. url: globalConfig.context + "/api/admin/contract/list",
  22. data: {
  23. pageNo: pageNo || 1,
  24. pageSize: this.state.pagination.pageSize,
  25. province: this.state.province,
  26. uid: this.state.unitId,
  27. type: this.state.contractType,
  28. status: this.state.contractState,
  29. contractId: this.state.contractId,
  30. startDateFormattedDate: this.state.startDateFormattedDate,
  31. endDateFormattedDate: this.state.endDateFormattedDate,
  32. },
  33. success: function (data) {
  34. if (data.error.length || !data.data || !data.data.list) {
  35. message.warning(data.error[0].message);
  36. return;
  37. };
  38. for (let i = 0; i < data.data.list.length; i++) {
  39. let thisdata = data.data.list[i];
  40. this.state.data.push({
  41. key: i,
  42. completeDate: thisdata.completeDate,
  43. completeDateFormattedDate: thisdata.completeDateFormattedDate,
  44. contacts: thisdata.contacts,
  45. depict: thisdata.depict,
  46. founder: thisdata.founder,
  47. id: thisdata.id,
  48. province: thisdata.province,
  49. serialNumber: thisdata.serialNumber,
  50. signDate: thisdata.signDate,
  51. signDateFormattedDate: thisdata.signDateFormattedDate,
  52. status: thisdata.status,
  53. type: thisdata.type,
  54. uid: thisdata.uid,
  55. unitName: thisdata.unitName,
  56. });
  57. };
  58. this.state.pagination.defaultCurrent = data.data.pageNo;
  59. this.state.pagination.total = data.data.totalCount;
  60. this.setState({
  61. dataSource: this.state.data,
  62. pagination: this.state.pagination
  63. });
  64. }.bind(this),
  65. }).always(function () {
  66. this.setState({
  67. loading: false
  68. });
  69. }.bind(this));
  70. },
  71. getAuthorList() {
  72. this.setState({
  73. loading: true
  74. });
  75. $.ajax({
  76. method: "get",
  77. dataType: "json",
  78. crossDomain: false,
  79. url: globalConfig.context + "/api/admin/contract/principal",
  80. success: function (data) {
  81. if (!data.data) {
  82. if (data.error && data.error.length) {
  83. message.warning(data.error[0].message);
  84. };
  85. return;
  86. };
  87. let _me = this, theArr = [];
  88. for (var item in data.data) {
  89. theArr.push(
  90. <Select.Option value={item} key={item}>{data.data[item]}</Select.Option>
  91. )
  92. };
  93. this.setState({
  94. authorOption: theArr
  95. });
  96. }.bind(this),
  97. }).always(function () {
  98. this.setState({
  99. loading: false
  100. });
  101. }.bind(this));
  102. },
  103. getCompanyList() {
  104. this.setState({
  105. loading: true
  106. });
  107. $.ajax({
  108. method: "get",
  109. dataType: "json",
  110. crossDomain: false,
  111. url: globalConfig.context + "/api/admin/getUnitNames",
  112. success: function (data) {
  113. if (data.error.length || !data.data) {
  114. return;
  115. };
  116. let _me = this, theArr = [];
  117. for (var item in data.data) {
  118. theArr.push(
  119. <Select.Option value={item} key={item}>{data.data[item]}</Select.Option>
  120. )
  121. };
  122. this.setState({
  123. companyOption: theArr
  124. });
  125. }.bind(this),
  126. }).always(function () {
  127. this.setState({
  128. loading: false
  129. });
  130. }.bind(this));
  131. },
  132. getStateList() {
  133. this.setState({
  134. loading: true
  135. });
  136. $.ajax({
  137. method: "get",
  138. dataType: "json",
  139. crossDomain: false,
  140. url: globalConfig.context + "/api/admin/contract/status",
  141. success: function (data) {
  142. if (!data.data) {
  143. if (data.error && data.error.length) {
  144. message.warning(data.error[0].message);
  145. return;
  146. };
  147. };
  148. let _me = this, theArr = [];
  149. for (var item in data.data) {
  150. theArr.push(
  151. <Select.Option value={item} key={item}>{data.data[item]}</Select.Option>
  152. )
  153. };
  154. this.setState({
  155. statusOption: theArr
  156. });
  157. }.bind(this),
  158. }).always(function () {
  159. this.setState({
  160. loading: false
  161. });
  162. }.bind(this));
  163. },
  164. getInitialState() {
  165. return {
  166. visible: false,
  167. data: [],
  168. loading: false,
  169. showAdd: false,
  170. showDesc: false,
  171. searchMore: true,
  172. startDateFormattedDate: [],
  173. endDateFormattedDate: [],
  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. }, {
  198. title: '公司名称',
  199. dataIndex: 'unitName',
  200. key: 'unitName',
  201. }, {
  202. title: '签订时间',
  203. dataIndex: 'signDateFormattedDate',
  204. key: 'signDateFormattedDate',
  205. }, {
  206. title: '合同状态',
  207. dataIndex: 'status',
  208. key: 'status',
  209. render: (text) => { return getContractState(text) }
  210. }, {
  211. title: '合同类型',
  212. dataIndex: 'type',
  213. key: 'type',
  214. render: (text) => { return getContractType(text) }
  215. }, {
  216. title: '创建人',
  217. dataIndex: 'founder',
  218. key: 'founder'
  219. }, {
  220. title: '技术员',
  221. dataIndex: 'techPrincipal',
  222. key: 'techPrincipal',
  223. }, {
  224. title: '描述',
  225. dataIndex: 'describe',
  226. key: 'describe',
  227. }
  228. ],
  229. dataSource: []
  230. };
  231. },
  232. getContractList() {
  233. this.setState({
  234. loading: true
  235. });
  236. $.ajax({
  237. method: "get",
  238. dataType: "json",
  239. crossDomain: false,
  240. url: globalConfig.context + "/api/admin/contract/serialNumber",
  241. success: function (data) {
  242. if (!data.data) {
  243. if (data.error && data.error.length) {
  244. message.warning(data.error[0].message);
  245. };
  246. return;
  247. };
  248. let theArr = [];
  249. for (let i = 0; i < data.data.length; i++) {
  250. let item = data.data[i];
  251. theArr.push(
  252. <Select.Option value={item.contractId} key={item.contractId}>{item.serialNumber}</Select.Option>
  253. );
  254. };
  255. this.setState({
  256. contractListOption: theArr
  257. });
  258. }.bind(this),
  259. }).always(function () {
  260. this.setState({
  261. loading: false
  262. });
  263. }.bind(this));
  264. },
  265. componentWillMount() {
  266. let _me = this, pArr = [], tArr = [], sArr = [];
  267. provinceArr.map(function (item) {
  268. pArr.push(
  269. <Select.Option value={item} key={item}>{item}</Select.Option>
  270. )
  271. });
  272. contractTypeList.map(function (item) {
  273. tArr.push(
  274. <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  275. )
  276. });
  277. contractStateList.map(function (item) {
  278. sArr.push(
  279. <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  280. )
  281. });
  282. this.setState({
  283. provinceOption: pArr,
  284. typeOption: tArr,
  285. stateOption: sArr
  286. });
  287. this.getAuthorList();
  288. this.getCompanyList();
  289. this.getStateList();
  290. this.getContractList();
  291. if (window.location.search) {
  292. let theObj = getSearchUrl(window.location.search);
  293. if (theObj.rid) {
  294. theObj.id = theObj.rid;
  295. if (theObj.rid != 'null' && theObj.uid != 'null') {
  296. this.tableRowClick(theObj);
  297. };
  298. };
  299. };
  300. this.loadData();
  301. },
  302. tableRowClick(record, index) {
  303. this.state.RowData = record;
  304. if (record.status === '0') {
  305. this.setState({
  306. showAdd: true
  307. });
  308. } else {
  309. this.setState({
  310. showDesc: true
  311. });
  312. };
  313. },
  314. delectRow() {
  315. let deletedIds = [];
  316. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  317. let rowItem = this.state.selectedRows[idx];
  318. if (rowItem.id) {
  319. deletedIds.push(rowItem.id)
  320. };
  321. };
  322. this.setState({
  323. selectedRowKeys: [],
  324. loading: deletedIds.length > 0
  325. });
  326. $.ajax({
  327. method: "POST",
  328. dataType: "json",
  329. crossDomain: false,
  330. url: globalConfig.context + "/api/admin/contract/delete",
  331. data: {
  332. ids: deletedIds
  333. }
  334. }).done(function (data) {
  335. if (!data.error.length) {
  336. message.success('删除成功!');
  337. this.setState({
  338. loading: false,
  339. });
  340. } else {
  341. message.warning(data.error[0].message);
  342. };
  343. this.loadData();
  344. }.bind(this));
  345. },
  346. closeDesc(e, s) {
  347. this.state.showDesc = e;
  348. if (s) {
  349. this.loadData();
  350. };
  351. },
  352. addClick() {
  353. this.setState({
  354. showAdd: true
  355. });
  356. },
  357. closeAdd(e, s) {
  358. this.setState({
  359. showAdd: e
  360. });
  361. if (s) {
  362. this.loadData();
  363. };
  364. },
  365. searchSwitch() {
  366. this.setState({
  367. searchMore: !this.state.searchMore
  368. });
  369. },
  370. search() {
  371. this.loadData();
  372. },
  373. reset() {
  374. this.state.province = undefined;
  375. this.state.unitId = undefined;
  376. this.state.contractState = undefined;
  377. this.state.contractType = undefined;
  378. this.state.contractId = undefined;
  379. this.state.startDateFormattedDate = [];
  380. this.state.endDateFormattedDate = [];
  381. this.loadData();
  382. },
  383. render() {
  384. const rowSelection = {
  385. selectedRowKeys: this.state.selectedRowKeys,
  386. onChange: (selectedRowKeys, selectedRows) => {
  387. this.setState({
  388. selectedRows: selectedRows,
  389. selectedRowKeys: selectedRowKeys
  390. });
  391. }
  392. };
  393. const hasSelected = this.state.selectedRowKeys.length > 0;
  394. const { MonthPicker, RangePicker } = DatePicker;
  395. return (
  396. <div className="foster-box">
  397. <div className="foster-content">
  398. <div className="content-title">
  399. <span>合同申请管理</span>
  400. <ContractAdd
  401. companyOption={this.state.companyOption}
  402. authorOption={this.state.authorOption}
  403. typeOption={this.state.typeOption}
  404. data={this.state.RowData}
  405. onClick={this.addClick}
  406. showAdd={this.state.showAdd}
  407. closeAdd={this.closeAdd} />
  408. </div>
  409. <div className="foster-query">
  410. <Select placeholder="选择省份"
  411. style={{ width: 100 }}
  412. value={this.state.province}
  413. showSearch
  414. filterOption={companySearch}
  415. onChange={(e) => { this.setState({ province: e }) }}>
  416. {this.state.provinceOption}
  417. </Select>
  418. <Select placeholder="选择公司"
  419. style={{ width: 200 }}
  420. value={this.state.unitId}
  421. showSearch
  422. filterOption={companySearch}
  423. onChange={(e) => { this.setState({ unitId: e }) }}>
  424. {this.state.companyOption}
  425. </Select>
  426. <Select placeholder="选择合同编号"
  427. style={{ width: 120 }}
  428. value={this.state.contractId}
  429. showSearch
  430. filterOption={companySearch}
  431. onChange={(e) => { this.setState({ contractId: e }) }}>
  432. {this.state.contractListOption}
  433. </Select>
  434. <Select placeholder="选择一个合同类型"
  435. style={{ width: 200 }}
  436. value={this.state.contractType}
  437. showSearch
  438. filterOption={companySearch}
  439. onChange={(e) => { this.setState({ contractType: e }) }}>
  440. {this.state.typeOption}
  441. </Select>
  442. <Select style={{ width: 120 }}
  443. value={this.state.contractState}
  444. onChange={(e) => { this.setState({ contractState: e }) }}
  445. placeholder="选择一个状态">
  446. {this.state.stateOption}
  447. </Select>
  448. <span>更多搜索 <Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  449. <Button type="primary" onClick={this.search}>搜索</Button>
  450. <Button onClick={this.reset}>重置</Button>
  451. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  452. disabled={!hasSelected}
  453. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  454. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  455. <span>创建时间:</span>
  456. <RangePicker style={{ width: '240px' }}
  457. allowClear={false}
  458. value={[this.state.startDateFormattedDate[0] ? moment(this.state.startDateFormattedDate[0]) : null,
  459. this.state.startDateFormattedDate[1] ? moment(this.state.startDateFormattedDate[1]) : null]}
  460. onChange={(date, dateString) => { this.setState({ startDateFormattedDate: dateString }) }} />
  461. <span>结束时间:</span>
  462. <RangePicker style={{ width: '240px' }}
  463. allowClear={false}
  464. value={[this.state.endDateFormattedDate[0] ? moment(this.state.endDateFormattedDate[0]) : null,
  465. this.state.endDateFormattedDate[1] ? moment(this.state.endDateFormattedDate[1]) : null]}
  466. onChange={(date, dateString) => { this.setState({ endDateFormattedDate: dateString }) }} />
  467. </div>
  468. </div>
  469. <div className="foster-table">
  470. <Spin spinning={this.state.loading}>
  471. <Table columns={this.state.columns}
  472. dataSource={this.state.dataSource}
  473. rowSelection={rowSelection}
  474. pagination={this.state.pagination}
  475. onRowClick={this.tableRowClick} />
  476. </Spin>
  477. </div>
  478. <ContractDetail
  479. data={this.state.RowData}
  480. authorOption={this.state.authorOption}
  481. statusOption={this.state.statusOption}
  482. showDesc={this.state.showDesc}
  483. closeDesc={this.closeDesc} />
  484. </div >
  485. </div>
  486. );
  487. }
  488. });
  489. export default Contract;