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 ( this.setState({ filter: isOpen })} >
{ this.changeStruct(null); this.getList(value.key, 1); }} tabs={[{ title: '单次', key: 'video' }, { title: '套餐', key: 'package' }]} />
this.setState({ filter: true })}> 筛选
{this.renderList()}
); } renderRow(rowData) { const { tab } = this.state; switch (tab) { case 'video': return ; case 'package': return ; default: return
; } } renderList() { const { listMap, tab } = this.state; const data = listMap[tab]; if (!data) return
; const { dataSource = {}, bottom, loading, finish, maxSectionId = 1, total } = data; if (total === 0) return this.renderEmpty(); return ( { this.lv = el; }} dataSource={dataSource} renderFooter={() => (
{loading ? '加载中...' : bottom ? '没有更多了' : ''}
)} renderRow={(rowData, sectionID, rowID) => this.renderRow(rowData, sectionID, rowID)} style={{ height: this.state.height, overflow: 'auto', }} pageSize={this.state.search.size} scrollRenderAheadDistance={500} onEndReached={() => { if (loading) return; if (bottom) { if (!finish) { data.finish = true; // this.setState({ time: new Date() }) } return; } this.getList(tab, maxSectionId + 1); }} onEndReachedThreshold={10} /> ); } renderEmpty() { return
; } renderFilter() { const { search, videoTree = [], packageTree = [], tab } = this.state; return (
筛选学科
{(tab === 'package' ? packageTree : videoTree).map(row => { return (
0 ? 'label' : 'label left'}>{row.title}
{row.children.length > 0 && (
{ this.changeStruct(value); }} />
)} {row.children.length === 0 && (
{ this.changeStruct(row.id); }} />
)}
); })}
); } }