member.jsx 5.7 KB

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