|
@@ -6,7 +6,7 @@ import { connect } from 'dva';
|
|
|
import { Spin, Popover, Badge, Table, Radio, Card, Form, Input, Icon, Button, Select } from 'antd';
|
|
|
import PageHeaderLayout from '../../../layouts/PageHeaderLayout';
|
|
|
import ResourceSelectSortModal from './modal';
|
|
|
-import { Codes, resourceType } from '../../../utils/config';
|
|
|
+import { Codes, resourceType, pageSize } from '../../../utils/config';
|
|
|
|
|
|
const FormItem = Form.Item;
|
|
|
const Option = Select.Option;
|
|
@@ -18,19 +18,19 @@ const { TextArea } = Input;
|
|
|
resource: state.resource,
|
|
|
}))
|
|
|
export default class WareDetail extends PureComponent {
|
|
|
- static propTypes = {
|
|
|
- wareDetail: PropTypes.object,
|
|
|
- };
|
|
|
+ state = { resType: [String(Codes.CODE_IMAGE)] }; // 资源类型[默认为图片资源]
|
|
|
|
|
|
// 展示模态框 - 加载第一页数据
|
|
|
handleModalShow = () => {
|
|
|
const { dispatch } = this.props;
|
|
|
+ const { resType } = this.state;
|
|
|
dispatch({ type: 'wareDetail/showModal' });
|
|
|
dispatch({
|
|
|
type: 'resource/query',
|
|
|
payload: {
|
|
|
pageNo: 1,
|
|
|
- pageSize: 10,
|
|
|
+ pageSize,
|
|
|
+ type: resType[0],
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -53,40 +53,51 @@ export default class WareDetail extends PureComponent {
|
|
|
// 搜索
|
|
|
handleModalSearch = (data) => {
|
|
|
const { dispatch } = this.props;
|
|
|
+ const { resType } = this.state;
|
|
|
const newData = { ...data };
|
|
|
if (newData.keyword) {
|
|
|
newData[newData.field] = newData.keyword;
|
|
|
- delete newData.field;
|
|
|
- delete newData.keyword;
|
|
|
- } else {
|
|
|
- delete newData.field;
|
|
|
- delete newData.keyword;
|
|
|
}
|
|
|
+ delete newData.field;
|
|
|
+ delete newData.keyword;
|
|
|
+
|
|
|
dispatch({
|
|
|
type: 'resource/query',
|
|
|
- payload: { ...newData, pageNo: 1, pageSize: 10 },
|
|
|
+ payload: {
|
|
|
+ ...newData,
|
|
|
+ type: resType[0],
|
|
|
+ pageNo: 1,
|
|
|
+ pageSize,
|
|
|
+ },
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 翻页 - 资源列表
|
|
|
handleModalTableOnChange = (pagination, filterArgs, filters) => {
|
|
|
+ // 待选资源列表中资源类型过滤选项
|
|
|
+ const { type } = filterArgs;
|
|
|
+ if (Array.isArray(type) && type.length) {
|
|
|
+ this.setState({ resType: type.map(item => String(item)) });
|
|
|
+ } else {
|
|
|
+ this.setState({ resType: [String(Codes.CODE_IMAGE)] });
|
|
|
+ filterArgs.type = [String(Codes.CODE_IMAGE)];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 整理要搜索的内容及过滤项
|
|
|
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;
|
|
|
}
|
|
|
+ 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]);
|
|
|
dispatch({ type: 'resource/query', payload: data });
|
|
@@ -108,11 +119,17 @@ export default class WareDetail extends PureComponent {
|
|
|
}
|
|
|
} = this.props;
|
|
|
validateFields((errors) => {
|
|
|
- if (errors) { return; }
|
|
|
- const data = {
|
|
|
- ...currentItem,
|
|
|
- ...getFieldsValue(),
|
|
|
- };
|
|
|
+ if (errors) return;
|
|
|
+
|
|
|
+ const { id, status, resourceList } = currentItem;
|
|
|
+ const data = {...getFieldsValue()}
|
|
|
+ data.resourceList = (resourceList || []).map(item => item.id);
|
|
|
+ if (operType === 'create') {
|
|
|
+ data.status = Codes.CODE_NORMAL;
|
|
|
+ } else if (operType === 'update') {
|
|
|
+ data.id = id;
|
|
|
+ data.status = status;
|
|
|
+ }
|
|
|
dispatch({
|
|
|
type: `wareDetail/${operType}`,
|
|
|
payload: data,
|
|
@@ -123,9 +140,9 @@ export default class WareDetail extends PureComponent {
|
|
|
search: queryString.stringify(filters),
|
|
|
})
|
|
|
);
|
|
|
+ resetFields();
|
|
|
}
|
|
|
- })
|
|
|
- resetFields();
|
|
|
+ });
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -141,7 +158,9 @@ export default class WareDetail extends PureComponent {
|
|
|
}
|
|
|
|
|
|
render() {
|
|
|
- const { dispatch, form: { getFieldDecorator }, wareDetail, resource } = this.props;
|
|
|
+ const { dispatch, wareDetail, resource, form } = this.props;
|
|
|
+ const { resType } = this.state;
|
|
|
+ const { getFieldDecorator } = form;
|
|
|
const { itemLoading, currentItem, filters, modalVisible } = wareDetail;
|
|
|
const { resourceList, name, code, digest } = currentItem;
|
|
|
const { list, listLoading, pagination } = resource;
|
|
@@ -244,7 +263,7 @@ export default class WareDetail extends PureComponent {
|
|
|
emptyText: <span style={{ color: "#C6D0D6" }}> <Icon type="frown-o"/>
|
|
|
该课件下不包含任何内容,请选择图片或视频!</span>
|
|
|
}}
|
|
|
- dataSource={resourceList}
|
|
|
+ dataSource={resourceList || []}
|
|
|
columns={subTableColumns}
|
|
|
rowKey={record => record.id}
|
|
|
bordered
|
|
@@ -268,6 +287,7 @@ export default class WareDetail extends PureComponent {
|
|
|
fsTableDataSource={list}
|
|
|
fsTableLoading={listLoading}
|
|
|
fsTablePagination={pagination}
|
|
|
+ fsFilteredValue={resType}
|
|
|
fsTableOnChange={this.handleModalTableOnChange}
|
|
|
/>
|
|
|
</Card>
|