contract.jsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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. id: thisdata.id,
  42. uid: thisdata.uid,
  43. province: thisdata.province,
  44. unitName: thisdata.unitName,
  45. serialNumber: thisdata.serialNumber,
  46. type: thisdata.type,
  47. signDate: thisdata.signDate,
  48. founder: thisdata.founder,
  49. describe: thisdata.describe,
  50. status: thisdata.status,
  51. signDateFormattedDate: thisdata.signDateFormattedDate
  52. });
  53. };
  54. this.state.pagination.defaultCurrent = data.data.pageNo;
  55. this.state.pagination.total = data.data.totalCount;
  56. this.setState({
  57. dataSource: this.state.data,
  58. pagination: this.state.pagination
  59. });
  60. }.bind(this),
  61. }).always(function () {
  62. this.setState({
  63. loading: false
  64. });
  65. }.bind(this));
  66. },
  67. getAuthorList() {
  68. this.setState({
  69. loading: true
  70. });
  71. $.ajax({
  72. method: "get",
  73. dataType: "json",
  74. crossDomain: false,
  75. url: globalConfig.context + "/api/admin/contract/principal",
  76. success: function (data) {
  77. if (!data.data) {
  78. if (data.error && data.error.length) {
  79. message.warning(data.error[0].message);
  80. };
  81. return;
  82. };
  83. let _me = this, theArr = [];
  84. for (var item in data.data) {
  85. theArr.push(
  86. <Select.Option value={item} key={item}>{data.data[item]}</Select.Option>
  87. )
  88. };
  89. this.setState({
  90. authorOption: theArr
  91. });
  92. }.bind(this),
  93. }).always(function () {
  94. this.setState({
  95. loading: false
  96. });
  97. }.bind(this));
  98. },
  99. getCompanyList() {
  100. this.setState({
  101. loading: true
  102. });
  103. $.ajax({
  104. method: "get",
  105. dataType: "json",
  106. crossDomain: false,
  107. url: globalConfig.context + "/api/admin/getUnitNames",
  108. success: function (data) {
  109. if (data.error.length || !data.data) {
  110. return;
  111. };
  112. let _me = this, theArr = [];
  113. for (var item in data.data) {
  114. theArr.push(
  115. <Select.Option value={item} key={item}>{data.data[item]}</Select.Option>
  116. )
  117. };
  118. this.setState({
  119. companyOption: theArr
  120. });
  121. }.bind(this),
  122. }).always(function () {
  123. this.setState({
  124. loading: false
  125. });
  126. }.bind(this));
  127. },
  128. getStateList() {
  129. this.setState({
  130. loading: true
  131. });
  132. $.ajax({
  133. method: "get",
  134. dataType: "json",
  135. crossDomain: false,
  136. url: globalConfig.context + "/api/admin/contract/status",
  137. success: function (data) {
  138. if (!data.data) {
  139. if (data.error && data.error.length) {
  140. message.warning(data.error[0].message);
  141. return;
  142. };
  143. };
  144. let _me = this, theArr = [];
  145. for (var item in data.data) {
  146. theArr.push(
  147. <Select.Option value={item} key={item}>{data.data[item]}</Select.Option>
  148. )
  149. };
  150. this.setState({
  151. statusOption: theArr
  152. });
  153. }.bind(this),
  154. }).always(function () {
  155. this.setState({
  156. loading: false
  157. });
  158. }.bind(this));
  159. },
  160. getInitialState() {
  161. return {
  162. visible: false,
  163. data: [],
  164. loading: false,
  165. showAdd: false,
  166. showDesc: false,
  167. searchMore: true,
  168. startDateFormattedDate: [],
  169. endDateFormattedDate: [],
  170. pagination: {
  171. defaultCurrent: 1,
  172. defaultPageSize: 10,
  173. showQuickJumper: true,
  174. pageSize: 10,
  175. onChange: function (page) {
  176. this.loadData(page);
  177. }.bind(this),
  178. showTotal: function (total) {
  179. return '共' + total + '条数据';
  180. }
  181. },
  182. columns: [
  183. {
  184. title: '编号',
  185. dataIndex: 'serialNumber',
  186. key: 'serialNumber',
  187. }, {
  188. title: '省份',
  189. dataIndex: 'province',
  190. key: 'province',
  191. }, {
  192. title: '公司名称',
  193. dataIndex: 'unitName',
  194. key: 'unitName',
  195. }, {
  196. title: '创建时间',
  197. dataIndex: 'signDateFormattedDate',
  198. key: 'signDateFormattedDate',
  199. }, {
  200. title: '合同状态',
  201. dataIndex: 'status',
  202. key: 'status',
  203. render: (text) => { return getContractState(text) }
  204. }, {
  205. title: '合同类型',
  206. dataIndex: 'type',
  207. key: 'type',
  208. render: (text) => { return getContractType(text) }
  209. }, {
  210. title: '创建人',
  211. dataIndex: 'founder',
  212. key: 'founder'
  213. }, {
  214. title: '技术员',
  215. dataIndex: 'techPrincipal',
  216. key: 'techPrincipal',
  217. }, {
  218. title: '描述',
  219. dataIndex: 'describe',
  220. key: 'describe',
  221. }
  222. ],
  223. dataSource: []
  224. };
  225. },
  226. componentWillMount() {
  227. let _me = this, pArr = [], tArr = [], sArr = [];
  228. provinceArr.map(function (item) {
  229. pArr.push(
  230. <Select.Option value={item} key={item}>{item}</Select.Option>
  231. )
  232. });
  233. contractTypeList.map(function (item) {
  234. tArr.push(
  235. <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  236. )
  237. });
  238. contractStateList.map(function (item) {
  239. sArr.push(
  240. <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  241. )
  242. });
  243. this.setState({
  244. provinceOption: pArr,
  245. typeOption: tArr,
  246. stateOption: sArr
  247. });
  248. this.loadData();
  249. this.getAuthorList();
  250. this.getCompanyList();
  251. this.getStateList();
  252. // if (window.location.search) {
  253. // let theArr = getSearchUrl(window.location.search);
  254. // if (theArr.length > 1) {
  255. // let theObj = {};
  256. // theObj.id = theArr[0];
  257. // theObj.uid = theArr[1];
  258. // if (theObj.id != 'null' && theObj.uid != 'null') {
  259. // this.tableRowClick(theObj);
  260. // };
  261. // } else if (theArr.length == 1) {
  262. // this.state.unitName = theArr[0];
  263. // };
  264. // };
  265. },
  266. tableRowClick(record, index) {
  267. this.state.RowData = record;
  268. this.setState({
  269. showDesc: true
  270. });
  271. },
  272. closeDesc(e, s) {
  273. this.state.showDesc = e;
  274. if (s) {
  275. this.loadData();
  276. };
  277. },
  278. addClick() {
  279. this.setState({
  280. showAdd: true
  281. });
  282. },
  283. closeAdd(e, s) {
  284. this.state.showAdd = e;
  285. if (s) {
  286. this.loadData();
  287. };
  288. },
  289. searchSwitch() {
  290. this.setState({
  291. searchMore: !this.state.searchMore
  292. });
  293. },
  294. search() {
  295. this.loadData();
  296. },
  297. reset() {
  298. this.state.province = undefined;
  299. this.state.unitId = undefined;
  300. this.state.contractState = undefined;
  301. this.state.contractType = undefined;
  302. this.state.startDateFormattedDate = [];
  303. this.state.endDateFormattedDate = [];
  304. this.loadData();
  305. },
  306. render() {
  307. const { MonthPicker, RangePicker } = DatePicker;
  308. return (
  309. <div className="foster-box">
  310. <div className="foster-content">
  311. <div className="content-title">
  312. <span>合同申请管理</span>
  313. <ContractAdd
  314. companyOption={this.state.companyOption}
  315. authorOption={this.state.authorOption}
  316. typeOption={this.state.typeOption}
  317. onClick={this.addClick}
  318. closeAdd={this.closeAdd} />
  319. </div>
  320. <div className="foster-query">
  321. <Select placeholder="选择省份"
  322. style={{ width: 100 }}
  323. value={this.state.province}
  324. showSearch
  325. filterOption={companySearch}
  326. onChange={(e) => { this.setState({ province: e }) }}>
  327. {this.state.provinceOption}
  328. </Select>
  329. <Select placeholder="选择公司"
  330. style={{ width: 200 }}
  331. value={this.state.unitId}
  332. showSearch
  333. filterOption={companySearch}
  334. onChange={(e) => { this.setState({ unitId: e }) }}>
  335. {this.state.companyOption}
  336. </Select>
  337. <Select placeholder="选择一个合同类型"
  338. style={{ width: 200 }}
  339. value={this.state.contractType}
  340. showSearch
  341. filterOption={companySearch}
  342. onChange={(e) => { this.setState({ contractType: e }) }}>
  343. {this.state.typeOption}
  344. </Select>
  345. <Select style={{ width: 120 }}
  346. value={this.state.searchStatus}
  347. onChange={(e) => { this.setState({ contractState: e }) }}
  348. placeholder="选择一个状态">
  349. {this.state.stateOption}
  350. </Select>
  351. <span>更多搜索 <Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  352. <Button type="primary" onClick={this.search}>搜索</Button>
  353. <Button onClick={this.reset}>重置</Button>
  354. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  355. <span>创建时间:</span>
  356. <RangePicker style={{ width: '240px' }}
  357. allowClear={false}
  358. value={[this.state.startDateFormattedDate[0] ? moment(this.state.startDateFormattedDate[0]) : null,
  359. this.state.startDateFormattedDate[1] ? moment(this.state.startDateFormattedDate[1]) : null]}
  360. onChange={(date, dateString) => { this.setState({ startDateFormattedDate: dateString }) }} />
  361. <span>结束时间:</span>
  362. <RangePicker style={{ width: '240px' }}
  363. allowClear={false}
  364. value={[this.state.endDateFormattedDate[0] ? moment(this.state.endDateFormattedDate[0]) : null,
  365. this.state.endDateFormattedDate[1] ? moment(this.state.endDateFormattedDate[1]) : null]}
  366. onChange={(date, dateString) => { this.setState({ endDateFormattedDate: dateString }) }} />
  367. </div>
  368. </div>
  369. <div className="foster-table">
  370. <Spin spinning={this.state.loading}>
  371. <Table columns={this.state.columns}
  372. dataSource={this.state.dataSource}
  373. pagination={this.state.pagination}
  374. onRowClick={this.tableRowClick} />
  375. </Spin>
  376. </div>
  377. <ContractDetail
  378. data={this.state.RowData}
  379. authorOption={this.state.authorOption}
  380. statusOption={this.state.statusOption}
  381. showDesc={this.state.showDesc}
  382. closeDesc={this.closeDesc} />
  383. </div >
  384. </div>
  385. );
  386. }
  387. });
  388. export default Contract;