CourseList.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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/AXList';
  7. import Ellipsis from '../../../components/Ellipsis';
  8. import { renderStatus, addRowKey } from '../../../utils/utils';
  9. const Message = message;
  10. @connect(({ loading, shelves }) => ({
  11. shelves,
  12. loading: loading.models.shelves,
  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: 'shelves/fetchCourseItemList',
  26. payload: { ...this.state.Queryers },
  27. });
  28. }
  29. handleCreateOperation = () => {
  30. this.props.dispatch(routerRedux.push({
  31. pathname: '/shelves/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: 'shelves/deleteItem',
  44. payload: { id: item.id },
  45. states: this.state,
  46. });
  47. },
  48. });
  49. }
  50. handleEditOperation = (item) => {
  51. this.props.dispatch(routerRedux.push({
  52. pathname: '/shelves/course/edit',
  53. state: {
  54. pid: item.pid,
  55. merchantId: item.merchantId,
  56. ...this.state,
  57. },
  58. }));
  59. }
  60. handleFilterOperation = (params, states) => {
  61. this.props.dispatch({
  62. type: 'shelves/fetchCourseItemList',
  63. payload: params,
  64. });
  65. this.setState({
  66. UIParams: states,
  67. Queryers: params,
  68. });
  69. }
  70. handleBatchOperation = () => {
  71. Message.info('暂不支持批量操作!');
  72. }
  73. render() {
  74. const { loading, shelves } = this.props;
  75. const { list, totalSize, pageSize, pageNo } = shelves;
  76. const renderOperation = (item) => {
  77. return (
  78. <div>
  79. <Button
  80. size="small"
  81. className="editBtn"
  82. onClick={() => this.handleEditOperation(item)}
  83. >编辑
  84. </Button>
  85. <Button
  86. size="small"
  87. className="delBtn"
  88. onClick={() => this.handleDeleteOperation(item)}
  89. >下架
  90. </Button>
  91. </div>
  92. );
  93. };
  94. const batchActions = [{
  95. key: 'delete',
  96. name: '批量删除',
  97. }, {
  98. key: 'recovery',
  99. name: '批量恢复',
  100. }];
  101. const basicSearch = {
  102. keys: [{
  103. name: '课程编号',
  104. field: 'code',
  105. }, {
  106. name: '课程名称',
  107. field: 'name',
  108. }],
  109. };
  110. const pagination = {
  111. pageNo,
  112. pageSize,
  113. totalSize,
  114. };
  115. const columns = [{
  116. title: '课程编号',
  117. key: 1,
  118. dataIndex: 'code',
  119. width: '15%',
  120. }, {
  121. title: '课程名称',
  122. key: 2,
  123. dataIndex: 'name',
  124. render: text => (
  125. <Ellipsis tooltip lines={1}>{text}</Ellipsis>
  126. ),
  127. width: '30%',
  128. }, {
  129. title: '上架渠道',
  130. key: 3,
  131. dataIndex: 'merchantName',
  132. width: '14%',
  133. }, {
  134. title: '上架状态',
  135. key: 4,
  136. dataIndex: 'status',
  137. render: text => renderStatus(text, '已下架', '已上架'),
  138. width: '10%',
  139. }, {
  140. title: '更新时间',
  141. key: 5,
  142. dataIndex: 'gmtModified',
  143. render: text => moment(text).format('YYYY-MM-DD HH:mm:ss'),
  144. width: '17%',
  145. }, {
  146. title: '操作',
  147. key: 6,
  148. dataIndex: 'operation',
  149. render: (_, record) => renderOperation(record),
  150. width: '13%',
  151. align: 'right',
  152. }];
  153. return (
  154. <Card>
  155. <StandardTableList
  156. columns={columns}
  157. loading={loading}
  158. dataSource={addRowKey(list)}
  159. header={{
  160. basicSearch,
  161. onFilterClick: this.handleFilterOperation,
  162. onCreateClick: this.handleCreateOperation,
  163. }}
  164. footer={{
  165. pagination,
  166. batchActions,
  167. onBatchClick: this.handleBatchOperation,
  168. }}
  169. keepUIState={{ ...this.state.UIParams }}
  170. />
  171. </Card>
  172. );
  173. }
  174. }