page.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 { Class } from '../../../stores/class';
  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)} - ${formatDate(row.expireTime)}`;
  61. }).join(<br />);
  62. },
  63. }, {
  64. title: '操作',
  65. dataIndex: 'handler',
  66. render: (text, record) => {
  67. return <div className="table-button">
  68. {(
  69. <Link to={`/user/detail/${record.id}`}>查看</Link>
  70. )}
  71. </div>;
  72. },
  73. },
  74. ];
  75. Class.listCourse({ size: 100 }).then(result => {
  76. this.filterForm[1].select = result.list.map(row => {
  77. return {
  78. title: row.title,
  79. value: row.id,
  80. };
  81. });
  82. this.courseMap = getMap(result.list, 'id');
  83. });
  84. }
  85. initData() {
  86. User.listStudent(this.state.search).then(result => {
  87. this.setTableData(result.list, result.total);
  88. });
  89. }
  90. renderView() {
  91. return <Block flex>
  92. <FilterLayout
  93. show
  94. itemList={this.filterForm}
  95. data={this.state.search}
  96. onChange={data => {
  97. this.search(data);
  98. }}
  99. ref={(ref) => {
  100. if (ref) this.filterF = ref;
  101. }} />
  102. {/* <ActionLayout
  103. itemList={this.actionList}
  104. selectedKeys={this.state.selectedKeys}
  105. onAction={key => this.onAction(key)}
  106. /> */}
  107. <TableLayout
  108. // select
  109. columns={this.columns}
  110. list={this.state.list}
  111. pagination={this.state.page}
  112. loading={this.props.core.loading}
  113. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  114. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  115. selectedKeys={this.state.selectedKeys}
  116. />
  117. </Block>;
  118. }
  119. }