contract.jsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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.startDateFormattedDate[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) => {
  130. if (text == '3') {
  131. return '已完成'
  132. } else {
  133. return getContractState(text)
  134. }
  135. }
  136. }, {
  137. title: '合同类型',
  138. dataIndex: 'type',
  139. key: 'type',
  140. render: (text) => { return getContractType(text) }
  141. }, {
  142. title: '联系人',
  143. dataIndex: 'contacts',
  144. key: 'contacts',
  145. render: (text) => { return this.state.contactsList[text] }
  146. }, {
  147. title: '完成时间',
  148. dataIndex: 'completeDateFormattedDate',
  149. key: 'completeDateFormattedDate',
  150. }, {
  151. title: '描述',
  152. dataIndex: 'describe',
  153. key: 'describe',
  154. }
  155. ],
  156. dataSource: []
  157. };
  158. },
  159. componentWillMount() {
  160. let _me = this, tArr = [], sArr = [];
  161. contractTypeList.map(function (item) {
  162. tArr.push(
  163. <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  164. )
  165. });
  166. contractStateList.map(function (item) {
  167. if (item.value == '3') {
  168. sArr.push(
  169. <Select.Option value={item.value} key={item.key}>已完成</Select.Option>
  170. )
  171. } else {
  172. sArr.push(
  173. <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  174. )
  175. }
  176. });
  177. this.setState({
  178. typeOption: tArr,
  179. stateOption: sArr
  180. });
  181. this.loadData();
  182. this.getContactsList();
  183. // if (window.location.search) {
  184. // let theArr = getSearchUrl(window.location.search);
  185. // if (theArr.length > 1) {
  186. // let theObj = {};
  187. // theObj.id = theArr[0];
  188. // theObj.uid = theArr[1];
  189. // if (theObj.id != 'null' && theObj.uid != 'null') {
  190. // this.tableRowClick(theObj);
  191. // };
  192. // } else if (theArr.length == 1) {
  193. // this.state.unitName = theArr[0];
  194. // };
  195. // };
  196. },
  197. tableRowClick(record, index) {
  198. this.state.RowData = record;
  199. if (record.status === '0') {
  200. this.setState({
  201. showAdd: true
  202. });
  203. } else {
  204. this.setState({
  205. showDesc: true
  206. });
  207. };
  208. },
  209. closeDesc(e, s) {
  210. this.state.showDesc = e;
  211. if (s) {
  212. this.loadData();
  213. };
  214. },
  215. addClick() {
  216. this.state.RowData = {};
  217. this.setState({
  218. showAdd: true,
  219. });
  220. },
  221. closeAdd(e, s) {
  222. this.setState({
  223. showAdd: e
  224. });
  225. if (s) {
  226. this.loadData();
  227. };
  228. },
  229. searchSwitch() {
  230. this.setState({
  231. searchMore: !this.state.searchMore
  232. });
  233. },
  234. search() {
  235. this.loadData();
  236. },
  237. reset() {
  238. this.state.contractState = undefined;
  239. this.state.contractType = undefined;
  240. this.state.serialNumber = undefined;
  241. this.state.startDateFormattedDate = [];
  242. this.state.endDateFormattedDate = [];
  243. this.loadData();
  244. },
  245. render() {
  246. const { MonthPicker, RangePicker } = DatePicker;
  247. return (
  248. <div className="foster-box">
  249. <div className="foster-content">
  250. <div className="content-title">
  251. <span>合同申请管理</span>
  252. <ContractAdd
  253. contactsOption={this.state.contactsOption}
  254. typeOption={this.state.typeOption}
  255. data={this.state.RowData}
  256. onClick={this.addClick}
  257. showAdd={this.state.showAdd}
  258. closeAdd={this.closeAdd} />
  259. </div>
  260. <div className="foster-query">
  261. <Input value={this.state.serialNumber}
  262. placeholder="输入合同编号"
  263. onChange={(e) => { this.setState({ serialNumber: e.target.value }); }} />
  264. <Select placeholder="选择一个合同类型"
  265. style={{ width: 200 }}
  266. value={this.state.contractType}
  267. showSearch
  268. filterOption={companySearch}
  269. onChange={(e) => { this.setState({ contractType: e }) }}>
  270. {this.state.typeOption}
  271. </Select>
  272. <Select style={{ width: 120 }}
  273. value={this.state.contractState}
  274. onChange={(e) => { this.setState({ contractState: e }) }}
  275. placeholder="选择一个状态">
  276. {this.state.stateOption}
  277. </Select>
  278. <span>更多搜索 <Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  279. <Button type="primary" onClick={this.search}>搜索</Button>
  280. <Button onClick={this.reset}>重置</Button>
  281. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  282. <span>签订时间:</span>
  283. <RangePicker style={{ width: '240px' }}
  284. allowClear={false}
  285. value={[this.state.startDateFormattedDate[0] ? moment(this.state.startDateFormattedDate[0]) : null,
  286. this.state.startDateFormattedDate[1] ? moment(this.state.startDateFormattedDate[1]) : null]}
  287. onChange={(date, dateString) => { this.setState({ startDateFormattedDate: dateString }) }} />
  288. <span>完成时间:</span>
  289. <RangePicker style={{ width: '240px' }}
  290. allowClear={false}
  291. value={[this.state.endDateFormattedDate[0] ? moment(this.state.endDateFormattedDate[0]) : null,
  292. this.state.endDateFormattedDate[1] ? moment(this.state.endDateFormattedDate[1]) : null]}
  293. onChange={(date, dateString) => { this.setState({ endDateFormattedDate: dateString }) }} />
  294. </div>
  295. </div>
  296. <div className="foster-table">
  297. <Spin spinning={this.state.loading}>
  298. <Table columns={this.state.columns}
  299. dataSource={this.state.dataSource}
  300. pagination={this.state.pagination}
  301. style={{
  302. cursor: 'pointer',
  303. }}
  304. onRowClick={this.tableRowClick} />
  305. </Spin>
  306. </div>
  307. <ContractDetail
  308. data={this.state.RowData}
  309. statusOption={this.state.statusOption}
  310. contactsList={this.state.contactsList}
  311. showDesc={this.state.showDesc}
  312. closeDesc={this.closeDesc} />
  313. </div >
  314. </div>
  315. );
  316. }
  317. });
  318. export default Contract;