|
@@ -0,0 +1,393 @@
|
|
|
+import React, { PureComponent } from 'react';
|
|
|
+import { routerRedux } from 'dva/router';
|
|
|
+import PropTypes from 'prop-types';
|
|
|
+import queryString from 'query-string';
|
|
|
+import { connect } from 'dva';
|
|
|
+import { Spin, Popover, Badge, Table, Radio, Card, Form, Input, Icon, Button, Select } from 'antd';
|
|
|
+import PageHeaderLayout from '../../../layouts/PageHeaderLayout';
|
|
|
+import LessonSelectSortModal from './lessonModal';
|
|
|
+import ResourceSelectModal from './resourceModal';
|
|
|
+import SupportSelectSortModal from './supportModal';
|
|
|
+import { Codes } from '../../../utils/config';
|
|
|
+
|
|
|
+const FormItem = Form.Item;
|
|
|
+const Option = Select.Option;
|
|
|
+const { Meta } = Card;
|
|
|
+const { TextArea } = Input;
|
|
|
+
|
|
|
+@Form.create()
|
|
|
+@connect(state => ({
|
|
|
+ courseDetail: state.courseDetail,
|
|
|
+ resource: state.resource,
|
|
|
+ lesson: state.lesson,
|
|
|
+ support: state.support,
|
|
|
+}))
|
|
|
+export default class CourseDetail extends PureComponent {
|
|
|
+ state = {
|
|
|
+ curClickedBtn: null, //记录点击的按钮
|
|
|
+ };
|
|
|
+
|
|
|
+ // 展示选择模态框 - 加载第一页数据
|
|
|
+ handleModalShow = (btnName) => {
|
|
|
+ this.setState({
|
|
|
+ curClickedBtn: btnName,
|
|
|
+ }, () => {
|
|
|
+ const { dispatch } = this.props;
|
|
|
+ if (btnName === 'lessonBtn') {
|
|
|
+ dispatch({ type: 'courseDetail/showLessonModal' });
|
|
|
+ dispatch({
|
|
|
+ type: 'lesson/query',
|
|
|
+ payload: {
|
|
|
+ pageNo: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ status: Codes.CODE_NORMAL,
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else if (btnName === 'cvImgBtn' || btnName === 'bgImgBtn') {
|
|
|
+ dispatch({ type: 'courseDetail/showResourceModal' });
|
|
|
+ dispatch({
|
|
|
+ type: 'resource/query',
|
|
|
+ payload: {
|
|
|
+ pageNo: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ status: Codes.CODE_NORMAL,
|
|
|
+ type: Codes.CODE_IMAGE,
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else if (btnName === 'supportBtn') {
|
|
|
+ dispatch({ type: 'courseDetail/showSupportModal' });
|
|
|
+ dispatch({
|
|
|
+ type: 'support/query',
|
|
|
+ payload: {
|
|
|
+ pageNo: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ status: Codes.CODE_NORMAL,
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 取消/关闭 - 隐藏选择模态框
|
|
|
+ handleModalCancel = () => {
|
|
|
+ const { curClickedBtn } = this.state;
|
|
|
+ const { dispatch } = this.props;
|
|
|
+ if (curClickedBtn === 'lessonBtn') {
|
|
|
+ dispatch({ type: 'courseDetail/hideLessonModal' });
|
|
|
+ } else if (curClickedBtn === 'cvImgBtn' || curClickedBtn === 'bgImgBtn') {
|
|
|
+ dispatch({ type: 'courseDetail/hideResourceModal' });
|
|
|
+ } else if (curClickedBtn === 'supportBtn') {
|
|
|
+ dispatch({ type: 'courseDetail/hideSupportModal' });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 提交 - 保存选择和排序完的数据到model中
|
|
|
+ handleModalOk = (data) => {
|
|
|
+ const { curClickedBtn } = this.state;
|
|
|
+ const { dispatch } = this.props;
|
|
|
+ if (curClickedBtn === 'lessonBtn') {
|
|
|
+ dispatch({
|
|
|
+ type: 'courseDetail/saveLessonList',
|
|
|
+ payload: { lessonList: data }
|
|
|
+ });
|
|
|
+ } else if (curClickedBtn === 'cvImgBtn') {
|
|
|
+ dispatch({
|
|
|
+ type: 'courseDetail/saveCoverImg',
|
|
|
+ payload: { cvImg: data },
|
|
|
+ });
|
|
|
+ } else if (curClickedBtn === 'bgImgBtn') {
|
|
|
+ dispatch({
|
|
|
+ type: 'courseDetail/saveBackgroundImg',
|
|
|
+ payload: { bgImg: data },
|
|
|
+ });
|
|
|
+ } else if (curClickedBtn === 'supportBtn') {
|
|
|
+ dispatch({
|
|
|
+ type: 'courseDetail/saveSupportList',
|
|
|
+ payload: { supportList: data }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 搜索
|
|
|
+ handleModalSearch = (data) => {
|
|
|
+ const { curClickedBtn } = this.state;
|
|
|
+ const { dispatch } = this.props;
|
|
|
+ const newData = { ...data };
|
|
|
+ if (newData.keyword) {
|
|
|
+ newData[newData.field] = newData.keyword;
|
|
|
+ delete newData.field;
|
|
|
+ delete newData.keyword;
|
|
|
+ } else {
|
|
|
+ delete newData.field;
|
|
|
+ delete newData.keyword;
|
|
|
+ }
|
|
|
+ if (curClickedBtn === 'lessonBtn') {
|
|
|
+ dispatch({
|
|
|
+ type: `lesson/query`,
|
|
|
+ payload: { ...newData, pageNo: 1, pageSize: 10, status: Codes.CODE_NORMAL },
|
|
|
+ });
|
|
|
+ } else if (curClickedBtn === 'cvImgBtn' || curClickedBtn === 'bgImgBtn') {
|
|
|
+ dispatch({
|
|
|
+ type: `resource/query`,
|
|
|
+ payload: { ...newData, pageNo: 1, pageSize: 10, status: Codes.CODE_NORMAL, type: Codes.CODE_IMAGE },
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 翻页 - 资源列表
|
|
|
+ handleModalTableChange = (pagination, filterArgs, filters) => {
|
|
|
+ const { curClickedBtn } = this.state;
|
|
|
+ const { dispatch } = this.props;
|
|
|
+ const newFilters = { ...filters };
|
|
|
+ if (newFilters.keyword) {
|
|
|
+ newFilters[newFilters.field] = newFilters.keyword;
|
|
|
+ delete newFilters.field;
|
|
|
+ delete newFilters.keyword;
|
|
|
+ } else {
|
|
|
+ delete newFilters.field;
|
|
|
+ delete newFilters.keyword;
|
|
|
+ }
|
|
|
+ const getValue = obj => Object.keys(obj).map(key => obj[key]).join(',');
|
|
|
+ const tableFilters = Object.keys(filterArgs).reduce((obj, key) => {
|
|
|
+ const newObj = { ...obj };
|
|
|
+ newObj[key] = getValue(filterArgs[key]);
|
|
|
+ return newObj;
|
|
|
+ }, {});
|
|
|
+
|
|
|
+ const data = { ...newFilters, ...tableFilters, pageNo: pagination.current, pageSize: pagination.pageSize };
|
|
|
+ Object.keys(data).map(key => data[key] ? null : delete data[key]);
|
|
|
+
|
|
|
+ if (curClickedBtn === 'lessonBtn') {
|
|
|
+ dispatch({ type: `lesson/query`, payload: { ...data, status: Codes.CODE_NORMAL } });
|
|
|
+ } else if (curClickedBtn === 'cvImgBtn' || curClickedBtn === 'bgImgBtn') {
|
|
|
+ dispatch({ type: `resource/query`, payload: { ...data, status: Codes.CODE_NORMAL, type: Codes.CODE_IMAGE } });
|
|
|
+ } else if (curClickedBtn === 'supportBtn') {
|
|
|
+ dispatch({ type: `support/query`, payload: { ...data, status: Codes.CODE_NORMAL } });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ handlePageSubmit = (e) => {
|
|
|
+ e.preventDefault()
|
|
|
+ const {
|
|
|
+ dispatch,
|
|
|
+ form: {
|
|
|
+ validateFields,
|
|
|
+ getFieldsValue,
|
|
|
+ resetFields
|
|
|
+ },
|
|
|
+ courseDetail: {
|
|
|
+ operType,
|
|
|
+ currentItem,
|
|
|
+ filters,
|
|
|
+ }
|
|
|
+ } = this.props;
|
|
|
+ validateFields((errors) => {
|
|
|
+ if (errors) { return; }
|
|
|
+ const data = {
|
|
|
+ ...currentItem,
|
|
|
+ ...getFieldsValue(),
|
|
|
+ };
|
|
|
+ dispatch({
|
|
|
+ type: `courseDetail/${operType}`,
|
|
|
+ payload: data,
|
|
|
+ callback: () => {
|
|
|
+ dispatch(
|
|
|
+ routerRedux.push({
|
|
|
+ pathname: '/product/course',
|
|
|
+ search: queryString.stringify(filters),
|
|
|
+ })
|
|
|
+ );
|
|
|
+ }
|
|
|
+ })
|
|
|
+ resetFields();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ handlePageCancel = () => {
|
|
|
+ const { dispatch, courseDetail: { filters } } = this.props;
|
|
|
+ dispatch({ type: 'courseDetail/clearPage' });
|
|
|
+ dispatch(
|
|
|
+ routerRedux.push({
|
|
|
+ pathname: '/product/course',
|
|
|
+ search: queryString.stringify(filters),
|
|
|
+ })
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ render() {
|
|
|
+ const { dispatch, form: { getFieldDecorator }, courseDetail, lesson, resource, support } = this.props;
|
|
|
+ const { itemLoading, currentItem, filters, lessonModalVisible, supportModalVisible, resourceModalVisible } = courseDetail;
|
|
|
+ const { lessonList = [], supportList = [], name, code, digest, cvImg = {}, bgImg = {} } = currentItem;
|
|
|
+
|
|
|
+ // 待选表格去掉分页的跳转及变换页码
|
|
|
+ if (resource && resource.pagination) {
|
|
|
+ delete resource.pagination.showQuickJumper;
|
|
|
+ delete resource.pagination.showSizeChanger;
|
|
|
+ }
|
|
|
+
|
|
|
+ const lessonTableColumns = [{
|
|
|
+ title: '课编号',
|
|
|
+ dataIndex: 'code',
|
|
|
+ key: 'code',
|
|
|
+ },{
|
|
|
+ title: '课名称',
|
|
|
+ dataIndex: 'name',
|
|
|
+ key: 'name',
|
|
|
+ }];
|
|
|
+
|
|
|
+ const supportTableColumns = [{
|
|
|
+ title: '配套编号',
|
|
|
+ dataIndex: 'code',
|
|
|
+ key: 'code',
|
|
|
+ },{
|
|
|
+ title: '配套名称',
|
|
|
+ dataIndex: 'name',
|
|
|
+ key: 'name',
|
|
|
+ }]
|
|
|
+
|
|
|
+ const formItemLayout = {
|
|
|
+ labelCol: {
|
|
|
+ span: 7,
|
|
|
+ },
|
|
|
+ wrapperCol: {
|
|
|
+ span: 12,
|
|
|
+ },
|
|
|
+ };
|
|
|
+ const submitFormLayout = {
|
|
|
+ wrapperCol: {
|
|
|
+ xs: { span: 24, offset: 0 },
|
|
|
+ sm: { span: 10, offset: 7 },
|
|
|
+ },
|
|
|
+ };
|
|
|
+
|
|
|
+ return (
|
|
|
+ <PageHeaderLayout>
|
|
|
+ <Spin spinning={itemLoading}>
|
|
|
+ <Card title="课程信息">
|
|
|
+ <Form layout="horizontal" onSubmit={this.handlePageSubmit}>
|
|
|
+ <FormItem label="课程编号:" hasFeedback {...formItemLayout}>
|
|
|
+ {getFieldDecorator('code', {
|
|
|
+ rules: [{ required: true, type: 'string', message: "编号为必填项!" }],
|
|
|
+ initialValue: code,
|
|
|
+ })(<Input />)}
|
|
|
+ </FormItem>
|
|
|
+ <FormItem label="课程名称:" hasFeedback {...formItemLayout}>
|
|
|
+ {getFieldDecorator('name', {
|
|
|
+ rules: [{ required: true, type: 'string', message: "名称为必填项!" }],
|
|
|
+ initialValue: name,
|
|
|
+ })(<Input />)}
|
|
|
+ </FormItem>
|
|
|
+ <FormItem label="课程简述:" hasFeedback {...formItemLayout}>
|
|
|
+ {getFieldDecorator('digest', {
|
|
|
+ initialValue: digest,
|
|
|
+ })(<TextArea />)}
|
|
|
+ </FormItem>
|
|
|
+ <FormItem label="课程封面" {...formItemLayout}>
|
|
|
+ <Button onClick={() => this.handleModalShow('cvImgBtn')} type="primary" icon="select" size="small">选择</Button>
|
|
|
+ {cvImg.url === undefined ? null :
|
|
|
+ <Card
|
|
|
+ hoverable
|
|
|
+ bordered
|
|
|
+ cover={<img alt="图片加载失败" src={cvImg.url} />}
|
|
|
+ style={{ width: 240, marginTop: 20 }}
|
|
|
+ >
|
|
|
+ </Card>}
|
|
|
+ </FormItem>
|
|
|
+ <FormItem label="课程底图" {...formItemLayout}>
|
|
|
+ <Button onClick={() => this.handleModalShow('bgImgBtn')} type="primary" icon="select" size="small">选择</Button>
|
|
|
+ {bgImg.url === undefined ? null :
|
|
|
+ <Card
|
|
|
+ hoverable
|
|
|
+ bordered
|
|
|
+ cover={<img alt="图片加载失败" src={bgImg.url} />}
|
|
|
+ style={{ width: 240, marginTop: 20 }}
|
|
|
+ >
|
|
|
+ </Card>}
|
|
|
+ </FormItem>
|
|
|
+ <FormItem label="选择课" {...formItemLayout}>
|
|
|
+ <Button onClick={() => this.handleModalShow('lessonBtn')} type="primary" size="small" icon="edit">编辑</Button>
|
|
|
+ </FormItem>
|
|
|
+ <FormItem wrapperCol={{ offset: 7, span: 12 }}>
|
|
|
+ <Table
|
|
|
+ locale={{
|
|
|
+ emptyText: <span style={{ color: "#C6D0D6" }}> <Icon type="frown-o"/>
|
|
|
+ 该课程下不包含任何课,请选择!</span>
|
|
|
+ }}
|
|
|
+ dataSource={lessonList}
|
|
|
+ columns={lessonTableColumns}
|
|
|
+ rowKey={record => record.id}
|
|
|
+ bordered
|
|
|
+ pagination={false}
|
|
|
+ />
|
|
|
+ </FormItem>
|
|
|
+ <FormItem label="相关配套" {...formItemLayout}>
|
|
|
+ <Button onClick={() => this.handleModalShow('supportBtn')} type="primary" size="small" icon="edit">编辑</Button>
|
|
|
+ </FormItem>
|
|
|
+ <FormItem wrapperCol={{ offset: 7, span: 12 }}>
|
|
|
+ <Table
|
|
|
+ locale={{
|
|
|
+ emptyText: <span style={{ color: "#C6D0D6" }}> <Icon type="frown-o"/>
|
|
|
+ 该课程暂无相关配套,请选择!</span>
|
|
|
+ }}
|
|
|
+ dataSource={supportList}
|
|
|
+ columns={supportTableColumns}
|
|
|
+ rowKey={record => record.id}
|
|
|
+ bordered
|
|
|
+ pagination={false}
|
|
|
+ />
|
|
|
+ </FormItem>
|
|
|
+ <FormItem {...submitFormLayout} style={{ marginTop: 32 }}>
|
|
|
+ <Button onClick={this.handlePageCancel}>取消</Button>
|
|
|
+ <Button type="primary" style={{ marginLeft: 35 }} htmlType="submit">提交</Button>
|
|
|
+ </FormItem>
|
|
|
+ </Form>
|
|
|
+ {/*课的模态选择框*/}
|
|
|
+ <LessonSelectSortModal
|
|
|
+ rowKeyName="id"
|
|
|
+ modalVisible={lessonModalVisible}
|
|
|
+ style={{ top: 20 }}
|
|
|
+ width={600}
|
|
|
+ onCancel={this.handleModalCancel}
|
|
|
+ onOk={this.handleModalOk}
|
|
|
+ onSearch={this.handleModalSearch}
|
|
|
+ selTableData={lessonList}
|
|
|
+ fsTableDataSource={lesson.list || []}
|
|
|
+ fsTableLoading={lesson.listLoading}
|
|
|
+ fsTablePagination={lesson.pagination}
|
|
|
+ fsTableOnChange={this.handleModalTableChange}
|
|
|
+ />
|
|
|
+ {/*图片资源的模态选择框*/}
|
|
|
+ <ResourceSelectModal
|
|
|
+ rowKeyName="id"
|
|
|
+ modalVisible={resourceModalVisible}
|
|
|
+ style={{ top: 20 }}
|
|
|
+ width={600}
|
|
|
+ onOk={this.handleModalOk}
|
|
|
+ onCancel={this.handleModalCancel}
|
|
|
+ onSearch={this.handleModalSearch}
|
|
|
+ fsTableDataSource={resource.list || []}
|
|
|
+ fsTableLoading={resource.listLoading}
|
|
|
+ fsTablePagination={resource.pagination}
|
|
|
+ fsTableOnChange={this.handleModalTableChange}
|
|
|
+ />
|
|
|
+ {/*周边的模态选择框*/}
|
|
|
+ <SupportSelectSortModal
|
|
|
+ rowKeyName="id"
|
|
|
+ modalVisible={supportModalVisible}
|
|
|
+ style={{ top: 20 }}
|
|
|
+ width={600}
|
|
|
+ onCancel={this.handleModalCancel}
|
|
|
+ onOk={this.handleModalOk}
|
|
|
+ onSearch={this.handleModalSearch}
|
|
|
+ selTableData={supportList}
|
|
|
+ fsTableDataSource={support.list || []}
|
|
|
+ fsTableLoading={support.listLoading}
|
|
|
+ fsTablePagination={support.pagination}
|
|
|
+ fsTableOnChange={this.handleModalTableChange}
|
|
|
+ />
|
|
|
+ </Card>
|
|
|
+ </Spin>
|
|
|
+ </PageHeaderLayout>
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|