123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- 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 <div className="table-button">
- {(
- <a onClick={() => {
- this.editAction(record);
- }}>编辑</a>
- )}
- {!!record.isSpecial && (
- <a onClick={() => {
- this.special(record, 0);
- }}>取消推荐</a>
- )}
- {!record.isSpecial && (
- <a onClick={() => {
- this.special(record, 1);
- }}>首页推荐</a>
- )}
- {!record.isShow && (
- <a onClick={() => {
- this.show(record, 1);
- }}>上架</a>
- )}
- {!!record.isShow && (
- <a onClick={() => {
- this.show(record, 0);
- }}>下架</a>
- )}
- </div>;
- },
- }];
- }
- 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 <Block flex>
- {/* <FilterLayout
- show
- itemList={this.filterForm}
- data={this.state.search}
- onChange={data => {
- data.page = 1;
- this.search(data);
- }} /> */}
- <ActionLayout
- itemList={this.actionList}
- selectedKeys={this.state.selectedKeys}
- onAction={key => this.onAction(key)}
- />
- <TableLayout
- columns={this.tableSort(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>;
- }
- }
|