index.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import OHeader from '@/components/o-header'
  2. import OSticky from '@/components/o-sticky'
  3. import request from '@/helpers/request'
  4. import { Cell, Icon, List, Popover, Tag } from 'vant'
  5. import { defineComponent, onMounted, reactive } from 'vue'
  6. import { useRouter } from 'vue-router'
  7. import styles from './index.module.less'
  8. import { state } from '@/state'
  9. import OEmpty from '@/components/o-empty'
  10. import { orchestraType } from '@/constant'
  11. export default defineComponent({
  12. name: 'my-orchestra',
  13. setup() {
  14. const router = useRouter()
  15. const form = reactive({
  16. showPopover: false,
  17. actions: [
  18. { text: '全部乐团', color: 'var(--van-primary-color)', value: 'ALL' },
  19. { text: '交付团', value: 'DELIVERY' },
  20. { text: '晋升团', value: 'PROMOTION' }
  21. ],
  22. list: [] as any,
  23. listState: {
  24. dataShow: true, // 判断是否有数据
  25. loading: false,
  26. finished: false
  27. },
  28. params: {
  29. type: null,
  30. page: 1,
  31. rows: 20
  32. }
  33. })
  34. const onSelect = (val: any) => {
  35. form.actions.forEach((item: any) => {
  36. item.color = null
  37. })
  38. val.color = 'var(--van-primary-color)'
  39. form.params.type = val.value === 'ALL' ? null : val.value
  40. form.params.page = 1
  41. form.list = []
  42. form.listState.dataShow = true // 判断是否有数据
  43. form.listState.loading = false
  44. form.listState.finished = false
  45. getList()
  46. }
  47. const getList = async () => {
  48. try {
  49. const res = await request.post('/api-school/orchestra/page', {
  50. data: {
  51. ...form.params,
  52. schoolId: state.user.data.school.id
  53. }
  54. })
  55. form.listState.loading = false
  56. const result = res.data || {}
  57. // 处理重复请求数据
  58. if (form.list.length > 0 && result.current === 1) {
  59. return
  60. }
  61. form.list = form.list.concat(result.rows || [])
  62. form.listState.finished = result.current >= result.pages
  63. form.params.page = result.current + 1
  64. form.listState.dataShow = form.list.length > 0
  65. } catch {
  66. form.listState.dataShow = false
  67. form.listState.finished = true
  68. }
  69. }
  70. const onDetail = (item: any) => {
  71. console.log(item)
  72. router.push({
  73. path: '/orchestra-detail',
  74. query: {
  75. id: item.id
  76. }
  77. })
  78. }
  79. onMounted(() => {
  80. getList()
  81. })
  82. return () => (
  83. <>
  84. <OSticky position="top">
  85. <OHeader>
  86. {{
  87. right: () => (
  88. <Icon
  89. name="plus"
  90. size={19}
  91. color="#333"
  92. onClick={() => {
  93. router.push('/create-orchestra')
  94. }}
  95. />
  96. )
  97. }}
  98. </OHeader>
  99. <div style={{ padding: '12px 13px', background: '#F8F8F8' }}>
  100. <Popover
  101. v-model:show={form.showPopover}
  102. actions={form.actions}
  103. showArrow={false}
  104. placement="bottom-start"
  105. onSelect={onSelect}
  106. offset={[0, 12]}
  107. >
  108. {{
  109. reference: () => (
  110. <div class={styles.searchBand}>
  111. 全部乐团 <Icon name={form.showPopover ? 'arrow-up' : 'arrow-down'} />
  112. </div>
  113. )
  114. }}
  115. </Popover>
  116. </div>
  117. </OSticky>
  118. {form.listState.dataShow ? (
  119. <List
  120. v-model:loading={form.listState.loading}
  121. finished={form.listState.finished}
  122. finishedText=" "
  123. class={[styles.liveList]}
  124. onLoad={getList}
  125. immediateCheck={false}
  126. >
  127. {form.list.map((item: any) => (
  128. <Cell isLink center class={styles.oCell} onClick={() => onDetail(item)}>
  129. {{
  130. title: () => (
  131. <div class={styles.oTitle}>
  132. {item.name}
  133. <Tag
  134. style={{ marginLeft: '6px' }}
  135. color={item.type === 'DELIVERY' ? '#FF8057' : '#64A9FF'}
  136. >
  137. {orchestraType[item.type]}
  138. </Tag>
  139. </div>
  140. ),
  141. label: () => <p>学生人数:{item.currentStudentNum}人</p>
  142. }}
  143. </Cell>
  144. ))}
  145. </List>
  146. ) : (
  147. <OEmpty btnStatus={false} classImgSize="SMALL" tips="暂无乐团" />
  148. )}
  149. </>
  150. )
  151. }
  152. })