day-bang.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import OSearch from '@/components/o-search'
  2. import OEmpty from '@/components/o-empty'
  3. import dayjs from 'dayjs'
  4. import {
  5. Icon,
  6. Popover,
  7. DatePicker,
  8. DatePickerColumnType,
  9. Popup,
  10. List,
  11. PullRefresh,
  12. ActionSheet,
  13. showToast,
  14. Sticky
  15. } from 'vant'
  16. import { defineComponent, reactive, ref, onMounted, watch, inject } from 'vue'
  17. import { useRouter } from 'vue-router'
  18. import styles from './timer-bang.module.less'
  19. import request from '@/helpers/request'
  20. import { state as globalState } from '@/state'
  21. import RankItem from '../modals/rank-item'
  22. import MyRankingItem from '../modals/my-ranking-item'
  23. export default defineComponent({
  24. props: ['toHeight'],
  25. emits: ['setTime'],
  26. name: 'day-bang',
  27. setup(props, { slots, attrs, emit }) {
  28. const router = useRouter()
  29. const state = reactive({
  30. showPopoverTime: false,
  31. showPopoverOrchestra: false,
  32. showPopoverSubject: false,
  33. actions: [] as any,
  34. subjects: [] as any,
  35. currentDate: [dayjs().format('YYYY'), dayjs().format('MM')]
  36. })
  37. const parentData = inject('parentData', { practiceMonth: '', timeName: '' } as any)
  38. const forms = reactive({
  39. practiceMonth: parentData.practiceMonth,
  40. page: 1,
  41. rows: 50,
  42. sortType: 'PRACTICE_DAY'
  43. })
  44. const minDate = ref(new Date(dayjs().subtract(10, 'year').format('YYYY-MM-DD')))
  45. const maxDate = ref(new Date(dayjs().add(10, 'year').format('YYYY-MM-DD')))
  46. const columnsType = ref<DatePickerColumnType[]>(['year', 'month'])
  47. const refreshing = ref(false)
  48. const loading = ref(false)
  49. const finished = ref(false)
  50. const showContact = ref(false)
  51. const list = ref([])
  52. const toTop = ref(props.toHeight)
  53. console.log(props.toHeight)
  54. watch(
  55. () => props.toHeight,
  56. (val: number) => {
  57. toTop.value = val
  58. }
  59. )
  60. watch(
  61. () => parentData.practiceMonth,
  62. (val) => {
  63. forms.practiceMonth = val
  64. refreshing.value = true
  65. getList()
  66. }
  67. )
  68. const getList = async () => {
  69. loading.value = true
  70. try {
  71. if (refreshing.value) {
  72. forms.page = 1
  73. list.value = []
  74. refreshing.value = false
  75. }
  76. const res = await request.post('/api-school/student/page', {
  77. data: { ...forms }
  78. })
  79. if (list.value.length > 0 && res.data.pages === 1) {
  80. return
  81. }
  82. forms.page = res.data.current + 1
  83. // list.value = list.value.concat(res.data.rows || [])
  84. list.value = res.data.rows
  85. showContact.value = list.value.length > 0
  86. console.log(showContact.value, ' showContact.value ')
  87. loading.value = false
  88. finished.value = true
  89. // finished.value = res.data.current >= res.data.pages
  90. } catch (e: any) {
  91. // console.log(e, 'e')
  92. const message = e.message
  93. showToast(message)
  94. showContact.value = false
  95. finished.value = true
  96. }
  97. }
  98. onMounted(() => {
  99. getList()
  100. })
  101. const onRefresh = () => {
  102. finished.value = false
  103. // 重新加载数据
  104. // 将 loading 设置为 true,表示处于加载状态
  105. loading.value = true
  106. getList()
  107. }
  108. return () => (
  109. <>
  110. {showContact.value ? (
  111. <div>
  112. <PullRefresh
  113. v-model={refreshing.value}
  114. onRefresh={onRefresh}
  115. style="min-height: 100vh;"
  116. >
  117. <List
  118. v-model:loading={loading.value}
  119. finished={finished.value}
  120. finished-text="没有更多了"
  121. onLoad={getList}
  122. >
  123. {list.value.map((item: any, index: number) => (
  124. <RankItem item={item} type="day" index={index + 1}></RankItem>
  125. ))}
  126. </List>
  127. </PullRefresh>
  128. <MyRankingItem item={list.value[0]}></MyRankingItem>
  129. </div>
  130. ) : (
  131. <OEmpty />
  132. )}
  133. </>
  134. )
  135. }
  136. })