| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- import OHeader from '@/components/o-header'
- import OSticky from '@/components/o-sticky'
- import request from '@/helpers/request'
- import { ActionSheet, Cell, Icon, List, Popover, Tag } from 'vant'
- import { defineComponent, onMounted, onUnmounted, reactive } from 'vue'
- import { useRouter } from 'vue-router'
- import styles from './index.module.less'
- import { postMessage } from '@/helpers/native-message'
- import { state } from '@/state'
- import OEmpty from '@/components/o-empty'
- import { orchestraType } from '@/constant'
- import OFullRefresh from '@/components/o-full-refresh'
- import OActionSheet from '@/components/o-action-sheet'
- export default defineComponent({
- name: 'my-orchestra',
- setup() {
- const router = useRouter()
- const form = reactive({
- showPopover: false,
- actions: [
- { name: '全部乐团', selected: true, value: 'ALL' },
- { name: '交付团', value: 'DELIVERY' },
- { name: '晋升团', value: 'PROMOTION' }
- ],
- isClick: false,
- list: [] as any,
- listState: {
- dataShow: true, // 判断是否有数据
- loading: false,
- finished: false,
- refreshing: false,
- height: 0 // 页面头部高度,为了处理下拉刷新用的
- },
- params: {
- type: null,
- status: 'DONE',
- page: 1,
- rows: 20
- }
- })
- const formatType = (type: any) => {
- const template = {
- DELIVERY: '交付团',
- PROMOTION: '晋升团'
- }
- return template[type] || '全部乐团'
- }
- const onSelect = (val: any) => {
- form.actions.forEach((child: any) => {
- child.selected = false
- })
- val.selected = true
- form.params.type = val.value === 'ALL' ? null : val.value
- form.showPopover = false
- form.params.page = 1
- form.list = []
- form.listState.dataShow = true // 判断是否有数据
- form.listState.loading = false
- form.listState.finished = false
- getList()
- }
- const getList = async () => {
- try {
- if (form.isClick) return
- form.isClick = true
- const res = await request.post('/api-school/orchestra/page', {
- data: {
- ...form.params,
- schoolId: state.user.data.school.id
- }
- })
- form.listState.loading = false
- form.listState.refreshing = false
- const result = res.data || {}
- // 处理重复请求数据
- if (form.list.length > 0 && result.current === 1) {
- return
- }
- form.list = form.list.concat(result.rows || [])
- form.listState.finished = result.current >= result.pages
- form.params.page = result.current + 1
- form.listState.dataShow = form.list.length > 0
- form.isClick = false
- } catch {
- form.listState.dataShow = false
- form.listState.finished = true
- form.listState.refreshing = false
- form.isClick = false
- }
- }
- const onDetail = (item: any) => {
- console.log(item)
- router.push({
- path: '/orchestra-detail',
- query: {
- id: item.id
- }
- })
- }
- const onRefresh = () => {
- form.params.page = 1
- form.list = []
- form.listState.dataShow = true // 判断是否有数据
- form.listState.loading = false
- form.listState.finished = false
- getList()
- }
- onMounted(() => {
- getList()
- // 处理返回上一页的问题
- window.history.pushState(null, '', document.URL)
- window.addEventListener('popstate', onBack, false)
- })
- const onBack = () => {
- postMessage({ api: 'back' })
- }
- onUnmounted(() => {
- window.removeEventListener('popstate', onBack)
- })
- return () => (
- <div class={!form.listState.dataShow && 'emptyRootContainer'}>
- <OSticky
- position="top"
- onGetHeight={(height: any) => {
- form.listState.height = height
- }}
- >
- <OHeader>
- {{
- right: () => (
- <Icon
- name="plus"
- size={19}
- color="#333"
- onClick={() => {
- router.push('/create-orchestra')
- }}
- />
- )
- }}
- </OHeader>
- <div class="searchGroup-single">
- <span
- onClick={() => (form.showPopover = true)}
- class={['searchItem', form.showPopover ? 'searchItem-active' : '']}
- >
- {formatType(form.params.type)}
- </span>
- </div>
- </OSticky>
- {form.listState.dataShow ? (
- <OFullRefresh
- v-model:modelValue={form.listState.refreshing}
- onRefresh={onRefresh}
- style={{
- minHeight: `calc(100vh - ${form.listState.height}px)`
- }}
- >
- <List
- // v-model:loading={form.listState.loading}
- finished={form.listState.finished}
- finishedText=" "
- class={[styles.liveList]}
- onLoad={getList}
- immediateCheck={false}
- >
- {form.list.map((item: any) => (
- <Cell isLink center class={styles.oCell} onClick={() => onDetail(item)}>
- {{
- title: () => (
- <div class={styles.oTitle}>
- <div>{item.name}</div>
- <Tag
- style={{ marginLeft: '6px', flexShrink: 0 }}
- color={item.type === 'DELIVERY' ? '#FF8057' : '#64A9FF'}
- >
- {orchestraType[item.type]}
- </Tag>
- </div>
- ),
- label: () => <p>学员人数:{item.currentStudentNum || 0}人</p>
- }}
- </Cell>
- ))}
- </List>
- </OFullRefresh>
- ) : (
- <OEmpty btnStatus={false} tips="暂无乐团" />
- )}
- <OActionSheet v-model:show={form.showPopover} actions={form.actions} onSelect={onSelect} />
- </div>
- )
- }
- })
|