timer-bang.tsx 9.2 KB

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