day-bang.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. const myInfo = ref({} as any)
  54. console.log(props.toHeight)
  55. watch(
  56. () => props.toHeight,
  57. (val: number) => {
  58. toTop.value = val
  59. }
  60. )
  61. watch(
  62. () => parentData.practiceMonth,
  63. (val) => {
  64. forms.practiceMonth = val
  65. refreshing.value = true
  66. getList()
  67. }
  68. )
  69. const getList = async () => {
  70. loading.value = true
  71. try {
  72. if (refreshing.value) {
  73. forms.page = 1
  74. list.value = []
  75. refreshing.value = false
  76. }
  77. const res = await request.post('/api-student/student/page', {
  78. data: { ...forms }
  79. })
  80. if (list.value.length > 0 && res.data.pages === 1) {
  81. return
  82. }
  83. forms.page = res.data.current + 1
  84. // list.value = list.value.concat(res.data.rows || [])
  85. list.value = res.data.rows
  86. showContact.value = list.value.length > 0
  87. console.log(showContact.value, ' showContact.value ')
  88. loading.value = false
  89. finished.value = true
  90. myInfo.value = res.data.extra
  91. // finished.value = res.data.current >= res.data.pages
  92. } catch (e: any) {
  93. // console.log(e, 'e')
  94. const message = e.message
  95. showToast(message)
  96. showContact.value = false
  97. finished.value = true
  98. }
  99. }
  100. onMounted(() => {
  101. getList()
  102. })
  103. const onRefresh = () => {
  104. finished.value = false
  105. // 重新加载数据
  106. // 将 loading 设置为 true,表示处于加载状态
  107. loading.value = true
  108. getList()
  109. }
  110. return () => (
  111. <>
  112. {showContact.value ? (
  113. <div>
  114. <PullRefresh
  115. v-model={refreshing.value}
  116. onRefresh={onRefresh}
  117. style="min-height: 100vh;"
  118. >
  119. <List
  120. v-model:loading={loading.value}
  121. finished={finished.value}
  122. finished-text="没有更多了"
  123. onLoad={getList}
  124. >
  125. {list.value.map((item: any, index: number) => (
  126. <RankItem item={item} type="day" index={index + 1}></RankItem>
  127. ))}
  128. </List>
  129. </PullRefresh>
  130. <MyRankingItem item={myInfo.value}></MyRankingItem>
  131. </div>
  132. ) : (
  133. <OEmpty />
  134. )}
  135. </>
  136. )
  137. }
  138. })