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, formatTreeData, bindSearch, flattenTree } from '@src/services/Tools'; import { asyncSMessage, asyncForm, asyncDelConfirm } from '@src/services/AsyncTools'; import { FaqChannel, SwitchSelect, AnswerStatus, MoneyRange } from '../../../../Constant'; import { System } from '../../../stores/system'; import { User } from '../../../stores/user'; import { Course } from '../../../stores/course'; const SwitchSelectMap = getMap(SwitchSelect, 'value', 'label'); const AnswerStatusMap = getMap(AnswerStatus, 'value', 'label'); const FaqChannelTree = formatTreeData(FaqChannel, 'value', 'label', 'parent'); const FaqChannelFlatten = flattenTree(FaqChannelTree, (row, item) => { row = Object.assign({}, row); row.value = `${item.value}-${row.value}`; row.label = `${item.label}-${row.label}`; return row; }, 'children'); const FaqChannelMap = getMap(FaqChannelFlatten, 'value', 'label'); export default class extends Page { init() { this.actionList = [{ key: 'ignore', type: 'danger', name: '批量忽略', needSelect: 1, }]; this.formF = null; this.itemList = [{ key: 'id', type: 'hidden', }, { 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.filterF = null; this.filterForm = [{ key: 'channel', type: 'cascader', allowClear: true, name: '频道', select: FaqChannelTree, placeholder: '请选择', onChange: (value) => { this.changeSearch(this.filterForm, this, value.join('-'), null); }, }, { key: 'position', type: 'select', allowClear: true, name: '位置', select: [], number: true, placeholder: '请选择', }, { key: 'answerStatus', type: 'select', allowClear: true, number: true, name: '状态', select: AnswerStatus, }, { key: 'userId', type: 'select', allowClear: true, name: '用户', select: [], number: true, placeholder: '请输入', }, { key: 'moneyRang', type: 'select', allowClear: true, name: '消费金额', select: MoneyRange, number: true, }, { key: 'isSpecial', type: 'select', allowClear: true, name: '展示', number: true, select: SwitchSelect, }]; this.columns = [{ title: '频道', dataIndex: 'channel', render: (text, record) => { return FaqChannelMap[record.channel]; }, }, { title: '位置', dataIndex: 'positionDetail.title', }, { title: '提问时间', sorter: true, dataIndex: 'createTime', render: (text) => { return formatDate(text, 'YYYY-MM-DD HH:mm:ss'); }, }, { title: '提问者', dataIndex: 'user.nickname', }, { title: '消费金额', dataIndex: 'user.totalMoney', }, { title: '回答状态', dataIndex: 'answerStatus', render: (text) => { return AnswerStatusMap[text] || ''; }, }, { title: '回答时间', sorter: true, dataIndex: 'answerTime', render: (text) => { return text ? formatDate(text, 'YYYY-MM-DD HH:mm:ss') : ''; }, }, { title: '展示', dataIndex: 'isSpecial', render: (text) => { return SwitchSelectMap[text] || text; }, }, { title: '操作', dataIndex: 'handler', render: (text, record) => { return
{record.answerStatus === 0 && ( { this.answerAction(record); }}>回复 )} {!!record.isSpecial && ( { this.special(record, 0); }}>取消展示 )} {!record.isSpecial && ( { this.special(record, 1); }}>展示 )}
; }, }]; bindSearch(this.filterForm, 'userId', this, (search) => { return User.list(search); }, (row) => { return { title: `${row.nickname}(${row.mobile})`, value: row.id, }; }, this.state.search.userId ? Number(this.state.search.userId) : null, null); this.changeSearch(this.filterForm, this, this.state.search.channel, this.state.search.position); } changeSearch(list, component, key, value) { 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[1].disabled = false; } else { list[1].disabled = true; } component.setState({ load: false }); } initData() { System.listFAQ(Object.assign({ user: true }, this.state.search)).then(result => { this.setTableData(result.list, result.total); }); } 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.status = 1; return System.editFAQ(data).then(() => { asyncSMessage('回复成功!'); this.refresh(); }); }).then(component => { this.formF = component; }); } special(row, isSpecial) { System.editFAQ({ id: row.id, isSpecial, isShow: isSpecial }).then(() => { asyncSMessage('编辑成功!'); this.refresh(); }); } ignoreAction() { const { selectedKeys } = this.state; asyncDelConfirm('忽略确认', '是否忽略选中记录?', () => { return Promise.all(selectedKeys.map(row => System.editFAQ({ id: row, status: 2 }))).then(() => { asyncSMessage('操作成功!'); this.refresh(); }); }); } renderView() { const { search } = this.state; return { 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); }} /> this.onAction(key)} /> this.tableChange(pagination, filters, sorter)} onSelect={(keys, rows) => this.tableSelect(keys, rows)} selectedKeys={this.state.selectedKeys} /> ; } }