contract.jsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. import React from 'react';
  2. import { Icon, Button, Input, Select, Spin, Table, DatePicker, message, Cascader, Switch, Modal } from 'antd';
  3. import { contractStateList, contractTypeList } from '../../../dataDic.js';
  4. import { getTime, companySearch, getContractState, getContractType, 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/user/contract/list",
  22. data: {
  23. pageNo: pageNo || 1,
  24. pageSize: this.state.pagination.pageSize,
  25. type: this.state.contractType,
  26. status: this.state.contractState,
  27. contractId: this.state.contractId,
  28. startDateFormattedDate: this.state.startDateFormattedDate,
  29. endDateFormattedDate: this.state.endDateFormattedDate,
  30. },
  31. success: function (data) {
  32. let theArr = [];
  33. if (!data.data && !data.data.list) {
  34. if (data.error && data.error.length) {
  35. message.warning(data.error[0].message);
  36. };
  37. return;
  38. };
  39. for (let i = 0; i < data.data.list.length; i++) {
  40. let thisdata = data.data.list[i];
  41. theArr.push({
  42. key: i,
  43. id: thisdata.id,
  44. uid: thisdata.uid,
  45. contacts: thisdata.contacts,
  46. serialNumber: thisdata.serialNumber,
  47. type: thisdata.type,
  48. signDate: thisdata.signDate,
  49. depict: thisdata.depict,
  50. status: thisdata.status,
  51. completeDate: thisdata.completeDate,
  52. signDateFormattedDate: thisdata.signDateFormattedDate,
  53. completeDateFormattedDate: thisdata.completeDateFormattedDate,
  54. });
  55. };
  56. this.state.pagination.defaultCurrent = data.data.pageNo;
  57. this.state.pagination.total = data.data.totalCount;
  58. this.setState({
  59. dataSource: theArr,
  60. pagination: this.state.pagination
  61. });
  62. }.bind(this),
  63. }).always(function () {
  64. this.setState({
  65. loading: false
  66. });
  67. }.bind(this));
  68. },
  69. getStateList() {
  70. this.setState({
  71. loading: true
  72. });
  73. $.ajax({
  74. method: "get",
  75. dataType: "json",
  76. crossDomain: false,
  77. url: globalConfig.context + "/api/admin/contract/status",
  78. success: function (data) {
  79. if (!data.data) {
  80. if (data.error && data.error.length) {
  81. message.warning(data.error[0].message);
  82. return;
  83. };
  84. };
  85. let _me = this, theArr = [];
  86. for (var item in data.data) {
  87. theArr.push(
  88. <Select.Option value={item} key={item}>{data.data[item]}</Select.Option>
  89. )
  90. };
  91. this.setState({
  92. statusOption: theArr
  93. });
  94. }.bind(this),
  95. }).always(function () {
  96. this.setState({
  97. loading: false
  98. });
  99. }.bind(this));
  100. },
  101. getInitialState() {
  102. return {
  103. visible: false,
  104. data: [],
  105. loading: false,
  106. showAdd: false,
  107. showDesc: false,
  108. searchMore: true,
  109. startDateFormattedDate: [],
  110. endDateFormattedDate: [],
  111. pagination: {
  112. defaultCurrent: 1,
  113. defaultPageSize: 10,
  114. showQuickJumper: true,
  115. pageSize: 10,
  116. onChange: function (page) {
  117. this.loadData(page);
  118. }.bind(this),
  119. showTotal: function (total) {
  120. return '共' + total + '条数据';
  121. }
  122. },
  123. columns: [
  124. {
  125. title: '编号',
  126. dataIndex: 'serialNumber',
  127. key: 'serialNumber',
  128. }, {
  129. title: '省份',
  130. dataIndex: 'province',
  131. key: 'province',
  132. }, {
  133. title: '公司名称',
  134. dataIndex: 'unitName',
  135. key: 'unitName',
  136. }, {
  137. title: '签订时间',
  138. dataIndex: 'signDateFormattedDate',
  139. key: 'signDateFormattedDate',
  140. }, {
  141. title: '合同状态',
  142. dataIndex: 'status',
  143. key: 'status',
  144. render: (text) => { return getContractState(text) }
  145. }, {
  146. title: '合同类型',
  147. dataIndex: 'type',
  148. key: 'type',
  149. render: (text) => { return getContractType(text) }
  150. }, {
  151. title: '创建人',
  152. dataIndex: 'founder',
  153. key: 'founder'
  154. }, {
  155. title: '技术员',
  156. dataIndex: 'techPrincipal',
  157. key: 'techPrincipal',
  158. }, {
  159. title: '描述',
  160. dataIndex: 'describe',
  161. key: 'describe',
  162. }
  163. ],
  164. dataSource: []
  165. };
  166. },
  167. componentWillMount() {
  168. let _me = this, tArr = [], sArr = [];
  169. contractTypeList.map(function (item) {
  170. tArr.push(
  171. <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  172. )
  173. });
  174. contractStateList.map(function (item) {
  175. sArr.push(
  176. <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  177. )
  178. });
  179. this.setState({
  180. typeOption: tArr,
  181. stateOption: sArr
  182. });
  183. this.loadData();
  184. this.getStateList();
  185. // if (window.location.search) {
  186. // let theArr = getSearchUrl(window.location.search);
  187. // if (theArr.length > 1) {
  188. // let theObj = {};
  189. // theObj.id = theArr[0];
  190. // theObj.uid = theArr[1];
  191. // if (theObj.id != 'null' && theObj.uid != 'null') {
  192. // this.tableRowClick(theObj);
  193. // };
  194. // } else if (theArr.length == 1) {
  195. // this.state.unitName = theArr[0];
  196. // };
  197. // };
  198. },
  199. tableRowClick(record, index) {
  200. this.state.RowData = record;
  201. if (record.status === '0') {
  202. this.setState({
  203. showAdd: true
  204. });
  205. } else {
  206. this.setState({
  207. showDesc: true
  208. });
  209. };
  210. },
  211. closeDesc(e, s) {
  212. this.state.showDesc = e;
  213. if (s) {
  214. this.loadData();
  215. };
  216. },
  217. addClick() {
  218. this.setState({
  219. showAdd: true
  220. });
  221. },
  222. closeAdd(e, s) {
  223. this.setState({
  224. showAdd: e
  225. });
  226. if (s) {
  227. this.loadData();
  228. };
  229. },
  230. searchSwitch() {
  231. this.setState({
  232. searchMore: !this.state.searchMore
  233. });
  234. },
  235. search() {
  236. this.loadData();
  237. },
  238. reset() {
  239. this.state.contractState = undefined;
  240. this.state.contractType = undefined;
  241. this.state.contractId = undefined;
  242. this.state.startDateFormattedDate = [];
  243. this.state.endDateFormattedDate = [];
  244. this.loadData();
  245. },
  246. render() {
  247. const { MonthPicker, RangePicker } = DatePicker;
  248. return (
  249. <div className="foster-box">
  250. <div className="foster-content">
  251. <div className="content-title">
  252. <span>合同申请管理</span>
  253. <ContractAdd
  254. contactsOption={this.state.contactsOption}
  255. typeOption={this.state.typeOption}
  256. data={this.state.RowData}
  257. onClick={this.addClick}
  258. showAdd={this.state.showAdd}
  259. closeAdd={this.closeAdd} />
  260. </div>
  261. <div className="foster-query">
  262. <Select placeholder="选择一个合同类型"
  263. style={{ width: 200 }}
  264. value={this.state.contractType}
  265. showSearch
  266. filterOption={companySearch}
  267. onChange={(e) => { this.setState({ contractType: e }) }}>
  268. {this.state.typeOption}
  269. </Select>
  270. <Select style={{ width: 120 }}
  271. value={this.state.searchStatus}
  272. onChange={(e) => { this.setState({ contractState: e }) }}
  273. placeholder="选择一个状态">
  274. {this.state.stateOption}
  275. </Select>
  276. <span>更多搜索 <Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  277. <Button type="primary" onClick={this.search}>搜索</Button>
  278. <Button onClick={this.reset}>重置</Button>
  279. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  280. <span>创建时间:</span>
  281. <RangePicker style={{ width: '240px' }}
  282. allowClear={false}
  283. value={[this.state.startDateFormattedDate[0] ? moment(this.state.startDateFormattedDate[0]) : null,
  284. this.state.startDateFormattedDate[1] ? moment(this.state.startDateFormattedDate[1]) : null]}
  285. onChange={(date, dateString) => { this.setState({ startDateFormattedDate: dateString }) }} />
  286. <span>结束时间:</span>
  287. <RangePicker style={{ width: '240px' }}
  288. allowClear={false}
  289. value={[this.state.endDateFormattedDate[0] ? moment(this.state.endDateFormattedDate[0]) : null,
  290. this.state.endDateFormattedDate[1] ? moment(this.state.endDateFormattedDate[1]) : null]}
  291. onChange={(date, dateString) => { this.setState({ endDateFormattedDate: dateString }) }} />
  292. </div>
  293. </div>
  294. <div className="foster-table">
  295. <Spin spinning={this.state.loading}>
  296. <Table columns={this.state.columns}
  297. dataSource={this.state.dataSource}
  298. pagination={this.state.pagination}
  299. onRowClick={this.tableRowClick} />
  300. </Spin>
  301. </div>
  302. <ContractDetail
  303. data={this.state.RowData}
  304. statusOption={this.state.statusOption}
  305. showDesc={this.state.showDesc}
  306. closeDesc={this.closeDesc} />
  307. </div >
  308. </div>
  309. );
  310. }
  311. });
  312. export default Contract;