page.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import React from 'react';
  2. import { Link } from 'react-router-dom';
  3. import './index.less';
  4. import Page from '@src/containers/Page';
  5. import Block from '@src/components/Block';
  6. import FilterLayout from '@src/layouts/FilterLayout';
  7. // import ActionLayout from '@src/layouts/ActionLayout';
  8. import TableLayout from '@src/layouts/TableLayout';
  9. import { getMap, formatDate } from '@src/services/Tools';
  10. // import { SwitchSelect, ServiceKey } from '../../../../Constant';
  11. import { User } from '../../../stores/user';
  12. import { Course } from '../../../stores/course';
  13. export default class extends Page {
  14. constructor(props) {
  15. super(props);
  16. this.filterF = null;
  17. this.courseMap = {};
  18. }
  19. init() {
  20. this.filterForm = [
  21. {
  22. key: 'keyword',
  23. type: 'input',
  24. name: 'ID/手机号',
  25. placeholder: '请输入',
  26. },
  27. {
  28. key: 'courseId',
  29. type: 'select',
  30. allowClear: true,
  31. name: '课程',
  32. select: [],
  33. placeholder: '请选择',
  34. number: true,
  35. },
  36. ];
  37. this.columns = [
  38. {
  39. title: '手机号',
  40. dataIndex: 'mobile',
  41. },
  42. {
  43. title: '用户姓名',
  44. dataIndex: 'realName',
  45. },
  46. {
  47. title: '开通科目',
  48. dataIndex: 'classes',
  49. render: (text, record) => {
  50. return (record.classes || []).map(row => {
  51. return this.courseMap[row.courseId];
  52. }).join(<br />);
  53. },
  54. },
  55. {
  56. title: '开通时间',
  57. dataIndex: 'time',
  58. render: (text, record) => {
  59. return (record.classes || []).map(row => {
  60. return `${formatDate(row.startTime, 'YYYY-MM-DD HH:mm:ss')} - ${formatDate(row.expireTime, 'YYYY-MM-DD HH:mm:ss')}`;
  61. }).join(<br />);
  62. },
  63. },
  64. {
  65. title: '创建时间',
  66. dataIndex: 'createTime',
  67. render: (text) => {
  68. return formatDate(text, 'YYYY-MM-DD HH:mm:ss');
  69. },
  70. }, {
  71. title: '操作',
  72. dataIndex: 'handler',
  73. render: (text, record) => {
  74. return <div className="table-button">
  75. {(
  76. <Link to={`/user/detail/${record.id}`}>查看</Link>
  77. )}
  78. </div>;
  79. },
  80. },
  81. ];
  82. Course.list({ size: 100 }).then(result => {
  83. this.filterForm[1].select = result.list.map(row => {
  84. return {
  85. title: row.title,
  86. value: row.id,
  87. };
  88. });
  89. this.courseMap = getMap(result.list, 'id');
  90. });
  91. }
  92. initData() {
  93. User.listStudent(this.state.search).then(result => {
  94. this.setTableData(result.list, result.total);
  95. });
  96. }
  97. renderView() {
  98. return <Block flex>
  99. <FilterLayout
  100. show
  101. itemList={this.filterForm}
  102. data={this.state.search}
  103. onChange={data => {
  104. data.page = 1;
  105. this.search(data);
  106. }}
  107. ref={(ref) => {
  108. if (ref) this.filterF = ref;
  109. }} />
  110. {/* <ActionLayout
  111. itemList={this.actionList}
  112. selectedKeys={this.state.selectedKeys}
  113. onAction={key => this.onAction(key)}
  114. /> */}
  115. <TableLayout
  116. // select
  117. columns={this.tableSort(this.columns)}
  118. list={this.state.list}
  119. pagination={this.state.page}
  120. loading={this.props.core.loading}
  121. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  122. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  123. selectedKeys={this.state.selectedKeys}
  124. />
  125. </Block>;
  126. }
  127. }