activityUserList.jsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. import React from 'react';
  2. import { Icon, Button, Spin, message, Table, Input, Tabs, Select } from 'antd';
  3. //import { getActivityForm, getActivityType } from '../../../tools';
  4. //import { activityForm, activityType } from '../../../dataDic';
  5. //import moment from 'moment';
  6. import ajax from 'jquery/src/ajax/xhr.js';
  7. import $ from 'jquery/src/ajax';
  8. const ActivityTable = React.createClass({
  9. loadData(pageNo, apiUrl) {
  10. this.setState({
  11. loading: true
  12. });
  13. $.ajax({
  14. method: "get",
  15. dataType: "json",
  16. crossDomain: false,
  17. url: globalConfig.context + (apiUrl || this.props.apiUrl),
  18. data: {
  19. pageNo: pageNo || 1,
  20. pageSize: this.state.pagination.pageSize,
  21. activityName: this.state.searchName,
  22. mobile: this.state.searchMobile,
  23. username: this.state.searchUsername,
  24. unitName: this.state.searchUnitName,
  25. number: this.state.searchNumber,
  26. },
  27. success: function (data) {
  28. let theArr = [];
  29. if (!data.data || !data.data.list) {
  30. if (data.error && data.error.length) {
  31. message.warning(data.error[0].message);
  32. };
  33. } else {
  34. for (let i = 0; i < data.data.list.length; i++) {
  35. let thisdata = data.data.list[i];
  36. theArr.push({
  37. key: i,
  38. aid: thisdata.aid,
  39. uid: thisdata.uid,
  40. createTime: thisdata.createTime,
  41. lastUpdateTime: thisdata.lastUpdateTime,
  42. activityName: thisdata.activityName,
  43. number: thisdata.number,
  44. mobile: thisdata.mobile,
  45. username: thisdata.username,
  46. unitName: thisdata.unitName,
  47. theName: thisdata.username || thisdata.unitName,
  48. startTime: thisdata.startTime,
  49. endTime: thisdata.endTime,
  50. enrollDeadline: thisdata.enrollDeadline,
  51. createTimeFormattedDate: thisdata.createTimeFormattedDate,
  52. enrollDeadlineFormattedDate: thisdata.enrollDeadlineFormattedDate,
  53. startTimeFormattedDate: thisdata.startTimeFormattedDate,
  54. endTimeFormattedDate: thisdata.endTimeFormattedDate,
  55. lastUpdateTimeFormattedDate: thisdata.lastUpdateTimeFormattedDate,
  56. });
  57. };
  58. this.state.pagination.current = data.data.pageNo;
  59. this.state.pagination.total = data.data.totalCount;
  60. };
  61. this.setState({
  62. tableData: theArr,
  63. pagination: this.state.pagination
  64. });
  65. }.bind(this),
  66. }).always(function () {
  67. this.setState({
  68. loading: false
  69. });
  70. }.bind(this));
  71. },
  72. getInitialState() {
  73. return {
  74. loading: false,
  75. visible: false,
  76. selectedRowKeys: [],
  77. selectedRows: [],
  78. pagination: {
  79. defaultCurrent: 1,
  80. defaultPageSize: 10,
  81. showQuickJumper: true,
  82. pageSize: 10,
  83. onChange: function (page) {
  84. this.loadData(page);
  85. }.bind(this),
  86. showTotal: function (total) {
  87. return '共' + total + '条数据';
  88. }
  89. },
  90. columns: [
  91. {
  92. title: '报名用户名称',
  93. dataIndex: 'theName',
  94. key: 'theName'
  95. }, {
  96. title: '活动名称',
  97. dataIndex: 'activityName',
  98. key: 'activityName',
  99. }, {
  100. title: '阿凡提号',
  101. dataIndex: 'number',
  102. key: 'number'
  103. }, {
  104. title: '联系方式',
  105. dataIndex: 'mobile',
  106. key: 'mobile'
  107. }, {
  108. title: '首次报名/咨询时间',
  109. dataIndex: 'createTimeFormattedDate',
  110. key: 'createTimeFormattedDate'
  111. }, {
  112. title: '最近一次报名/咨询时间',
  113. dataIndex: 'lastUpdateTimeFormattedDate',
  114. key: 'lastUpdateTimeFormattedDate'
  115. }, {
  116. title: '活动截止报名时间',
  117. dataIndex: 'enrollDeadlineFormattedDate',
  118. key: 'enrollDeadlineFormattedDate'
  119. }
  120. ],
  121. tableData: []
  122. };
  123. },
  124. componentWillMount() {
  125. this.loadData();
  126. },
  127. componentWillReceiveProps(nextProps) {
  128. if (this.props.tableType !== nextProps.tableType) {
  129. this.loadData(nextProps.apiUrl)
  130. }
  131. },
  132. delectRow() {
  133. let theAid = null, theUid = null;
  134. if (this.state.selectedRows && this.state.selectedRows.length) {
  135. theAid = this.state.selectedRows[0].aid;
  136. theUid = this.state.selectedRows[0].uid;
  137. } else {
  138. return;
  139. }
  140. this.setState({
  141. selectedRowKeys: [],
  142. loading: true
  143. });
  144. $.ajax({
  145. method: "POST",
  146. dataType: "json",
  147. crossDomain: false,
  148. url: globalConfig.context + '/api/admin/activityUser/delete',
  149. data: {
  150. aid: theAid,
  151. uid: theUid
  152. }
  153. }).done(function (data) {
  154. if (data.error && data.error.length) {
  155. message.warning(data.error[0].message);
  156. } else {
  157. message.success('删除成功!');
  158. };
  159. this.setState({
  160. loading: false,
  161. });
  162. this.loadData();
  163. }.bind(this));
  164. },
  165. cleanCache() {
  166. this.setState({
  167. loading: true
  168. });
  169. $.ajax({
  170. method: "post",
  171. dataType: "json",
  172. crossDomain: false,
  173. url: globalConfig.context + '/api/admin/activity/cleanCache',
  174. data: {
  175. 'cacheKey': 'activity_portal_list_cache_key'
  176. },
  177. success: function (data) {
  178. if (data.error && data.error.length) {
  179. message.warning(data.error[0].message);
  180. } else {
  181. message.success('清除缓存成功!');
  182. };
  183. }.bind(this),
  184. }).always(function () {
  185. this.setState({
  186. loading: false
  187. });
  188. }.bind(this));
  189. },
  190. reset() {
  191. this.state.searchName = undefined;
  192. this.state.searchMobile = undefined;
  193. this.state.searchUsername = undefined;
  194. this.state.searchUnitName = undefined;
  195. this.state.searchNumber = undefined;
  196. this.loadData();
  197. },
  198. render() {
  199. const rowSelection = {
  200. selectedRowKeys: this.state.selectedRowKeys,
  201. onChange: (selectedRowKeys, selectedRows) => {
  202. this.setState({
  203. selectedRows: selectedRows.slice(-1),
  204. selectedRowKeys: selectedRowKeys.slice(-1),
  205. });
  206. }
  207. };
  208. const hasSelected = this.state.selectedRowKeys.length > 0;
  209. return (
  210. <div className="admin-content-warp">
  211. <div className="admin-content-search">
  212. <Input placeholder="活动名称" style={{ width: 200 }}
  213. value={this.state.searchName}
  214. onChange={(e) => { this.setState({ searchName: e.target.value }); }} />
  215. <Input placeholder="报名人电话" style={{ width: 200 }}
  216. value={this.state.searchMobile}
  217. onChange={(e) => { this.setState({ searchMobile: e.target.value }); }} />
  218. {(() => {
  219. switch (this.props.tableType) {
  220. case 'user':
  221. return <Input placeholder="报名人名称" style={{ width: 200 }}
  222. value={this.state.searchUsername}
  223. onChange={(e) => { this.setState({ searchUsername: e.target.value }); }} />
  224. case 'org':
  225. return <Input placeholder="报名人名称" style={{ width: 200 }}
  226. value={this.state.searchUnitName}
  227. onChange={(e) => { this.setState({ searchUnitName: e.target.value }); }} />
  228. };
  229. })()}
  230. <Input placeholder="报名人阿凡提号" style={{ width: 200 }}
  231. value={this.state.searchNumber}
  232. onChange={(e) => { this.setState({ searchNumber: e.target.value }); }} />
  233. <Button type="primary" onClick={() => { this.loadData() }}>搜索</Button>
  234. <Button onClick={this.reset}>重置</Button>
  235. <Button type='danger' disabled={!hasSelected} onClick={this.delectRow}>
  236. 删除<Icon type="minus" />
  237. </Button>
  238. <Button type="primary" onClick={() => { this.cleanCache() }}>清除缓存</Button>
  239. </div>
  240. <Spin spinning={this.state.loading}>
  241. <Table className="no-all-select"
  242. columns={this.state.columns}
  243. dataSource={this.state.tableData}
  244. pagination={this.state.pagination}
  245. rowSelection={rowSelection} />
  246. </Spin>
  247. </div>
  248. )
  249. }
  250. });
  251. const ActivityUserList = React.createClass({
  252. getInitialState() {
  253. return {
  254. userApiUrl: '/api/admin/activityUser/userList',
  255. orgApiUrl: '/api/admin/activityUser/orgList',
  256. tableType: 'user'
  257. };
  258. },
  259. tabChange(key) {
  260. this.setState({ tableType: key });
  261. },
  262. render() {
  263. return (
  264. <div className="admin-content" >
  265. <div className="admin-content-title">
  266. <span>活动圈报名管理</span>
  267. </div>
  268. <Tabs activeKey={this.state.tableType} onChange={this.tabChange}>
  269. <Tabs.TabPane tab="个人报名管理" key="user">
  270. <ActivityTable apiUrl={this.state.userApiUrl} tableType={'user'} />
  271. </Tabs.TabPane>
  272. <Tabs.TabPane tab="组织报名管理" key="org">
  273. <ActivityTable apiUrl={this.state.orgApiUrl} tableType={'org'} />
  274. </Tabs.TabPane>
  275. </Tabs>
  276. </div >
  277. );
  278. }
  279. });
  280. export default ActivityUserList;