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 } from '@src/services/AsyncTools'; import { FaqChannel, SystemSelect } from '../../../../Constant'; import { System } from '../../../stores/system'; import { Course } from '../../../stores/course'; const SystemSelectMap = getMap(SystemSelect, '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: '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 { this.changeModel(value); }} />; }, }]; this.formF = null; this.itemList = [{ key: 'id', type: 'hidden', }, { key: 'channel', type: 'cascader', name: '频道', select: FaqChannelTree, placeholder: '请选择', onChange: (value) => { this.changeSearch(this.itemList, this.formF, value.join('-'), null, 2); }, }, { key: 'position', type: 'select', name: '位置', select: [], placeholder: '请选择', }, { key: 'content', type: 'textarea', name: '用户留言', }, { key: 'answer', type: 'textarea', name: '编辑回复', }]; this.filterF = null; this.filterForm = [{ key: 'channel', type: 'cascader', allowClear: true, name: '频道', select: formatTreeData(FaqChannel, 'value', 'label', 'parent'), placeholder: '请选择', onChange: (value) => { this.changeSearch(this.filterForm, this, value.join('-'), null); }, }, { key: 'position', type: 'select', allowClear: true, name: '位置', number: true, select: [], placeholder: '请选择', }, { key: 'isSystem', type: 'select', allowClear: true, number: true, name: '来源', select: SystemSelect, }]; 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: 'isSystem', render: (text) => { return SystemSelectMap[text]; }, }, { title: '操作', dataIndex: 'handler', render: (text, record) => { return
{( { this.editAction(record); }}>编辑 )}
; }, }]; 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 = 'sort'; this.state.search.direction = 'desc'; } System.listFAQ(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.order = 'sort'; search.direction = 'desc'; search.size = page.total; search.isSystem = null; this.setState({ mode: 'order', search }); } else { search.size = 20; search.order = null; search.direction = null; 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.addFAQ(data).then(() => { asyncSMessage('添加成功!'); this.refresh(); }); }).then(component => { this.formF = component; this.changeSearch(this.itemList, this.formF, null, null, 2); }); } editAction(row) { const info = Object.assign({}, row); info.channel = info.channel.split('-'); asyncForm('编辑', this.itemList, info, data => { data.isShow = 1; data.isSystem = 1; data.isSpecial = 1; data.channel = data.channel.join('-'); return System.editFAQ(data).then(() => { asyncSMessage('编辑成功!'); this.refresh(); }); }).then(component => { this.formF = component; this.changeSearch(this.itemList, this.formF, row.channel, row.position, 2); }); } show(row, isShow) { System.editFAQ({ 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.orderFAQ({ ids: list.map(row => row.id) }).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.state.mode && this.tableChange(pagination, filters, sorter)} onSelect={(keys, rows) => this.tableSelect(keys, rows)} selectedKeys={this.state.selectedKeys} />} {this.state.mode === 'order' && { this.order(oldIndex, newIndex); }} renderItem={(item) => ( ]}> Q: {item.content} A: {item.answer} )} />} {this.state.mode === 'order' && } ; } }