CourseList.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import React, { Component } from 'react';
  2. import moment from 'moment';
  3. import { connect } from 'dva';
  4. import { routerRedux } from 'dva/router';
  5. import { Card, Modal, Button, message } from 'antd';
  6. import { StandardTableList } from '../../../components/RBList/index';
  7. import { renderStatus, addRowKey } from '../../../utils/utils';
  8. import styles from './CourseList.less';
  9. const Message = message;
  10. @connect(({ loading, product }) => ({
  11. product,
  12. loading: loading.models.product,
  13. }))
  14. export default class CourseListPage extends Component {
  15. constructor(props) {
  16. super(props);
  17. const { state } = props.location;
  18. this.state = {
  19. UIParams: (state || {}).UIParams, // 组件的状态参数
  20. Queryers: (state || {}).Queryers, // 查询的条件参数
  21. };
  22. }
  23. componentDidMount() {
  24. this.props.dispatch({
  25. type: 'product/fetchCourseList',
  26. payload: { ...this.state.Queryers },
  27. });
  28. }
  29. handleCreateOperation = () => {
  30. this.props.dispatch(routerRedux.push({
  31. pathname: '/product/course/create',
  32. state: this.state,
  33. }));
  34. }
  35. handleDeleteOperation = (item) => {
  36. Modal.confirm({
  37. okText: '确定',
  38. cancelText: '取消',
  39. title: '你确定要删除该课程吗?',
  40. content: '如果该课程已经被某些套餐包关联,则将导致删除失败,需要手动解除与这些套餐包的关联才可进行删除',
  41. onOk: () => {
  42. this.props.dispatch({
  43. type: 'product/deleteCourseItem',
  44. payload: { id: item.id },
  45. states: this.state,
  46. });
  47. },
  48. });
  49. }
  50. handleEditOperation = (item) => {
  51. this.props.dispatch(routerRedux.push({
  52. pathname: `/product/course/edit/${item.pid}`,
  53. state: this.state,
  54. }));
  55. }
  56. handleFilterOperation = (params, states) => {
  57. this.props.dispatch({
  58. type: 'product/fetchCourseList',
  59. payload: params,
  60. });
  61. this.setState({
  62. UIParams: states,
  63. Queryers: params,
  64. });
  65. }
  66. handleBatchOperation = () => {
  67. Message.info('暂不支持批量操作!');
  68. }
  69. render() {
  70. const { loading, product } = this.props;
  71. const { list, totalSize, pageSize, pageNo } = product;
  72. const renderOperation = (item) => {
  73. return (
  74. <div>
  75. <Button
  76. size="small"
  77. className={styles.editBtn}
  78. onClick={() => this.handleEditOperation(item)}
  79. >编辑
  80. </Button>
  81. <Button
  82. size="small"
  83. className={styles.delBtn}
  84. onClick={() => this.handleDeleteOperation(item)}
  85. >删除
  86. </Button>
  87. </div>
  88. );
  89. };
  90. const batchActions = [{
  91. key: 'delete',
  92. name: '批量删除',
  93. }, {
  94. key: 'recovery',
  95. name: '批量恢复',
  96. }];
  97. const basicSearch = {
  98. keys: [{
  99. name: '课程编号',
  100. field: 'code',
  101. }, {
  102. name: '课程名称',
  103. field: 'name',
  104. }],
  105. };
  106. const pagination = {
  107. pageNo,
  108. pageSize,
  109. totalSize,
  110. };
  111. const columns = [{
  112. title: '课程编号',
  113. key: 1,
  114. dataIndex: 'code',
  115. render: (text, record) => (
  116. <a
  117. className={styles.link}
  118. onClick={() => this.handleEditOperation(record)}
  119. >
  120. {text}
  121. </a>
  122. ),
  123. width: '25%',
  124. }, {
  125. title: '课程名称',
  126. key: 2,
  127. dataIndex: 'name',
  128. render: (text, record) => (
  129. <a
  130. className={styles.link}
  131. onClick={() => this.handleEditOperation(record)}
  132. >
  133. {text}
  134. </a>
  135. ),
  136. width: '30%',
  137. }, {
  138. title: '课程状态',
  139. key: 3,
  140. dataIndex: 'status',
  141. render: text => renderStatus(text),
  142. width: '12%',
  143. }, {
  144. title: '更新时间',
  145. key: 4,
  146. dataIndex: 'gmtModified',
  147. render: text => moment(text).format('YYYY-MM-DD HH:mm:ss'),
  148. width: '20%',
  149. }, {
  150. title: '操作',
  151. key: 5,
  152. dataIndex: 'operation',
  153. render: (_, record) => renderOperation(record),
  154. width: '13%',
  155. }];
  156. return (
  157. <Card>
  158. <StandardTableList
  159. columns={columns}
  160. loading={loading}
  161. dataSource={addRowKey(list)}
  162. header={{
  163. basicSearch,
  164. onFilterClick: this.handleFilterOperation,
  165. onCreateClick: this.handleCreateOperation,
  166. }}
  167. footer={{
  168. pagination,
  169. batchActions,
  170. onBatchClick: this.handleBatchOperation,
  171. }}
  172. keepUIState={{ ...this.state.UIParams }}
  173. />
  174. </Card>
  175. );
  176. }
  177. }