page.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import React from 'react';
  2. import { Link } from 'react-router-dom';
  3. import { Button } from 'antd';
  4. import './index.less';
  5. import Page from '@src/containers/Page';
  6. import Block from '@src/components/Block';
  7. import FilterLayout from '@src/layouts/FilterLayout';
  8. import ActionLayout from '@src/layouts/ActionLayout';
  9. import TableLayout from '@src/layouts/TableLayout';
  10. import { getMap, formatTreeData } from '@src/services/Tools';
  11. // import { asyncSMessage, asyncDelConfirm } from '@src/services/AsyncTools';
  12. import { DataType, SwitchSelect } from '../../../../Constant';
  13. // import { User } from '../../../stores/user';
  14. import { Exercise } from '../../../stores/exercise';
  15. import { Course } from '../../../stores/course';
  16. const SwitchSelectMap = getMap(SwitchSelect, 'value', 'label');
  17. const DataTypeMap = getMap(DataType, 'value', 'label');
  18. export default class extends Page {
  19. init() {
  20. this.actionList = [{
  21. key: 'add',
  22. type: 'primary',
  23. name: '创建',
  24. render: (item) => {
  25. return <Button onClick={() => {
  26. linkTo('/course/data/detail');
  27. }}>{item.name}</Button>;
  28. },
  29. }];
  30. this.exerciseMap = {};
  31. this.filterForm = [{
  32. key: 'structId',
  33. type: 'tree',
  34. allowClear: true,
  35. name: '学科',
  36. select: [],
  37. placeholder: '请选择',
  38. number: true,
  39. }, {
  40. key: 'dataType',
  41. type: 'select',
  42. allowClear: true,
  43. name: '资料形式',
  44. select: DataType,
  45. placeholder: '请选择',
  46. }];
  47. this.columns = [
  48. {
  49. title: '学科',
  50. dataIndex: 'structId',
  51. render: (text, record) => {
  52. return `${record.parentStructId ? `${this.exerciseMap[record.parentStructId]}-` : ''}${this.exerciseMap[record.structId]}`;
  53. },
  54. },
  55. {
  56. title: '资料形式',
  57. dataIndex: 'dataType',
  58. render: (text) => {
  59. return DataTypeMap[text] || text;
  60. },
  61. },
  62. {
  63. title: '适合新手',
  64. dataIndex: 'isNovice',
  65. render: (text) => {
  66. return SwitchSelectMap[text];
  67. },
  68. },
  69. {
  70. title: '原创资料',
  71. dataIndex: 'isOriginal',
  72. render: (text) => {
  73. return SwitchSelectMap[text];
  74. },
  75. }, {
  76. title: '资料名称',
  77. dataIndex: 'title',
  78. }, {
  79. title: '查看人数',
  80. dataIndex: 'viewNumber',
  81. }, {
  82. title: '购买人数',
  83. dataIndex: 'saleNumber',
  84. }, {
  85. title: '操作',
  86. dataIndex: 'handler',
  87. render: (text, record) => {
  88. return <div className="table-button">
  89. {(
  90. <Link to={`/course/data/detail/${record.id}`}>编辑</Link>
  91. )}
  92. </div>;
  93. },
  94. },
  95. ];
  96. Exercise.courseStruct().then((result) => {
  97. const list = result.map(row => { row.title = `${row.titleZh}/${row.titleEn}`; row.value = row.id; return row; });
  98. this.filterForm[0].tree = formatTreeData(list, 'id', 'title', 'parentId');
  99. this.exerciseMap = getMap(result.map(row => {
  100. row.title = `${row.titleZh}/${row.titleEn}`;
  101. row.value = row.id;
  102. return row;
  103. }), 'id', 'title');
  104. this.setState({ exercise: result });
  105. });
  106. }
  107. initData() {
  108. Course.listData(this.state.search).then(result => {
  109. this.setTableData(result.list, result.total);
  110. });
  111. }
  112. renderView() {
  113. const { exercise } = this.state;
  114. return <Block flex>
  115. {exercise && <FilterLayout
  116. show
  117. itemList={this.filterForm}
  118. data={this.state.search}
  119. onChange={data => {
  120. this.search(data);
  121. }} />}
  122. <ActionLayout
  123. itemList={this.actionList}
  124. selectedKeys={this.state.selectedKeys}
  125. onAction={key => this.onAction(key)}
  126. />
  127. <TableLayout
  128. columns={this.columns}
  129. list={this.state.list}
  130. pagination={this.state.page}
  131. loading={this.props.core.loading}
  132. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  133. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  134. selectedKeys={this.state.selectedKeys}
  135. />
  136. </Block>;
  137. }
  138. }