timer-bang.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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={'searchGroup'}>
  179. <div
  180. class={['searchItem searchItem-normal', state.showPopoverTime && 'searchItem-active']}
  181. onClick={() => {
  182. state.showPopoverTime = true
  183. }}
  184. >
  185. <span>{forms.timeName}</span>
  186. <i class="arrow"></i>
  187. </div>
  188. <div
  189. class={[
  190. 'searchItem searchItem-normal',
  191. state.showPopoverOrchestra && 'searchItem-active'
  192. ]}
  193. onClick={() => {
  194. state.showPopoverOrchestra = true
  195. }}
  196. >
  197. <span>{forms.orchestraName}</span>
  198. <i class="arrow"></i>
  199. </div>
  200. <div
  201. class={[
  202. 'searchItem searchItem-normal',
  203. state.showPopoverSubject && 'searchItem-active'
  204. ]}
  205. onClick={() => {
  206. state.showPopoverSubject = true
  207. }}
  208. >
  209. <span>{forms.subjectName}</span>
  210. <i class="arrow"></i>
  211. </div>
  212. </div>
  213. {/* <div class={styles.chioseWrap}>
  214. <div style={{ padding: '0 13px', background: '#FFF' }}>
  215. <div
  216. class={styles.searchBand}
  217. onClick={() => {
  218. state.showPopoverTime = true
  219. }}
  220. >
  221. {forms.timeName}
  222. <Icon name={state.showPopoverTime ? 'arrow-up' : 'arrow-down'} />
  223. </div>
  224. </div>
  225. <div
  226. style={{
  227. padding: '0 13px',
  228. background: '#FFF'
  229. }}
  230. >
  231. <div
  232. class={styles.searchBand}
  233. onClick={() => {
  234. state.showPopoverOrchestra = true
  235. }}
  236. >
  237. <div class={['van-ellipsis', styles.bandName]}>{forms.orchestraName}</div>
  238. <Icon name={state.showPopoverOrchestra ? 'arrow-up' : 'arrow-down'} />
  239. </div>
  240. </div>
  241. <div style={{ padding: '0 13px', background: '#FFF' }}>
  242. <div
  243. class={styles.searchBand}
  244. onClick={() => {
  245. state.showPopoverSubject = true
  246. }}
  247. >
  248. {forms.subjectName}
  249. <Icon name={state.showPopoverSubject ? 'arrow-up' : 'arrow-down'} />
  250. </div>
  251. </div>
  252. </div> */}
  253. </Sticky>
  254. {/* </OSticky> */}
  255. {showContact.value ? (
  256. <OFullRefresh v-model:modelValue={refreshing.value} onRefresh={onRefresh}>
  257. <List
  258. // v-model:loading={loading.value}
  259. finished={finished.value}
  260. finished-text="没有更多了"
  261. onLoad={getList}
  262. loading-text=" "
  263. >
  264. {list.value.map((item: any, index: number) => (
  265. <RankItem item={item} type="time" index={index + 1}></RankItem>
  266. ))}
  267. </List>
  268. </OFullRefresh>
  269. ) : (
  270. <OEmpty />
  271. )}
  272. <Popup
  273. v-model:show={state.showPopoverTime}
  274. position="bottom"
  275. round
  276. class={'popupBottomSearch'}
  277. >
  278. <DatePicker
  279. onCancel={() => {
  280. state.showPopoverTime = false
  281. }}
  282. onConfirm={checkTimer}
  283. v-model={state.currentDate}
  284. title="选择年月"
  285. minDate={minDate.value}
  286. maxDate={maxDate.value}
  287. columnsType={columnsType.value}
  288. />
  289. </Popup>
  290. {/* <ActionSheet
  291. v-model:show={state.showPopoverOrchestra}
  292. title="选择乐团"
  293. actions={state.actions}
  294. onSelect={checkOrchestra}
  295. ></ActionSheet>
  296. <ActionSheet
  297. style={{ height: '40%' }}
  298. close-on-click-action
  299. v-model:show={state.showPopoverSubject}
  300. title="选择声部"
  301. actions={state.subjects}
  302. onSelect={checkSubject}
  303. ></ActionSheet> */}
  304. <Popup
  305. v-model:show={state.showPopoverOrchestra}
  306. position="bottom"
  307. round
  308. class={'popupBottomSearch'}
  309. >
  310. <Picker
  311. columns={state.actions}
  312. onCancel={() => (state.showPopoverOrchestra = false)}
  313. onConfirm={(val: any) => checkOrchestra(val)}
  314. columnsFieldNames={{ text: 'name', value: 'value' }}
  315. />
  316. </Popup>
  317. <Popup
  318. v-model:show={state.showPopoverSubject}
  319. position="bottom"
  320. round
  321. class={'popupBottomSearch'}
  322. >
  323. <Picker
  324. columns={state.subjects}
  325. onCancel={() => (state.showPopoverSubject = false)}
  326. onConfirm={(val: any) => checkSubject(val)}
  327. columnsFieldNames={{ text: 'name', value: 'value' }}
  328. />
  329. </Popup>
  330. </div>
  331. )
  332. }
  333. })