import React from 'react';
import './index.less';
import { Drawer, Tabs, ListView } from 'antd-mobile';
import Page from '@src/containers/Page';
import Assets from '@src/components/Assets';
import { formatTreeData, getMap } from '@src/services/Tools';
import ListData from '@src/services/ListData';
import { CourseBlock, CoursePackageBlock } from '../../../components/Block';
import { SpecialRadioGroup } from '../../../components/Radio';
import Button from '../../../components/Button';
import Checkbox from '../../../components/CheckBox';
import { Course } from '../../../stores/course';
import { Main } from '../../../stores/main';
export default class extends Page {
initState() {
return {
listMap: {},
};
}
init() {
Main.dataStruct().then(list => {
list = list.map(row => {
row.title = `${row.titleZh} ${row.titleEn}`;
row.label = row.title;
row.key = row.id;
return row;
});
const structMap = getMap(list, 'id');
const videoTree = formatTreeData(list, 'id', 'title', 'parentId');
const packageTree = formatTreeData(list.filter(row => row.level === 1), 'id', 'title', 'parentId');
this.setState({ videoTree, packageTree, structMap });
});
const { search } = this.state;
if (!search.order) search.order = 'saleNumber';
this.setState({ search, tab: 'video' });
}
initData() {
return this.initListKeys(['video', 'package']).then(() => {
return this.getList('video', 1);
});
}
initListKeys(keys) {
const { listMap } = this.state;
keys.forEach(key => {
listMap[key] = new ListData();
});
this.setState({ listMap });
return Promise.resolve();
}
getList(key, page) {
this.setState({ tab: key });
let handler;
switch (key) {
case 'video':
handler = Course.listVideo(Object.assign({ page }, this.state.search));
break;
case 'package':
handler = Course.listPackage(Object.assign({ page }, this.state.search)).then(result => {
const { structMap } = this.state;
result.list = result.list.map(row => {
row.tag = (structMap[row.structId] || {}).title;
return row;
});
return result;
});
break;
default:
return;
}
handler.then(result => {
const { listMap } = this.state;
if (page === 1) {
// todo 是否重新读取第一页为刷新所有数据
listMap[key] = new ListData();
}
listMap[key].get(page, result, this.state.search.size);
this.setState({ listMap, tab: key });
});
}
changeStruct(value) {
const { search = {} } = this.state;
search.structId = value;
this.setState({ search });
}
renderView() {
const { filter } = this.state;
return (