attend-student.tsx 7.5 KB

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