|
@@ -1,13 +1,14 @@
|
|
|
import React from 'react';
|
|
|
+import { Row, Button, Switch, Col, List, Icon } from 'antd';
|
|
|
import './index.less';
|
|
|
import Page from '@src/containers/Page';
|
|
|
import Block from '@src/components/Block';
|
|
|
import FilterLayout from '@src/layouts/FilterLayout';
|
|
|
import ActionLayout from '@src/layouts/ActionLayout';
|
|
|
import TableLayout from '@src/layouts/TableLayout';
|
|
|
+import DragList from '@src/components/DragList';
|
|
|
import { getMap, formatDate, bindSearch, formatTreeData, flattenTree } from '@src/services/Tools';
|
|
|
import { asyncSMessage, asyncForm } from '@src/services/AsyncTools';
|
|
|
-import { Switch } from 'antd';
|
|
|
import { CommentChannel, SystemSelect } from '../../../../Constant';
|
|
|
import { System } from '../../../stores/system';
|
|
|
import { Course } from '../../../stores/course';
|
|
@@ -31,7 +32,16 @@ export default class extends Page {
|
|
|
key: 'switch',
|
|
|
name: '切换模式',
|
|
|
render: () => {
|
|
|
- return <Switch on />;
|
|
|
+ const { channel, position } = this.state.search;
|
|
|
+ let d = false;
|
|
|
+ if (channel === 'course-video' || channel === 'course-vs' || channel === 'course-package' || channel === 'course_data') {
|
|
|
+ d = !position;
|
|
|
+ } else {
|
|
|
+ d = !channel;
|
|
|
+ }
|
|
|
+ return <Switch disabled={d} checked={this.state.mode === 'order'} checkedChildren='排序模式' unCheckedChildren='列表模式' onChange={(value) => {
|
|
|
+ this.changeModel(value);
|
|
|
+ }} />;
|
|
|
},
|
|
|
}];
|
|
|
this.formF = null;
|
|
@@ -141,11 +151,10 @@ export default class extends Page {
|
|
|
},
|
|
|
}];
|
|
|
this.changeSearch(this.filterForm, this, this.state.search.channel, this.state.search.position);
|
|
|
- this.state.search.channel = this.state.search.channel ? this.state.search.channel.split('-') : '';
|
|
|
}
|
|
|
|
|
|
changeSearch(list, component, key, value, index = 1) {
|
|
|
- if (key === 'course-video' || key === 'course-vs' || key === 'course_data') {
|
|
|
+ if (key === 'course-video' || key === 'course-vs' || key === 'course-package' || key === 'course_data') {
|
|
|
bindSearch(list, 'position', component, (search) => {
|
|
|
if (key === 'course-video') {
|
|
|
return Course.list(Object.assign({ courseModule: 'video' }, search));
|
|
@@ -169,11 +178,31 @@ export default class extends Page {
|
|
|
}
|
|
|
|
|
|
initData() {
|
|
|
+ if (!this.state.search.order) {
|
|
|
+ this.state.search.order = '`order`';
|
|
|
+ this.state.search.direction = 'desc';
|
|
|
+ }
|
|
|
System.listComment(Object.assign({ isSpecial: true }, this.state.search)).then(result => {
|
|
|
this.setTableData(result.list, result.total);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ changeModel(value) {
|
|
|
+ const { search, page } = this.state;
|
|
|
+ if (value) {
|
|
|
+ search.size = page.total;
|
|
|
+ search.order = '`order`';
|
|
|
+ search.direction = 'desc';
|
|
|
+ this.setState({ mode: 'order', search });
|
|
|
+ } else {
|
|
|
+ search.size = 20;
|
|
|
+ search.order = null;
|
|
|
+ search.direction = null;
|
|
|
+ this.setState({ mode: null, search });
|
|
|
+ }
|
|
|
+ this.initData();
|
|
|
+ }
|
|
|
+
|
|
|
addAction() {
|
|
|
asyncForm('创建评价', this.itemList, {}, data => {
|
|
|
data.isShow = 1;
|
|
@@ -195,8 +224,9 @@ export default class extends Page {
|
|
|
if (row.userId) {
|
|
|
item = this.userItemList;
|
|
|
}
|
|
|
- row.channel = row.split('-');
|
|
|
- asyncForm('编辑', item, row, data => {
|
|
|
+ const info = Object.assign({}, row);
|
|
|
+ info.channel = info.channel.split('-');
|
|
|
+ asyncForm('编辑', item, info, data => {
|
|
|
data.channel = data.channel.join('-');
|
|
|
return System.editComment(data).then(() => {
|
|
|
asyncSMessage('编辑成功!');
|
|
@@ -215,13 +245,33 @@ export default class extends Page {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ order(oldIndex, newIndex) {
|
|
|
+ const { list } = this.state;
|
|
|
+ const tmp = list.splice(oldIndex, 1);
|
|
|
+ if (newIndex === list.length) {
|
|
|
+ list.push(tmp[0]);
|
|
|
+ } else {
|
|
|
+ list.splice(newIndex, 0, tmp[0]);
|
|
|
+ }
|
|
|
+ this.setState({ list });
|
|
|
+ }
|
|
|
+
|
|
|
+ submit() {
|
|
|
+ const { list } = this.state;
|
|
|
+ System.orderComment({ ids: list.map(row => row.id) }).then(() => {
|
|
|
+ asyncSMessage('操作成功!');
|
|
|
+ this.refresh();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
renderView() {
|
|
|
+ const { search } = this.state;
|
|
|
return <Block flex>
|
|
|
<FilterLayout
|
|
|
show
|
|
|
ref={(ref) => { this.filterF = ref; }}
|
|
|
itemList={this.filterForm}
|
|
|
- data={this.state.search}
|
|
|
+ data={Object.assign({}, search, { channel: search.channel ? search.channel.split('-') : '' })}
|
|
|
onChange={data => {
|
|
|
data.channel = data.channel.join('-');
|
|
|
this.search(data);
|
|
@@ -231,7 +281,7 @@ export default class extends Page {
|
|
|
selectedKeys={this.state.selectedKeys}
|
|
|
onAction={key => this.onAction(key)}
|
|
|
/>
|
|
|
- <TableLayout
|
|
|
+ {!this.state.mode && <TableLayout
|
|
|
columns={this.tableSort(this.columns)}
|
|
|
list={this.state.list}
|
|
|
pagination={this.state.page}
|
|
@@ -239,7 +289,32 @@ export default class extends Page {
|
|
|
onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
|
|
|
onSelect={(keys, rows) => this.tableSelect(keys, rows)}
|
|
|
selectedKeys={this.state.selectedKeys}
|
|
|
- />
|
|
|
+ />}
|
|
|
+ {this.state.mode === 'order' && <DragList
|
|
|
+ loading={this.props.core.loading}
|
|
|
+ dataSource={this.state.list || []}
|
|
|
+ handle={'.icon'}
|
|
|
+ rowKey={'id'}
|
|
|
+ onMove={(oldIndex, newIndex) => {
|
|
|
+ this.order(oldIndex, newIndex);
|
|
|
+ }}
|
|
|
+ renderItem={(item) => (
|
|
|
+ <List.Item actions={[<Icon type='bars' className='icon' />]}>
|
|
|
+ <Row style={{ width: '100%' }}>
|
|
|
+ <Col span={8}>昵称:{item.user ? item.user.nickname : item.nickname}</Col>
|
|
|
+ <Col span={15} offset={1}>评论:{item.content}</Col>
|
|
|
+ </Row>
|
|
|
+ </List.Item>
|
|
|
+ )}
|
|
|
+ />}
|
|
|
+ {this.state.mode === 'order' && <Row type="flex" justify="center">
|
|
|
+ <Col>
|
|
|
+ <Button type="primary" onClick={() => {
|
|
|
+ this.submit();
|
|
|
+ }}>保存</Button>
|
|
|
+ </Col>
|
|
|
+ </Row>}
|
|
|
+
|
|
|
</Block>;
|
|
|
}
|
|
|
}
|