userList.jsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. username: 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. managerName: thisdata.managerName,
  123. username: thisdata.username,
  124. number: thisdata.number,
  125. auditStatus: thisdata.auditStatus,
  126. createTimeFormattedDate: thisdata.createTimeFormattedDate,
  127. adminName: thisdata.adminName
  128. });
  129. };
  130. this.state.pagination.current = data.data.pageNo;
  131. this.state.pagination.total = data.data.totalCount;
  132. };
  133. this.setState({
  134. dataSource: this.state.data,
  135. pagination: this.state.pagination
  136. });
  137. }.bind(this),
  138. }).always(function () {
  139. this.setState({
  140. loading: false
  141. });
  142. }.bind(this));
  143. },
  144. getInitialState() {
  145. return {
  146. searchMore: true,
  147. data: [],
  148. loading: false,
  149. pagination: {
  150. defaultCurrent: 1,
  151. defaultPageSize: 10,
  152. showQuickJumper: true,
  153. pageSize: 10,
  154. onChange: function (page) {
  155. this.loadData(page);
  156. }.bind(this),
  157. showTotal: function (total) {
  158. return '共' + total + '条数据';
  159. }
  160. },
  161. columns: [
  162. {
  163. title: '阿凡提号',
  164. dataIndex: 'number',
  165. key: 'number',
  166. }, {
  167. title: '登录名',
  168. dataIndex: 'mobile',
  169. key: 'mobile',
  170. }, {
  171. title: '认证名称',
  172. dataIndex: 'username',
  173. key: 'username',
  174. }, {
  175. title: '认证状态',
  176. dataIndex: 'auditStatus',
  177. key: 'auditStatus',
  178. render: text => { return getAuditState(text); }
  179. }, {
  180. title: '注册时间',
  181. dataIndex: 'createTimeFormattedDate',
  182. key: 'createTimeFormattedDate',
  183. }, {
  184. title: '用户名',
  185. dataIndex: 'aftUsername',
  186. key: 'aftUsername',
  187. }, {
  188. title: '联系方式',
  189. dataIndex: 'email',
  190. key: 'email',
  191. }, {
  192. title: '业务员',
  193. dataIndex: 'adminName',
  194. key: 'adminName',
  195. }
  196. ],
  197. dataSource: [],
  198. searchTime: [,]
  199. };
  200. },
  201. componentWillMount() {
  202. this.loadData();
  203. if (window.location.search) {
  204. let theObj = getSearchUrl(window.location.search);
  205. if (theObj.id != 'null' && theObj.type != 'null') {
  206. this.tableRowClick(theObj);
  207. };
  208. };
  209. },
  210. tableRowClick(record, index) {
  211. this.state.RowData = record;
  212. this.setState({
  213. showDesc: true
  214. });
  215. },
  216. closeDesc(e, s) {
  217. this.state.showDesc = e;
  218. if (s) {
  219. this.loadData();
  220. };
  221. },
  222. search() {
  223. this.loadData();
  224. },
  225. reset() {
  226. this.state.searchAftId = null;
  227. this.state.searchLoginId = null;
  228. this.state.searchAuditStatus = undefined;
  229. this.state.searchAftUsername = null;
  230. this.state.searchEmail = null;
  231. this.state.searchTime = [];
  232. this.loadData();
  233. },
  234. searchSwitch() {
  235. this.setState({
  236. searchMore: !this.state.searchMore
  237. });
  238. },
  239. searchcreateTime(date, dateString) {
  240. this.state.createTime = dateString;
  241. },
  242. render() {
  243. const { RangePicker } = DatePicker;
  244. return (
  245. <div className="user-content" >
  246. <div className="content-title">
  247. <span>个人用户管理</span>
  248. <OrgAdd closeDesc={this.closeDesc} />
  249. </div>
  250. <div className="user-search">
  251. <Input placeholder="阿凡提号" value={this.state.searchAftId}
  252. onChange={(e) => { this.setState({ searchAftId: e.target.value }); }} />
  253. <Input placeholder="登录号" value={this.state.searchLoginId}
  254. onChange={(e) => { this.setState({ searchLoginId: e.target.value }); }} />
  255. <Select placeholder="选择认证状态" style={{ width: 140 }}
  256. value={this.state.searchAuditStatus}
  257. onChange={(e) => { this.setState({ searchAuditStatus: e }) }}>
  258. {
  259. auditStatusList.map(function (item, i) {
  260. return <Select.Option key={i} value={item.value} >{item.key}</Select.Option>
  261. })
  262. }
  263. </Select>
  264. <Input placeholder="认证名称" value={this.state.searchAftUsername}
  265. onChange={(e) => { this.setState({ searchAftUsername: e.target.value }); }} />
  266. <Input placeholder="联系方式" value={this.state.searchEmail}
  267. onChange={(e) => { this.setState({ searchEmail: e.target.value }); }} />
  268. <Button type="primary" onClick={this.search}>搜索</Button>
  269. <Button onClick={this.reset}>重置</Button>
  270. <span>更多搜索<Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  271. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  272. <p>
  273. <span>注册时间:</span>
  274. <RangePicker
  275. value={[this.state.searchTime[0] ? moment(this.state.searchTime[0]) : null,
  276. this.state.searchTime[1] ? moment(this.state.searchTime[1]) : null]}
  277. onChange={(data, dataString) => { this.setState({ searchTime: dataString }); }} />
  278. </p>
  279. </div>
  280. </div>
  281. <div className="patent-table">
  282. <Spin spinning={this.state.loading}>
  283. <Table size="middle" columns={this.state.columns}
  284. dataSource={this.state.dataSource}
  285. pagination={this.state.pagination}
  286. onRowClick={this.tableRowClick} />
  287. </Spin>
  288. </div>
  289. <UserDesc data={this.state.RowData} showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  290. </div >
  291. );
  292. }
  293. });
  294. export default UserList;