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 } from '@src/services/Tools'; import { asyncSMessage, asyncForm } from '@src/services/AsyncTools'; import { ChannelModule, SwitchSelect, AskStatus } from '../../../../Constant'; import { System } from '../../../stores/system'; const SwitchSelectMap = getMap(SwitchSelect, 'value', 'label'); const ChannelModuleMap = getMap(ChannelModule, 'value', 'label'); const AskStatusMap = getMap(AskStatus, 'value', 'label'); export default class extends Page { init() { this.formF = null; this.itemList = [{ key: 'id', type: 'hidden', }, { key: 'channel', type: 'select', allowClear: true, name: '频道', select: ChannelModule, placeholder: '请选择', }, { key: 'position', type: 'select', allowClear: true, name: '位置', select: ChannelModule, placeholder: '请选择', }, { key: 'content', type: 'textarea', name: '用户留言', }, { key: 'answer', type: 'textarea', name: '编辑回复', }]; this.answerList = [{ key: 'id', type: 'hidden', }, { key: 'content', type: 'textarea', disabled: true, name: '用户留言', }, { key: 'answer', type: 'textarea', name: '编辑回复', }]; this.filterForm = [{ key: 'channel', type: 'select', allowClear: true, name: '频道', select: ChannelModule, placeholder: '请选择', }, { key: 'position', type: 'select', allowClear: true, name: '位置', select: ChannelModule, placeholder: '请选择', }, { key: 'answerStatus', type: 'select', allowClear: true, number: true, name: '状态', select: AskStatus, }, { key: 'isSpecial', type: 'select', allowClear: true, name: '精选', number: true, select: SwitchSelect, }]; this.columns = [{ title: '频道', dataIndex: 'channel', render: (text, record) => { return ChannelModuleMap[record.channel]; }, }, { title: '位置', dataIndex: 'position', }, { title: '提问时间', dataIndex: 'createTime', render: (text) => { return formatDate(text); }, }, { title: '提问者', dataIndex: 'user', render: (text, record) => { if (record.isSystem) return '系统创建'; if (!record.userId) return '未注册'; return text ? text.nickname : ''; }, }, { title: '问题摘要', dataIndex: 'content', }, { title: '回答状态', dataIndex: 'answerStatus', render: (text) => { return AskStatusMap[text] || ''; }, }, { title: '精选', dataIndex: 'isSpecial', render: (text, record) => { return record.status > 0 ? SwitchSelectMap[text] || text : '-'; }, }, { title: '操作', dataIndex: 'handler', render: (text, record) => { return
{( { this.editAction(record); }}>编辑 )} {!record.isSystem && record.status === 0 && ( { this.answerAction(record); }}>回复 )} {!!record.isSpecial && ( { this.special(record, 0); }}>取消精选 )} {!record.isSpecial && ( { this.special(record, 1); }}>精选 )}
; }, }]; } initData() { System.listFAQ(Object.assign({ user: true }, this.state.search)).then(result => { this.setTableData(result.list, result.total); }); } addAction() { asyncForm('创建', this.itemList, {}, data => { return System.addFAQ(data).then(() => { asyncSMessage('添加成功!'); this.refresh(); }); }).then(component => { this.formF = component; }); } editAction(row) { asyncForm('编辑', this.itemList, row, data => { return System.editFAQ(data).then(() => { asyncSMessage('编辑成功!'); this.refresh(); }); }).then(component => { this.formF = component; }); } answerAction(row) { asyncForm('回复', this.answerList, row, data => { data.sendUser = true; return System.editFAQ(data).then(() => { asyncSMessage('回复成功!'); this.refresh(); }); }).then(component => { this.formF = component; }); } special(row, isSpecial) { System.editFAQ({ id: row.id, isSpecial }).then(() => { asyncSMessage('编辑成功!'); this.refresh(); }); } renderView() { return { this.search(data); }} /> this.onAction(key)} /> this.tableChange(pagination, filters, sorter)} onSelect={(keys, rows) => this.tableSelect(keys, rows)} selectedKeys={this.state.selectedKeys} /> ; } }