userList.jsx 11 KB

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