123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- 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, bindSearch, formatDate } from '@src/services/Tools';
- import { asyncSMessage, asyncForm } from '@src/services/AsyncTools';
- import { ChannelModule, SwitchSelect, AskStatus } from '../../../../Constant';
- import { System } from '../../../stores/system';
- import { User } from '../../../stores/user';
- 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.actionList = [{
- key: 'add',
- type: 'primary',
- name: '创建',
- }];
- 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',
- name: '用户留言',
- }, {
- key: 'answer',
- type: 'textarea',
- name: '编辑回复',
- }, {
- key: 'isSpecial',
- type: 'switch',
- name: '是否精选',
- select: SwitchSelect,
- }, {
- key: 'sendMail',
- type: 'switch',
- name: '发送邮件',
- select: SwitchSelect,
- }];
- this.filterForm = [{
- key: 'channel',
- type: 'select',
- allowClear: true,
- name: '频道',
- select: ChannelModule,
- placeholder: '请选择',
- }, {
- key: 'position',
- type: 'select',
- allowClear: true,
- name: '位置',
- select: ChannelModule,
- placeholder: '请选择',
- }, {
- key: 'userId',
- type: 'select',
- allowClear: true,
- name: '用户',
- select: [],
- number: true,
- placeholder: '请输入',
- }, {
- key: 'status',
- 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: 'status',
- 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 <div className="table-button">
- {!!record.isSystem && (
- <a onClick={() => {
- this.editAction(record);
- }}>编辑</a>
- )}
- {!record.isSystem && record.status === 0 && (
- <a onClick={() => {
- this.answerAction(record);
- }}>回复</a>
- )}
- {!!record.isSpecial && (
- <a onClick={() => {
- this.special(record, 0);
- }}>取消精选</a>
- )}
- {!record.isSpecial && (
- <a onClick={() => {
- this.special(record, 1);
- }}>精选</a>
- )}
- </div>;
- },
- },
- ];
- 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);
- }
- initData() {
- System.listFAQ(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.isSpecial = data.isSpecial ? 1 : 0;
- data.sendMail = data.sendMail ? 1 : 0;
- 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 <Block flex>
- <FilterLayout
- show
- itemList={this.filterForm}
- data={this.state.search}
- onChange={data => {
- this.search(data);
- }} />
- <ActionLayout
- itemList={this.actionList}
- selectedKeys={this.state.selectedKeys}
- onAction={key => this.onAction(key)}
- />
- <TableLayout
- select
- columns={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}
- />
- </Block>;
- }
- }
|