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