day-bang.tsx 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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 } 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. export default defineComponent({
  23. props: ['toHeight'],
  24. emits: ['setTime'],
  25. name: 'day-bang',
  26. setup(props, { slots, attrs, emit }) {
  27. const router = useRouter()
  28. const state = reactive({
  29. showPopoverTime: false,
  30. showPopoverOrchestra: false,
  31. showPopoverSubject: false,
  32. actions: [] as any,
  33. subjects: [] as any,
  34. currentDate: [dayjs().format('YYYY'), dayjs().format('MM')]
  35. })
  36. const forms = reactive({
  37. practiceMonth: state.currentDate[0] + '' + state.currentDate[1],
  38. timeName: state.currentDate[0] + '年' + state.currentDate[1] + '月',
  39. orchestraId: '',
  40. orchestraName: '全部乐团',
  41. subjectId: '',
  42. subjectName: '全部声部',
  43. page: 1,
  44. rows: 50,
  45. sortType: 'PRACTICE_TIMES'
  46. })
  47. const minDate = ref(new Date(dayjs().subtract(10, 'year').format('YYYY-MM-DD')))
  48. const maxDate = ref(new Date(dayjs().add(10, 'year').format('YYYY-MM-DD')))
  49. const columnsType = ref<DatePickerColumnType[]>(['year', 'month'])
  50. const refreshing = ref(false)
  51. const loading = ref(false)
  52. const finished = ref(false)
  53. const showContact = ref(false)
  54. const list = ref([])
  55. const toTop = ref(props.toHeight)
  56. console.log(props.toHeight)
  57. watch(
  58. () => props.toHeight,
  59. (val: number) => {
  60. toTop.value = val
  61. }
  62. )
  63. const getList = async () => {
  64. loading.value = true
  65. try {
  66. if (refreshing.value) {
  67. forms.page = 1
  68. list.value = []
  69. refreshing.value = false
  70. }
  71. const res = await request.post('/api-school/student/page', {
  72. data: { ...forms }
  73. })
  74. if (list.value.length > 0 && res.data.pages === 1) {
  75. return
  76. }
  77. forms.page = res.data.current + 1
  78. // list.value = list.value.concat(res.data.rows || [])
  79. list.value = res.data.rows
  80. showContact.value = list.value.length > 0
  81. console.log(showContact.value, ' showContact.value ')
  82. loading.value = false
  83. finished.value = true
  84. // finished.value = res.data.current >= res.data.pages
  85. } catch (e: any) {
  86. // console.log(e, 'e')
  87. const message = e.message
  88. showToast(message)
  89. showContact.value = false
  90. finished.value = true
  91. }
  92. }
  93. const checkTimer = (val: any) => {
  94. forms.practiceMonth = val.selectedValues[0] + val.selectedValues[1]
  95. forms.timeName = val.selectedValues[0] + '年' + val.selectedValues[1] + '月'
  96. state.showPopoverTime = false
  97. emit('setTime', forms.timeName)
  98. refreshing.value = true
  99. getList()
  100. }
  101. const checkOrchestra = (val: any) => {
  102. forms.orchestraId = val.value
  103. forms.orchestraName = val.name
  104. state.showPopoverOrchestra = false
  105. refreshing.value = true
  106. getList()
  107. }
  108. const checkSubject = (val: any) => {
  109. forms.subjectId = val.value
  110. forms.subjectName = val.name
  111. console.log(val, forms)
  112. refreshing.value = true
  113. getList()
  114. }
  115. const getOrchestraList = async () => {
  116. // const schoolId = globalState.user.data.schoolInfos
  117. // .map((item) => {
  118. // return item.id
  119. // })
  120. // .join(',')
  121. try {
  122. const res = await request.post('/api-school/orchestra/page', {
  123. data: { page: 1, rows: 9999 }
  124. })
  125. state.actions = res.data.rows.map((item) => {
  126. return {
  127. name: item.name,
  128. value: item.id as string
  129. }
  130. })
  131. state.actions.unshift({ name: '全部乐团', value: '' })
  132. } catch (e: any) {
  133. const message = e.message
  134. showToast(message)
  135. }
  136. }
  137. const getSubjects = async () => {
  138. try {
  139. const res = await request.post('/api-school/subject/page', {
  140. data: { page: 1, rows: 9999 }
  141. })
  142. state.subjects = res.data.rows.map((item) => {
  143. return {
  144. name: item.name,
  145. value: item.id as string
  146. }
  147. })
  148. state.subjects.unshift({ name: '全部声部', value: '' })
  149. } catch (e: any) {
  150. const message = e.message
  151. showToast(message)
  152. }
  153. }
  154. onMounted(() => {
  155. getSubjects()
  156. getOrchestraList()
  157. getList()
  158. emit('setTime', forms.timeName)
  159. })
  160. const onRefresh = () => {
  161. finished.value = false
  162. // 重新加载数据
  163. // 将 loading 设置为 true,表示处于加载状态
  164. loading.value = true
  165. getList()
  166. }
  167. return () => (
  168. <>
  169. {/* <OSticky position="top" background="#FFF"> */}
  170. <Sticky offsetTop={toTop.value}>
  171. <div class={styles.chioseWrap}>
  172. <div style={{ padding: '0 13px', background: '#FFF' }}>
  173. <div
  174. class={styles.searchBand}
  175. onClick={() => {
  176. state.showPopoverTime = true
  177. }}
  178. >
  179. {forms.timeName}
  180. <Icon name={state.showPopoverTime ? 'arrow-up' : 'arrow-down'} />
  181. </div>
  182. </div>
  183. <div style={{ padding: '0 13px', background: '#FFF' }}>
  184. <div
  185. class={styles.searchBand}
  186. onClick={() => {
  187. state.showPopoverOrchestra = true
  188. }}
  189. >
  190. {forms.orchestraName}
  191. <Icon name={state.showPopoverOrchestra ? 'arrow-up' : 'arrow-down'} />
  192. </div>
  193. </div>
  194. <div style={{ padding: '0 13px', background: '#FFF' }}>
  195. <div
  196. class={styles.searchBand}
  197. onClick={() => {
  198. state.showPopoverSubject = true
  199. }}
  200. >
  201. {forms.subjectName}
  202. <Icon name={state.showPopoverSubject ? 'arrow-up' : 'arrow-down'} />
  203. </div>
  204. </div>
  205. </div>
  206. </Sticky>
  207. {/* </OSticky> */}
  208. {showContact.value ? (
  209. <PullRefresh v-model={refreshing.value} onRefresh={onRefresh} style="min-height: 100vh;">
  210. <List
  211. v-model:loading={loading.value}
  212. finished={finished.value}
  213. finished-text="没有更多了"
  214. onLoad={getList}
  215. >
  216. {list.value.map((item: any, index: number) => (
  217. <RankItem item={item} type="day" index={index + 1}></RankItem>
  218. ))}
  219. </List>
  220. </PullRefresh>
  221. ) : (
  222. <OEmpty />
  223. )}
  224. <Popup v-model:show={state.showPopoverTime} position="bottom" style="{ height: '30%' }">
  225. <DatePicker
  226. onCancel={() => {
  227. state.showPopoverTime = false
  228. }}
  229. onConfirm={checkTimer}
  230. v-model={state.currentDate}
  231. title="选择年月"
  232. minDate={minDate.value}
  233. maxDate={maxDate.value}
  234. columnsType={columnsType.value}
  235. />
  236. </Popup>
  237. <ActionSheet
  238. v-model:show={state.showPopoverOrchestra}
  239. title="选择乐团"
  240. actions={state.actions}
  241. onSelect={checkOrchestra}
  242. ></ActionSheet>
  243. <ActionSheet
  244. style={{ height: '40%' }}
  245. close-on-click-action
  246. v-model:show={state.showPopoverSubject}
  247. title="选择声部"
  248. actions={state.subjects}
  249. onSelect={checkSubject}
  250. ></ActionSheet>
  251. </>
  252. )
  253. }
  254. })