member.jsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import React from 'react';
  2. import { Table, Button, Spin, message, Icon } from 'antd';
  3. import { getProvince } from '../../NewDicProvinceList';
  4. import ajax from 'jquery/src/ajax/xhr.js'
  5. import $ from 'jquery/src/ajax';
  6. import TheModal from './modal.jsx';
  7. const Member = React.createClass({
  8. loadData(pageNo) {
  9. this.state.data = [];
  10. this.setState({
  11. loading: true
  12. });
  13. return $.ajax({
  14. type: 'get',
  15. cache: false,
  16. url: globalConfig.context + "/api/admin/supervise/adminList",
  17. dataType: "json",
  18. data: {
  19. pageNo: pageNo || 1,
  20. pageSize: this.state.pagination.pageSize
  21. },
  22. success: function (data) {
  23. if (!data.data) {
  24. if (data.error && data.error.length) {
  25. message.warning(data.error[0].message);
  26. };
  27. return;
  28. };
  29. for (let i = 0; i < data.data.list.length; i++) {
  30. let thisdata = data.data.list[i];
  31. this.state.onlyProvince = thisdata.province;
  32. this.state.data.push({
  33. key: i,
  34. id: thisdata.id,
  35. mobile: thisdata.mobile,
  36. name: thisdata.name,
  37. email: thisdata.email,
  38. createTime: thisdata.createTime,
  39. number: thisdata.number,
  40. province: thisdata.province,
  41. position: thisdata.position,
  42. superior: thisdata.superior,
  43. superiorId: thisdata.superiorId,
  44. createTimeFormattedDate: thisdata.createTimeFormattedDate
  45. });
  46. };
  47. this.state.pagination.current = data.data.pageNo;
  48. this.state.pagination.total = data.data.totalCount;
  49. this.setState({
  50. data: this.state.data,
  51. pagination: this.state.pagination
  52. });
  53. }.bind(this),
  54. }).always(function () {
  55. this.setState({
  56. loading: false
  57. });
  58. }.bind(this));
  59. },
  60. getInitialState() {
  61. return {
  62. data: [],
  63. dataSource: [],
  64. selectedRowKeys: [],
  65. selectedRows: [],
  66. loading: false,
  67. modalData: {},
  68. modalShow: false,
  69. pagination: {
  70. defaultCurrent: 1,
  71. defaultPageSize: 10,
  72. showQuickJumper: true,
  73. pageSize: 10,
  74. onChange: function (page) {
  75. this.loadData(page);
  76. }.bind(this),
  77. showTotal: function (total) {
  78. return '共' + total + '条数据';
  79. }
  80. }
  81. }
  82. },
  83. componentDidMount() {
  84. this.loadData();
  85. },
  86. addNew() {
  87. let e = {}
  88. this.setState({
  89. modalData: e,
  90. modalShow: true
  91. })
  92. },
  93. edit(e) {
  94. this.setState({
  95. modalData: e,
  96. modalShow: true
  97. })
  98. },
  99. handleReturn(show, render) {
  100. this.state.modalShow = show;
  101. if (render) {
  102. this.loadData();
  103. }
  104. },
  105. render() {
  106. const columns = [{
  107. title: '编号',
  108. dataIndex: 'number',
  109. key: 'number'
  110. }, {
  111. title: '登录账号',
  112. dataIndex: 'mobile',
  113. key: 'mobile'
  114. }, {
  115. title: '名字',
  116. dataIndex: 'name',
  117. key: 'name'
  118. }, {
  119. title: '职位',
  120. dataIndex: 'position',
  121. key: 'position'
  122. }, {
  123. title: '上级管理员',
  124. dataIndex: 'superior',
  125. key: 'superior'
  126. }, {
  127. title: '省份',
  128. dataIndex: 'province',
  129. key: 'province',
  130. render: text => {
  131. return text ? text.split(',').map((item) => {
  132. return getProvince(item) + ' '
  133. }) : []
  134. }
  135. }, {
  136. title: '邮箱',
  137. dataIndex: 'email',
  138. key: 'email'
  139. }, {
  140. title: '创建时间',
  141. dataIndex: 'createTimeFormattedDate',
  142. key: 'createTimeFormattedDate'
  143. }];
  144. return (
  145. <Spin spinning={this.state.loading}>
  146. <div className="set-content">
  147. <div className="set-title">
  148. <span>管理员设置</span>
  149. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  150. onClick={this.addNew}>添加<Icon type="plus" /></Button>
  151. </div>
  152. <TheModal data={this.state.modalData} onlyProvince={this.state.onlyProvince} show={this.state.modalShow} handleReturn={this.handleReturn} />
  153. <Table className='member-table'
  154. columns={columns}
  155. onRowClick={this.edit}
  156. dataSource={this.state.data}
  157. pagination={this.state.pagination} />
  158. </div>
  159. </Spin>
  160. );
  161. }
  162. });
  163. export default Member;