userLibrary.jsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import { Component } from 'react';
  2. import { Input, Select, Spin, Table, message, Button } from 'antd';
  3. class UserLibrary extends Component {
  4. constructor(props) {
  5. super(props);
  6. this.state = {
  7. loading: false,
  8. dataSource: [],
  9. pagination: {
  10. defaultCurrent: 1,
  11. defaultPageSize: 10,
  12. showQuickJumper: true,
  13. pageSize: 10,
  14. onChange: function(page) {
  15. this.loadData(page);
  16. this.setState({
  17. selectedRowKeys: []
  18. });
  19. }.bind(this),
  20. showTotal: function(total) {
  21. return '共' + total + '条数据';
  22. }
  23. },
  24. columns: [
  25. {
  26. title: '用户名',
  27. dataIndex: 'nickname',
  28. key: 'nickname'
  29. },
  30. {
  31. title: '手机号码',
  32. dataIndex: 'mobile',
  33. key: 'mobile'
  34. },
  35. {
  36. title: '用户类型',
  37. dataIndex: 'type',
  38. key: 'type',
  39. render: (text) => {
  40. return text == '1' ? '企业用户':text=='0'? '个人用户':'未认证';
  41. }
  42. },
  43. {
  44. title: '注册时间',
  45. dataIndex: 'createTime',
  46. key: 'createTime'
  47. }
  48. ]
  49. };
  50. }
  51. loadData(pageNo) {
  52. this.state.data = [];
  53. this.setState({
  54. page:pageNo,
  55. loading: true
  56. });
  57. $.ajax({
  58. method: "get",
  59. dataType: "json",
  60. crossDomain: false,
  61. url: globalConfig.context + "/api/admin/user/info",
  62. data: {
  63. pageNo: pageNo || 1,
  64. pageSize: this.state.pagination.pageSize,
  65. type: this.state.type, //需求名称
  66. username: this.state.username,
  67. mobile:this.state.mobile
  68. },
  69. success: function (data) {
  70. let theArr = [];
  71. if (!data.data || !data.data.list) {
  72. if (data.error && data.error.length) {
  73. message.warning(data.error[0].message);
  74. };
  75. } else {
  76. for (let i = 0; i < data.data.list.length; i++) {
  77. let thisdata = data.data.list[i];
  78. theArr.push({
  79. key: i,
  80. id: thisdata.id,
  81. type: thisdata.type, //编号
  82. nickname: thisdata.nickname,
  83. username:thisdata.username,
  84. mobile: thisdata.mobile,
  85. email:thisdata.email,
  86. createTime:thisdata.createTime?(new Date(thisdata.createTime)).toLocaleString():''
  87. });
  88. };
  89. };
  90. this.state.pagination.current = data.data.pageNo;
  91. this.state.pagination.total = data.data.totalCount;
  92. if(data.data&&data.data.list&&!data.data.list.length){
  93. this.state.pagination.current=0
  94. this.state.pagination.total=0
  95. };
  96. this.setState({
  97. total:data.data.totalCount,
  98. dataSource: theArr,
  99. pagination: this.state.pagination
  100. });
  101. }.bind(this),
  102. }).always(function () {
  103. this.setState({
  104. loading: false
  105. });
  106. }.bind(this));
  107. }
  108. search() {
  109. this.loadData();
  110. }
  111. reset() {
  112. this.state.username = '';
  113. this.state.type = undefined;
  114. this.state.mobile = '';
  115. this.loadData();
  116. }
  117. componentWillMount() {
  118. this.loadData();
  119. }
  120. render() {
  121. const rowSelection = {
  122. selectedRowKeys: this.state.selectedRowKeys,
  123. onChange: (selectedRowKeys, selectedRows) => {
  124. this.setState({
  125. selectedRows: selectedRows.slice(-1),
  126. selectedRowKeys: selectedRowKeys.slice(-1)
  127. });
  128. }
  129. };
  130. return (
  131. <div className="user-content">
  132. <div className="content-title">
  133. <div className="content-title">
  134. <span>用户库</span>
  135. </div>
  136. <div className="user-search">
  137. <Input
  138. style={{ marginRight: 10 }}
  139. value={this.state.username}
  140. placeholder="用户名称"
  141. onChange={(e) => {
  142. this.setState({ username: e.target.value });
  143. }}
  144. />
  145. <Input
  146. style={{ marginRight: 10 }}
  147. value={this.state.mobile}
  148. placeholder="手机号码"
  149. onChange={(e) => {
  150. this.setState({ mobile: e.target.value });
  151. }}
  152. />
  153. <Select
  154. value={this.state.type}
  155. style={{ width: 150 }}
  156. placeholder="用户类型"
  157. onChange={(e) => {
  158. this.setState({ type: e });
  159. }}
  160. >
  161. <Select.Option value="0">个人用户</Select.Option>
  162. <Select.Option value="1">企业用户</Select.Option>
  163. </Select>
  164. <Button type="primary" onClick={this.search.bind(this)} style={{ marginRight: 10 }}>
  165. 搜索
  166. </Button>
  167. <Button onClick={this.reset.bind(this)}>重置</Button>
  168. </div>
  169. <div className="patent-table">
  170. <Spin spinning={this.state.loading}>
  171. <Table
  172. columns={this.state.columns}
  173. dataSource={this.state.dataSource}
  174. rowSelection={rowSelection}
  175. pagination={this.state.pagination}
  176. />
  177. </Spin>
  178. </div>
  179. </div>
  180. </div>
  181. );
  182. }
  183. }
  184. export default UserLibrary;