contract.jsx 19 KB

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