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, formatTreeData, flattenObject } from '@src/services/Tools'; import { asyncSMessage, asyncForm } from '@src/services/AsyncTools'; import { ServiceKey, ServiceParamMap, SwitchSelect } from '../../../../Constant'; import { Course } from '../../../stores/course'; import { Exercise } from '../../../stores/exercise'; const SwitchSelectMap = getMap(SwitchSelect, 'value', 'label'); export default class extends Page { constructor(props) { super(props); this.exerciseMap = {}; this.actionList = [{ key: 'add', type: 'primary', name: '创建', }]; this.itemList = [{ key: 'id', type: 'hidden', }, { key: 'title', type: 'input', name: '套餐名称', }, { key: 'structId', type: 'select', select: [], name: '套餐学科', }, { key: 'description', type: 'input', name: '套餐描述', }, { key: 'price', type: 'number', name: '套餐价格', min: 0, }, { key: 'courseIds', type: 'multiple', name: '包含课程', }]; ServiceKey.forEach((row) => { const list = ServiceParamMap[row.value]; const item = { key: `gift.${row.value}`, type: 'number', name: `送${row.label}`, }; if (list) { item.select = list; item.type = 'select'; item.allowClear = true; } this.itemList.push(item); }); this.columns = [{ title: '套餐名称', dataIndex: 'title', }, { title: '套餐学科', dataIndex: 'structId', render: (text) => { return this.exerciseMap[text]; }, }, { title: '套餐价格', dataIndex: 'price', }, { title: '销售数量', dataIndex: 'saleNumber', }, { title: '首页推荐', dataIndex: 'isSpecial', render: (text) => { return SwitchSelectMap[text] || text; }, }, { title: '上架', dataIndex: 'isShow', render: (text) => { return SwitchSelectMap[text] || text; }, }, { title: '操作', dataIndex: 'handler', render: (text, record) => { return
{( { this.editAction(record); }}>编辑 )} {!!record.isSpecial && ( { this.special(record, 0); }}>取消推荐 )} {!record.isSpecial && ( { this.special(record, 1); }}>首页推荐 )} {!record.isShow && ( { this.show(record, 1); }}>上架 )} {!!record.isShow && ( { this.show(record, 0); }}>下架 )}
; }, }]; } init() { Exercise.courseStruct().then((result) => { const list = result.filter(row => row.level === 1).map(row => { row.title = `${row.titleZh}`; row.value = row.id; return row; }); this.itemList[2].select = list; this.exerciseMap = getMap(list, 'id', 'title'); this.setState({ exercise: formatTreeData(list, 'id', 'title', 'parentId') }); }); Course.list({ excludeVs: true, excludeOnline: true }).then((result) => { this.itemList[5].select = result.list.map(row => { row.value = row.id; return row; }); }); } initData() { Course.listPackage(this.state.search).then(result => { this.setTableData(result.list, result.total); }); } detailAction(row) { this.setState({ detail: row }); } addAction() { asyncForm('创建', this.itemList, {}, data => { return Course.addPackage(data).then(() => { asyncSMessage('添加成功!'); this.refresh(); }); }); } editAction(row) { row = flattenObject(row); asyncForm('编辑', this.itemList, row, data => { return Course.editPackage(data).then(() => { asyncSMessage('编辑成功!'); this.refresh(); }); }); } special(row, isSpecial) { Course.editPackage({ id: row.id, isSpecial }).then(() => { asyncSMessage('编辑成功!'); this.refresh(); }); } show(row, isShow) { Course.editPackage({ id: row.id, isShow }).then(() => { asyncSMessage('编辑成功!'); this.refresh(); }); } renderView() { return {/* { 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} /> ; } }