userList.jsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. import React from 'react';
  2. import { Icon, Button, Input, Select, Spin, Table, Switch, message, DatePicker, Modal } from 'antd';
  3. import ajax from 'jquery/src/ajax/xhr.js';
  4. import $ from 'jquery/src/ajax';
  5. import moment from 'moment';
  6. import './userList.less';
  7. import UserDesc from './userDesc.jsx';
  8. import { auditStatusList } from '../../dataDic.js';
  9. import { getAuditState, getSearchUrl } from '../../tools.js';
  10. const OrgAdd = React.createClass({
  11. getInitialState() {
  12. return {
  13. visible: false,
  14. loading: false
  15. };
  16. },
  17. showModal() {
  18. this.state.mobile;
  19. this.setState({
  20. visible: true,
  21. });
  22. },
  23. handleCancel(e) {
  24. this.setState({
  25. visible: false,
  26. });
  27. },
  28. handleOk() {
  29. this.setState({
  30. loading: true
  31. });
  32. $.ajax({
  33. method: "post",
  34. dataType: "json",
  35. crossDomain: false,
  36. url: globalConfig.context + "/api/admin/addNewUser",
  37. data: {
  38. mobile: this.state.mobile,
  39. type: 0
  40. }
  41. }).done(function (data) {
  42. this.setState({
  43. loading: false
  44. });
  45. if (!data.error.length) {
  46. message.success('新增成功!');
  47. this.setState({
  48. visible: false,
  49. });
  50. this.props.closeDesc(false, true);
  51. } else {
  52. message.warning(data.error[0].message);
  53. };
  54. }.bind(this));
  55. },
  56. render() {
  57. return (
  58. <div className="patent-desc" style={{ float: 'right', marginRight: '20px' }}>
  59. <Button type="primary" onClick={this.showModal}>添加用户</Button>
  60. <Modal maskClosable={false} title="新增个人用户" visible={this.state.visible}
  61. onCancel={this.handleCancel}
  62. width='350px'
  63. footer={[
  64. <Button key="submit" type="primary" loading={this.state.loading} onClick={this.handleOk}>提交</Button>,
  65. <Button key="back" onClick={this.handleCancel}>返回</Button>
  66. ]}
  67. className="admin-desc-content">
  68. <div className='orgAdd-input'>
  69. <span>用户手机号码:</span>
  70. <Input
  71. value={this.state.mobile}
  72. onChange={(e) => { this.setState({ mobile: e.target.value }); }} />
  73. </div>
  74. </Modal>
  75. </div>
  76. );
  77. }
  78. });
  79. const UserList = React.createClass({
  80. loadData(pageNo) {
  81. this.state.data = [];
  82. this.setState({
  83. loading: true
  84. });
  85. $.ajax({
  86. method: "post",
  87. dataType: "json",
  88. crossDomain: false,
  89. url: globalConfig.context + "/api/admin/userList",
  90. data: {
  91. pageNo: pageNo || 1,
  92. pageSize: this.state.pagination.pageSize,
  93. mobile: this.state.searchLoginId, //登录名
  94. email: this.state.searchEmail,
  95. createTime: this.state.searchTime,
  96. number: this.state.searchAftId, //阿凡提号
  97. aftUsername: this.state.searchAftUsername,
  98. auditStatus: this.state.searchAuditStatus
  99. },
  100. success: function (data) {
  101. if ( !data.data || !data.data.list) {
  102. if (data.error && data.error.length) {
  103. message.warning(data.error[0].message);
  104. };
  105. } else {
  106. for (let i = 0; i < data.data.list.length; i++) {
  107. let thisdata = data.data.list[i];
  108. this.state.data.push({
  109. key: i,
  110. id: thisdata.id,
  111. mobile: thisdata.mobile,
  112. email: thisdata.email,
  113. createTime: thisdata.createTime,
  114. aftUsername: thisdata.aftUsername,
  115. number: thisdata.number,
  116. auditStatus: thisdata.auditStatus,
  117. createTimeFormattedDate: thisdata.createTimeFormattedDate,
  118. adminName: thisdata.adminName
  119. });
  120. };
  121. };
  122. this.state.pagination.current = data.data.pageNo;
  123. this.state.pagination.total = data.data.totalCount;
  124. this.setState({
  125. dataSource: this.state.data,
  126. pagination: this.state.pagination
  127. });
  128. }.bind(this),
  129. }).always(function () {
  130. this.setState({
  131. loading: false
  132. });
  133. }.bind(this));
  134. },
  135. getInitialState() {
  136. return {
  137. searchMore: true,
  138. data: [],
  139. loading: false,
  140. pagination: {
  141. defaultCurrent: 1,
  142. defaultPageSize: 10,
  143. showQuickJumper: true,
  144. pageSize: 10,
  145. onChange: function (page) {
  146. this.loadData(page);
  147. }.bind(this),
  148. showTotal: function (total) {
  149. return '共' + total + '条数据';
  150. }
  151. },
  152. columns: [
  153. {
  154. title: '阿凡提号',
  155. dataIndex: 'number',
  156. key: 'number',
  157. }, {
  158. title: '登录名',
  159. dataIndex: 'mobile',
  160. key: 'mobile',
  161. }, {
  162. title: '认证状态',
  163. dataIndex: 'auditStatus',
  164. key: 'auditStatus',
  165. render: text => { return getAuditState(text); }
  166. }, {
  167. title: '注册时间',
  168. dataIndex: 'createTimeFormattedDate',
  169. key: 'createTimeFormattedDate',
  170. }, {
  171. title: '认证名称',
  172. dataIndex: 'aftUsername',
  173. key: 'aftUsername',
  174. }, {
  175. title: '联系方式',
  176. dataIndex: 'email',
  177. key: 'email',
  178. }, {
  179. title: '业务员',
  180. dataIndex: 'adminName',
  181. key: 'adminName',
  182. }
  183. ],
  184. dataSource: [],
  185. searchTime: [,]
  186. };
  187. },
  188. componentWillMount() {
  189. this.loadData();
  190. if (window.location.search) {
  191. let theObj = getSearchUrl(window.location.search);
  192. if (theObj.id != 'null' && theObj.type != 'null') {
  193. this.tableRowClick(theObj);
  194. };
  195. };
  196. },
  197. tableRowClick(record, index) {
  198. this.state.RowData = record;
  199. this.setState({
  200. showDesc: true
  201. });
  202. },
  203. closeDesc(e, s) {
  204. this.state.showDesc = e;
  205. if (s) {
  206. this.loadData();
  207. };
  208. },
  209. search() {
  210. this.loadData();
  211. },
  212. reset() {
  213. this.state.searchAftId = null;
  214. this.state.searchLoginId = null;
  215. this.state.searchAuditStatus = null;
  216. this.state.searchAftUsername = null;
  217. this.state.searchEmail = null;
  218. this.state.searchTime = [];
  219. this.loadData();
  220. },
  221. searchSwitch() {
  222. this.setState({
  223. searchMore: !this.state.searchMore
  224. });
  225. },
  226. searchcreateTime(date, dateString) {
  227. this.state.createTime = dateString;
  228. },
  229. render() {
  230. const { RangePicker } = DatePicker;
  231. return (
  232. <div className="user-content" >
  233. <div className="content-title">
  234. <span>个人用户管理</span>
  235. <OrgAdd closeDesc={this.closeDesc} />
  236. </div>
  237. <div className="user-search">
  238. <Input placeholder="阿凡提号" value={this.state.searchAftId}
  239. onChange={(e) => { this.setState({ searchAftId: e.target.value }); }} />
  240. <Input placeholder="登录号" value={this.state.searchLoginId}
  241. onChange={(e) => { this.setState({ searchLoginId: e.target.value }); }} />
  242. <Select placeholder="选择认证状态" style={{ width: 140 }}
  243. value={this.state.searchAuditStatus}
  244. onChange={(e) => { this.setState({ searchAuditStatus: e }) }}>
  245. {
  246. auditStatusList.map(function (item, i) {
  247. return <Select.Option key={i} value={item.value} >{item.key}</Select.Option>
  248. })
  249. }
  250. </Select>
  251. <Input placeholder="认证名称" value={this.state.searchAftUsername}
  252. onChange={(e) => { this.setState({ searchAftUsername: e.target.value }); }} />
  253. <Input placeholder="联系方式" value={this.state.searchEmail}
  254. onChange={(e) => { this.setState({ searchEmail: e.target.value }); }} />
  255. <Button type="primary" onClick={this.search}>搜索</Button>
  256. <Button onClick={this.reset}>重置</Button>
  257. <span>更多搜索<Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  258. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  259. <p>
  260. <span>注册时间:</span>
  261. <RangePicker
  262. value={[this.state.searchTime[0] ? moment(this.state.searchTime[0]) : null,
  263. this.state.searchTime[1] ? moment(this.state.searchTime[1]) : null]}
  264. onChange={(data, dataString) => { this.setState({ searchTime: dataString }); }} />
  265. </p>
  266. </div>
  267. </div>
  268. <div className="patent-table">
  269. <Spin spinning={this.state.loading}>
  270. <Table columns={this.state.columns}
  271. dataSource={this.state.dataSource}
  272. pagination={this.state.pagination}
  273. onRowClick={this.tableRowClick} />
  274. </Spin>
  275. </div>
  276. <UserDesc data={this.state.RowData} showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  277. </div >
  278. );
  279. }
  280. });
  281. export default UserList;