contract.jsx 12 KB

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