timer-bang.tsx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. Picker
  16. } from 'vant'
  17. import OFullRefresh from '@/components/o-full-refresh'
  18. import { defineComponent, reactive, ref, onMounted, watch } from 'vue'
  19. import { useRouter } from 'vue-router'
  20. import styles from './timer-bang.module.less'
  21. import request from '@/helpers/request'
  22. import RankItem from '../modals/rank-item'
  23. export default defineComponent({
  24. name: 'timer-bang',
  25. props: ['toHeight', 'startTime', 'endTime'],
  26. setup(props) {
  27. const state = reactive({
  28. showPopoverTime: false,
  29. showPopoverOrchestra: false,
  30. showPopoverSubject: false,
  31. actions: [] as any,
  32. subjects: [] as any,
  33. currentDate: [dayjs().format('YYYY'), dayjs().format('MM')]
  34. })
  35. const forms = reactive({
  36. practiceMonth: props.startTime,
  37. orchestraId: '',
  38. orchestraName: '全部乐团',
  39. subjectId: '',
  40. subjectName: '全部声部',
  41. page: 1,
  42. rows: 50,
  43. sortType: 'PRACTICE_TIMES'
  44. })
  45. const refreshing = ref(false)
  46. const loading = ref(false)
  47. const finished = ref(false)
  48. const showContact = ref(false)
  49. const list = ref([])
  50. const toTop = ref(props.toHeight)
  51. watch(
  52. () => props.toHeight,
  53. (val: number) => {
  54. toTop.value = val
  55. console.log(toTop.value)
  56. }
  57. )
  58. watch(
  59. () => props.startTime,
  60. () => {
  61. forms.practiceMonth = props.startTime
  62. refreshing.value = true
  63. getList()
  64. }
  65. )
  66. const getList = async () => {
  67. loading.value = true
  68. try {
  69. if (refreshing.value) {
  70. forms.page = 1
  71. list.value = []
  72. refreshing.value = false
  73. }
  74. const res = await request.post('/api-school/student/page', {
  75. data: { ...forms }
  76. })
  77. if (list.value.length > 0 && res.data.pages === 1) {
  78. return
  79. }
  80. forms.page = res.data.current + 1
  81. // list.value = list.value.concat(res.data.rows || [])
  82. list.value = res.data.rows
  83. showContact.value = list.value.length > 0
  84. console.log(showContact.value, ' showContact.value ')
  85. loading.value = false
  86. finished.value = true
  87. // finished.value = res.data.current >= res.data.pages
  88. } catch (e: any) {
  89. // console.log(e, 'e')
  90. const message = e.message
  91. showToast(message)
  92. showContact.value = false
  93. finished.value = true
  94. }
  95. }
  96. const checkOrchestra = (val: any) => {
  97. const selectedOptions = val.selectedOptions[0] || {}
  98. forms.orchestraId = selectedOptions.value
  99. forms.orchestraName = selectedOptions.name
  100. state.showPopoverOrchestra = false
  101. refreshing.value = true
  102. getList()
  103. }
  104. const checkSubject = (val: any) => {
  105. const selectedOptions = val.selectedOptions[0] || {}
  106. forms.subjectId = selectedOptions.value
  107. forms.subjectName = selectedOptions.name
  108. state.showPopoverSubject = false
  109. refreshing.value = true
  110. getList()
  111. }
  112. const getOrchestraList = async () => {
  113. // const schoolId = globalState.user.data.schoolInfos
  114. // .map((item) => {
  115. // return item.id
  116. // })
  117. // .join(',')
  118. try {
  119. const res = await request.post('/api-school/orchestra/page', {
  120. data: { page: 1, rows: 9999, status: 'DONE' }
  121. })
  122. state.actions = res.data.rows.map((item) => {
  123. return {
  124. name: item.name,
  125. value: item.id as string
  126. }
  127. })
  128. state.actions.unshift({ name: '全部乐团', value: '' })
  129. } catch (e: any) {
  130. const message = e.message
  131. showToast(message)
  132. }
  133. }
  134. const getSubjects = async () => {
  135. try {
  136. const res = await request.post('/api-school/subjectBasicConfig/page', {
  137. data: { page: 1, rows: 9999, enableFlag: true }
  138. })
  139. state.subjects = res.data.rows.map((item) => {
  140. return {
  141. name: item.subjectName,
  142. value: item.subjectId as string
  143. }
  144. })
  145. state.subjects.unshift({ name: '全部声部', value: '' })
  146. } catch (e: any) {
  147. const message = e.message
  148. showToast(message)
  149. }
  150. }
  151. onMounted(() => {
  152. getSubjects()
  153. getOrchestraList()
  154. getList()
  155. })
  156. const onRefresh = () => {
  157. finished.value = false
  158. // 重新加载数据
  159. // 将 loading 设置为 true,表示处于加载状态
  160. loading.value = true
  161. getList()
  162. }
  163. return () => (
  164. <div
  165. class={[!showContact.value && 'emptyRootContainer', styles.bangContainer]}
  166. style={{ minHeight: `calc(100vh - ${toTop.value}px)` }}
  167. >
  168. {/* <OSticky position="top" background="#FFF"> */}
  169. <Sticky offsetTop={toTop.value} style={{ width: '100%' }}>
  170. <div class={'searchGroup'}>
  171. {/* <div
  172. class={['searchItem searchItem-normal', state.showPopoverTime && 'searchItem-active']}
  173. onClick={() => {
  174. state.showPopoverTime = true
  175. }}
  176. >
  177. <span>{forms.timeName}</span>
  178. <i class="arrow"></i>
  179. </div> */}
  180. <div
  181. class={[
  182. 'searchItem searchItem-normal',
  183. state.showPopoverOrchestra && 'searchItem-active'
  184. ]}
  185. onClick={() => {
  186. state.showPopoverOrchestra = true
  187. }}
  188. >
  189. <span>{forms.orchestraName}</span>
  190. <i class="arrow"></i>
  191. </div>
  192. <div
  193. class={[
  194. 'searchItem searchItem-normal',
  195. state.showPopoverSubject && 'searchItem-active'
  196. ]}
  197. onClick={() => {
  198. state.showPopoverSubject = true
  199. }}
  200. >
  201. <span>{forms.subjectName}</span>
  202. <i class="arrow"></i>
  203. </div>
  204. </div>
  205. </Sticky>
  206. {/* </OSticky> */}
  207. {showContact.value ? (
  208. <OFullRefresh
  209. v-model:modelValue={refreshing.value}
  210. onRefresh={onRefresh}
  211. style={{
  212. minHeight: `calc(100vh - ${toTop.value}px - 1.17333rem)`
  213. }}
  214. >
  215. <List
  216. // v-model:loading={loading.value}
  217. finished={finished.value}
  218. finished-text=" "
  219. onLoad={getList}
  220. loading-text=" "
  221. >
  222. {list.value.map((item: any, index: number) => (
  223. <RankItem item={item} type="time" index={index + 1}></RankItem>
  224. ))}
  225. </List>
  226. </OFullRefresh>
  227. ) : (
  228. <OEmpty tips="暂无排行" />
  229. )}
  230. <Popup
  231. v-model:show={state.showPopoverOrchestra}
  232. position="bottom"
  233. round
  234. class={'popupBottomSearch'}
  235. >
  236. <Picker
  237. columns={state.actions}
  238. onCancel={() => (state.showPopoverOrchestra = false)}
  239. onConfirm={(val: any) => checkOrchestra(val)}
  240. columnsFieldNames={{ text: 'name', value: 'value' }}
  241. />
  242. </Popup>
  243. <Popup
  244. v-model:show={state.showPopoverSubject}
  245. position="bottom"
  246. round
  247. class={'popupBottomSearch'}
  248. >
  249. <Picker
  250. columns={state.subjects}
  251. onCancel={() => (state.showPopoverSubject = false)}
  252. onConfirm={(val: any) => checkSubject(val)}
  253. columnsFieldNames={{ text: 'name', value: 'value' }}
  254. />
  255. </Popup>
  256. </div>
  257. )
  258. }
  259. })