import React from 'react'; 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 { getMap, formatDate, bindSearch, formatTreeData } from '@src/services/Tools'; import { asyncSMessage, asyncForm } from '@src/services/AsyncTools'; import { CommentChannel, SystemSelect } from '../../../../Constant'; import { System } from '../../../stores/system'; import { Course } from '../../../stores/course'; const CommentChannelMap = getMap(CommentChannel, 'value', 'label'); const SystemSelectMap = getMap(SystemSelect, 'value', 'label'); export default class extends Page { init() { this.actionList = [{ key: 'add', type: 'primary', name: '创建', }]; this.formF = null; this.itemList = [{ key: 'id', type: 'hidden', }, { key: 'channel', type: 'cascader', allowClear: true, name: '频道', select: formatTreeData(CommentChannel, 'value', 'label', 'parent'), 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); }, }, { title: '来源', dataIndex: 'isSystem', render: (text) => { return SystemSelectMap[text]; }, }, { title: '操作', dataIndex: 'handler', render: (text, record) => { return
; }, }]; 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') { 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)); } 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; } } initData() { System.listComment(Object.assign({ isSpecial: true }, this.state.search)).then(result => { this.setTableData(result.list, result.total); }); } addAction() { asyncForm('创建评价', this.itemList, {}, data => { data.isShow = 1; data.isSystem = 1; data.isSpecial = 1; return System.addComment(data).then(() => { asyncSMessage('添加成功!'); this.refresh(); }); }).then(component => { this.formF = component; }); } editAction(row) { let item = this.itemList; if (row.userId) { item = this.userItemList; } asyncForm('编辑', item, row, data => { return System.editComment(data).then(() => { asyncSMessage('编辑成功!'); this.refresh(); }); }).then(component => { this.formF = component; this.changeSearch(this.filterForm, this, row.channel, row.position, 2); }); } special(row, isShow) { System.editComment({ id: row.id, isShow }).then(() => { asyncSMessage('操作成功!'); this.refresh(); }); } renderView() { return