contract.jsx 12 KB

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