123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- 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, asyncDelConfirm } from '@src/services/AsyncTools';
- import { CommentChannel, SystemSelect } from '../../../../Constant';
- import { System } from '../../../stores/system';
- import { Course } from '../../../stores/course';
- const CommentChannelTree = formatTreeData(CommentChannel, 'value', 'label', 'parent');
- const CommentChannelFlatten = flattenTree(CommentChannelTree, (row, item) => {
- row = Object.assign({}, row);
- row.value = `${item.value}-${row.value}`;
- row.label = `${item.label}-${row.label}`;
- return row;
- }, 'children');
- const CommentChannelMap = getMap(CommentChannelFlatten, 'value', 'label');
- const SystemSelectMap = getMap(SystemSelect, 'value', 'label');
- export default class extends Page {
- init() {
- this.actionList = [{
- key: 'add',
- type: 'primary',
- name: '创建',
- }, {
- key: 'switch',
- name: '切换模式',
- render: () => {
- 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;
- this.itemList = [{
- key: 'id',
- type: 'hidden',
- }, {
- key: 'channel',
- type: 'cascader',
- allowClear: true,
- name: '频道',
- select: CommentChannelTree,
- placeholder: '请选择',
- onChange: (value) => {
- this.changeSearch(this.itemList, this.formF, value.join('-'), null, 2);
- },
- }, {
- key: 'position',
- type: 'select',
- allowClear: true,
- name: '位置',
- select: [],
- placeholder: '请选择',
- }, {
- key: 'nickname',
- type: 'input',
- name: '学员昵称',
- }, {
- key: 'avatar',
- type: 'image',
- name: '学员头像',
- onUpload: ({ file }) => {
- return System.uploadImage(file).then(result => { return result; });
- },
- }, {
- key: 'content',
- type: 'textarea',
- name: '评价内容',
- }];
- this.userItemList = [{
- key: 'id',
- type: 'hidden',
- }, {
- key: 'content',
- type: 'textarea',
- name: '评价内容',
- }];
- this.filterF = null;
- this.filterForm = [{
- key: 'channel',
- type: 'cascader',
- allowClear: true,
- name: '频道',
- select: formatTreeData(CommentChannel, 'value', 'label', 'parent'),
- placeholder: '请选择',
- onChange: (value) => {
- this.changeSearch(this.filterForm, this, value.join('-'), null);
- },
- }, {
- key: 'position',
- type: 'select',
- allowClear: true,
- name: '位置',
- select: [],
- placeholder: '请选择',
- }, {
- key: 'isSystem',
- type: 'select',
- allowClear: true,
- number: true,
- name: '来源',
- select: SystemSelect,
- }];
- this.columns = [{
- title: '频道',
- dataIndex: 'channel',
- render: (text, record) => {
- return CommentChannelMap[record.channel];
- },
- }, {
- title: '商品名称',
- dataIndex: 'positionDetail.title',
- }, {
- title: '创建时间',
- sorter: true,
- dataIndex: 'createTime',
- render: (text) => {
- return formatDate(text, 'YYYY-MM-DD HH:mm:ss');
- },
- }, {
- title: '更新时间',
- sorter: true,
- dataIndex: 'updateTime',
- render: (text) => {
- return formatDate(text, 'YYYY-MM-DD HH:mm:ss');
- },
- }, {
- title: '来源',
- dataIndex: 'isSystem',
- render: (text) => {
- return SystemSelectMap[text];
- },
- }, {
- title: '操作',
- dataIndex: 'handler',
- render: (text, record) => {
- return <div className="table-button">
- {(
- <a onClick={() => {
- this.editAction(record);
- }}>编辑</a>
- )}
- {(
- <a onClick={() => {
- this.deleteAction(record);
- }}>删除</a>
- )}
- </div>;
- },
- }];
- this.changeSearch(this.filterForm, this, this.state.search.channel, this.state.search.position);
- }
- changeSearch(list, component, key, value, index = 1) {
- 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));
- } if (key === 'course-vs') {
- return Course.list(Object.assign({ courseModule: 'vs' }, search));
- } if (key === 'course-package') {
- return Course.listPackage(search);
- }
- return Course.listData(search);
- }, (row) => {
- return {
- title: row.title,
- value: row.id,
- };
- }, value ? Number(value) : null, null);
- list[index].disabled = false;
- } else {
- list[index].disabled = true;
- }
- component.setState({ load: false });
- }
- initData() {
- if (!this.state.search.order) {
- this.state.search.order = 'updateTime';
- 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 = 'sort';
- search.direction = 'desc';
- search.isSystem = null;
- this.setState({ mode: 'order', search });
- } else {
- search.size = 20;
- search.order = 'updateTime';
- search.direction = 'desc';
- this.setState({ mode: null, search });
- }
- this.initData();
- }
- addAction() {
- asyncForm('创建评价', this.itemList, {}, data => {
- data.isShow = 1;
- data.isSystem = 1;
- data.isSpecial = 1;
- data.channel = data.channel.join('-');
- return System.addComment(data).then(() => {
- asyncSMessage('添加成功!');
- this.refresh();
- });
- }).then(component => {
- this.formF = component;
- this.changeSearch(this.itemList, this.formF, null, null, 2);
- });
- }
- editAction(row) {
- let item = this.itemList;
- if (row.userId) {
- item = this.userItemList;
- }
- const info = Object.assign({}, row);
- info.channel = info.channel.split('-');
- asyncForm('编辑', item, info, data => {
- data.isShow = 1;
- data.isSystem = 1;
- data.isSpecial = 1;
- data.channel = data.channel.join('-');
- return System.editComment(data).then(() => {
- asyncSMessage('编辑成功!');
- this.refresh();
- });
- }).then(component => {
- this.formF = component;
- this.changeSearch(this.itemList, this.formF, row.channel, row.position, 2);
- });
- }
- deleteAction(row) {
- asyncDelConfirm('删除确认', '是否删除选中?', () => {
- const handler = System.delComment({ id: row.id });
- return handler.then(() => {
- asyncSMessage('删除成功!');
- this.refresh();
- });
- });
- }
- special(row, isShow) {
- System.editComment({ id: row.id, isShow }).then(() => {
- asyncSMessage('操作成功!');
- this.refresh();
- });
- }
- 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={Object.assign({}, search, { channel: search.channel ? search.channel.split('-') : '' })}
- onChange={data => {
- data.channel = data.channel ? data.channel.join('-') : data.channel;
- data.page = 1;
- this.search(data);
- }} />
- <ActionLayout
- itemList={this.actionList}
- selectedKeys={this.state.selectedKeys}
- onAction={key => this.onAction(key)}
- />
- {!this.state.mode && <TableLayout
- columns={this.tableSort(this.columns)}
- list={this.state.list}
- pagination={this.state.page}
- loading={this.props.core.loading}
- 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>;
- }
- }
|