CourseList.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. import React, { PureComponent } from 'react';
  2. import { connect } from 'dva';
  3. import { Link, routerRedux } from 'dva/router';
  4. import {
  5. Popconfirm, Progress, notification, Badge, message, Card,
  6. Icon, Button, Modal, Input, Select, Form, Row, Col
  7. } from 'antd';
  8. import PageHeaderLayout from '../../layouts/PageHeaderLayout';
  9. import StandardTable from '../../components/StandardTable';
  10. import styles from './CourseList.less';
  11. import config from '../../utils/config';
  12. import Logger from '../../utils/logger';
  13. const logger = Logger.getLogger('CourseList');
  14. const { Option } = Select;
  15. const FormItem = Form.Item;
  16. const ButtonGroup = Button.Group;
  17. const getValue = obj => Object.keys(obj).map(key => obj[key]).join(',');
  18. @connect(state => ({
  19. course: state.course,
  20. cp: state.cp,
  21. }))
  22. @Form.create()
  23. export default class CourseList extends PureComponent {
  24. state = {
  25. selectedRows: [],
  26. formValues: {},
  27. }
  28. componentDidMount() {
  29. this.tableListRefresh();
  30. this.props.dispatch({
  31. type: 'cp/getCPList',
  32. payload: {},
  33. });
  34. }
  35. tableListRefresh(params = {}) {
  36. const { dispatch } = this.props;
  37. dispatch({
  38. type: 'course/getCourseList',
  39. payload: params,
  40. });
  41. }
  42. handleSearch = (e) => {
  43. e.preventDefault();
  44. const { form } = this.props;
  45. form.validateFields((err, fieldsValue) => {
  46. if (err) return;
  47. const values = {
  48. ...fieldsValue,
  49. };
  50. this.tableListRefresh(values);
  51. });
  52. }
  53. handleReset = (e) => {
  54. e.preventDefault();
  55. const { form } = this.props;
  56. form.resetFields();
  57. this.tableListRefresh();
  58. }
  59. handleSelectRows = (rows) => {
  60. this.setState({
  61. selectedRows: rows,
  62. });
  63. }
  64. // handleItemAdd = () => {
  65. // const { dispatch } = this.props;
  66. // dispatch(routerRedux.push('/product/lesson/add'));
  67. // }
  68. //
  69. // handleItemEdit = (record) => {
  70. // const { dispatch } = this.props;
  71. // dispatch(routerRedux.push({
  72. // pathname: '/product/lesson/edit',
  73. // state: { code: record.code },
  74. // }));
  75. // }
  76. //
  77. // handleItemDel = (record) => {
  78. // const { dispatch } = this.props;
  79. // dispatch({
  80. // type: 'lesson/delLessonItem',
  81. // payload: { code: record.code },
  82. // });
  83. // dispatch({
  84. // type: 'lesson/getLessonList',
  85. // payload: {},
  86. // });
  87. // }
  88. //
  89. //配置分页器
  90. handleStandardTableChange = (pagination, filterArgs, sorter) => {
  91. const { formValues } = this.state;
  92. const filters = Object.keys(filterArgs).reduce((obj, key) => {
  93. const newObj = {...obj};
  94. newObj[key] = getValue(filterArgs[key]);
  95. return newObj;
  96. }, {});
  97. const params = {
  98. pageNo: pagination.current,
  99. pageSize: pagination.pageSize,
  100. ...formValues,
  101. ...filters,
  102. };
  103. if (sorter.field) {
  104. params.sorter = `${sorter.field}_${sorter.order}`;
  105. }
  106. this.tableListRefresh(params);
  107. }
  108. render() {
  109. const { selectedRows } = this.state;
  110. const { dispatch, course, cp: { cpList } } = this.props;
  111. const { getFieldDecorator } = this.props.form;
  112. const columns = [{
  113. title: '课程编号',
  114. dataIndex: 'code',
  115. },{
  116. title: '课程名称',
  117. dataIndex: 'name',
  118. },{
  119. title: '供应商名称',
  120. dataIndex: 'cpName',
  121. filters: cpList.map(item => ({
  122. text: item.cpName,
  123. value: item.cpId,
  124. })),
  125. },{
  126. title: '使用状态',
  127. dataIndex: 'status',
  128. filters: config.COURSE_STATE.map(item => ({
  129. text: item.name,
  130. value: item.value,
  131. })),
  132. render: (text, record) => (
  133. <p>
  134. {(config.COURSE_STATE.filter(item => item.value === record.status)[0] || { name: '未知' }).name}
  135. </p>
  136. ),
  137. },{
  138. title: '修改时间',
  139. dataIndex: 'gmtModified',
  140. },{
  141. title: '操作类型',
  142. render: (record) => (
  143. <p>
  144. <Button size="small" shape="circle" icon="edit" onClick={() => this.handleItemEdit(record)}></Button>
  145. <span className={styles.splitLine} />
  146. <Popconfirm
  147. placement="top"
  148. okText="删除"
  149. cancelText="取消"
  150. title={`确定删除${record.name}?`}
  151. onConfirm={() => this.handleItemDel(record)}
  152. >
  153. <Button size="small" shape="circle" icon="delete"></Button>
  154. </Popconfirm>
  155. </p>
  156. ),
  157. }];
  158. const standardTableProps = {
  159. dataSource: course.data.list,
  160. pagination: course.data.pagination,
  161. loading: course.loading,
  162. columns: columns,
  163. rowKeyName: 'code',
  164. selectedRows: selectedRows,
  165. };
  166. const pageHeaderSearch = (
  167. <Form layout="inline" onSubmit={this.handleSearch}>
  168. <Row gutter={24}>
  169. <Col md={9} sm={24}>
  170. <FormItem label="课程编号">
  171. {getFieldDecorator('code')(
  172. <Input placeholder="请输入课程编号" />
  173. )}
  174. </FormItem>
  175. </Col>
  176. <Col md={10} sm={24}>
  177. <FormItem label="课程名称">
  178. {getFieldDecorator('name')(
  179. <Input placeholder="请输入课程名称" />
  180. )}
  181. </FormItem>
  182. </Col>
  183. <Col md={5} sm={24} push={1}>
  184. <FormItem>
  185. <ButtonGroup>
  186. <Button icon="search" type="primary" htmlType="submit">搜索</Button>
  187. <Button icon="reload" type="danger" onClick={this.handleReset}>重置</Button>
  188. </ButtonGroup>
  189. </FormItem>
  190. </Col>
  191. </Row>
  192. </Form>
  193. );
  194. return (
  195. <PageHeaderLayout
  196. content={pageHeaderSearch}
  197. >
  198. <div className={styles.content}>
  199. <div className={styles.newButton}>
  200. <Button type="primary" icon="plus" onClick={() => {this.handleItemAdd()}}>新建课程</Button>
  201. </div>
  202. <StandardTable
  203. {...standardTableProps}
  204. onChange={this.handleStandardTableChange}
  205. onSelectRow={this.handleSelectRows}
  206. />
  207. </div>
  208. </PageHeaderLayout>
  209. );
  210. }
  211. }