timer-bang.tsx 7.5 KB

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