attend-student.tsx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. import OSearch from '@/components/o-search'
  2. import OEmpty from '@/components/o-empty'
  3. import dayjs from 'dayjs'
  4. import OFullRefresh from '@/components/o-full-refresh'
  5. import {
  6. Icon,
  7. Popover,
  8. DatePicker,
  9. DatePickerColumnType,
  10. Popup,
  11. List,
  12. PullRefresh,
  13. ActionSheet,
  14. showToast,
  15. Sticky,
  16. Picker
  17. } from 'vant'
  18. import { defineComponent, reactive, ref, onMounted, watch } from 'vue'
  19. import { useRouter } from 'vue-router'
  20. import styles from './attent-student.module.less'
  21. import request from '@/helpers/request'
  22. import { state as globalState } from '@/state'
  23. import StudentAttItem from '../modals/studentAtt-item'
  24. export default defineComponent({
  25. name: 'attend-student',
  26. props: {
  27. toHeight: {
  28. type: Number,
  29. default: 0
  30. }
  31. },
  32. setup(props, { emit }) {
  33. const router = useRouter()
  34. const state = reactive({
  35. showPopoverTime: false,
  36. showPopoverOrchestra: false,
  37. showPopoverSubject: false,
  38. isClick: false,
  39. actions: [] as any,
  40. subjects: [] as any,
  41. currentDate: [dayjs().format('YYYY'), dayjs().format('MM')]
  42. })
  43. const forms = reactive({
  44. time: state.currentDate[0] + '' + state.currentDate[1],
  45. timeName: state.currentDate[0] + '年' + state.currentDate[1] + '月',
  46. orchestraId: '',
  47. orchestraName: '全部乐团',
  48. subjectId: '',
  49. subjectName: '全部声部',
  50. page: 1,
  51. rows: 20
  52. })
  53. const toTop = ref(props.toHeight)
  54. const minDate = ref(new Date(dayjs().subtract(10, 'year').format('YYYY-MM-DD')))
  55. const maxDate = ref(new Date(dayjs().add(10, 'year').format('YYYY-MM-DD')))
  56. const columnsType = ref<DatePickerColumnType[]>(['year', 'month'])
  57. const refreshing = ref(false)
  58. const loading = ref(false)
  59. const finished = ref(false)
  60. const showContact = ref(false)
  61. const list = ref([])
  62. const getList = async () => {
  63. if (state.isClick) {
  64. return
  65. }
  66. state.isClick = true
  67. loading.value = true
  68. try {
  69. if (refreshing.value) {
  70. // forms.page = 1
  71. list.value = []
  72. refreshing.value = false
  73. }
  74. const res = await request.post(
  75. '/api-school/courseScheduleStudentAttendance/studentAttendance',
  76. {
  77. data: { ...forms }
  78. }
  79. )
  80. if (list.value.length > 0 && res.data.pages === 1) {
  81. return
  82. }
  83. // forms.page = res.data.current + 1
  84. list.value = res.data
  85. showContact.value = list.value.length > 0
  86. // console.log(showContact.value, ' showContact.value ')
  87. loading.value = false
  88. finished.value = true
  89. } catch (e: any) {
  90. // console.log(e, 'e')
  91. const message = e.message
  92. showToast(message)
  93. showContact.value = false
  94. finished.value = true
  95. }
  96. state.isClick = false
  97. }
  98. const checkTimer = (val: any) => {
  99. forms.time = val.selectedValues[0] + val.selectedValues[1]
  100. forms.timeName = val.selectedValues[0] + '年' + val.selectedValues[1] + '月'
  101. state.showPopoverTime = false
  102. getList()
  103. }
  104. const checkOrchestra = (val: any) => {
  105. const selectedOptions = val.selectedOptions[0] || {}
  106. forms.orchestraId = selectedOptions.value
  107. forms.orchestraName = selectedOptions.name
  108. state.showPopoverOrchestra = false
  109. refreshing.value = true
  110. getList()
  111. }
  112. const checkSubject = (val: any) => {
  113. const selectedOptions = val.selectedOptions[0] || {}
  114. forms.subjectId = selectedOptions.value
  115. forms.subjectName = selectedOptions.name
  116. state.showPopoverSubject = false
  117. refreshing.value = true
  118. getList()
  119. }
  120. const getOrchestraList = async () => {
  121. try {
  122. const res = await request.post('/api-teacher/orchestra/page', {
  123. data: { page: 1, rows: 9999, status: 'DONE' }
  124. })
  125. state.actions = res.data.rows.map((item) => {
  126. return {
  127. name: item.name,
  128. value: item.id as string
  129. }
  130. })
  131. state.actions.unshift({
  132. name: '全部乐团',
  133. value: ''
  134. })
  135. } catch (e: any) {
  136. const message = e.message
  137. showToast(message)
  138. }
  139. }
  140. const getSubjects = async () => {
  141. try {
  142. const res = await request.post('/api-school/subjectBasicConfig/page', {
  143. data: { page: 1, rows: 9999 }
  144. })
  145. state.subjects = res.data.rows.map((item) => {
  146. return {
  147. name: item.subjectName,
  148. value: item.subjectId as string
  149. }
  150. })
  151. state.subjects.unshift({ name: '全部声部', value: '' })
  152. } catch (e: any) {
  153. const message = e.message
  154. showToast(message)
  155. }
  156. }
  157. onMounted(() => {
  158. getSubjects()
  159. getOrchestraList()
  160. getList()
  161. })
  162. watch(
  163. () => props.toHeight,
  164. (val: number) => {
  165. toTop.value = val
  166. }
  167. )
  168. const onRefresh = () => {
  169. finished.value = false
  170. // 重新加载数据
  171. // 将 loading 设置为 true,表示处于加载状态
  172. loading.value = true
  173. getList()
  174. }
  175. return () => (
  176. <div>
  177. <div class={'searchGroup'}>
  178. <div
  179. class={['searchItem', state.showPopoverTime && 'searchItem-active']}
  180. onClick={() => {
  181. state.showPopoverTime = true
  182. }}
  183. >
  184. {forms.timeName}
  185. <i class={'arrow'}></i>
  186. </div>
  187. <div
  188. class={['searchItem', state.showPopoverOrchestra && 'searchItem-active']}
  189. onClick={() => {
  190. state.showPopoverOrchestra = true
  191. }}
  192. >
  193. <span>{forms.orchestraName}</span>
  194. <i class={'arrow'}></i>
  195. </div>
  196. <div
  197. class={['searchItem', state.showPopoverSubject && 'searchItem-active']}
  198. onClick={() => {
  199. state.showPopoverSubject = true
  200. }}
  201. >
  202. {forms.subjectName}
  203. <i class={'arrow'}></i>
  204. </div>
  205. </div>
  206. {/* </Sticky> */}
  207. <div
  208. style={{
  209. overflowY: 'auto',
  210. height: 'calc(100vh - var(--van-tabs-line-height) - var(--header-height) - 1.17333rem)'
  211. }}
  212. >
  213. {showContact.value ? (
  214. <OFullRefresh
  215. v-model:modelValue={refreshing.value}
  216. onRefresh={onRefresh}
  217. style="min-height: calc(100vh - var(--van-tabs-line-height) - var(--header-height) - 1.17333rem);"
  218. >
  219. <List
  220. loading-text=" "
  221. // v-model:loading={loading.value}
  222. finished={finished.value}
  223. finished-text=" "
  224. onLoad={getList}
  225. >
  226. {list.value.map((item: any) => (
  227. <StudentAttItem item={item}></StudentAttItem>
  228. ))}
  229. </List>
  230. </OFullRefresh>
  231. ) : (
  232. <OEmpty tips="暂无考勤"></OEmpty>
  233. )}
  234. </div>
  235. <Popup
  236. v-model:show={state.showPopoverTime}
  237. position="bottom"
  238. round
  239. teleport={'body'}
  240. class={'popupBottomSearch'}
  241. >
  242. <DatePicker
  243. onCancel={() => {
  244. state.showPopoverTime = false
  245. }}
  246. onConfirm={checkTimer}
  247. v-model={state.currentDate}
  248. title="选择年月"
  249. minDate={minDate.value}
  250. maxDate={maxDate.value}
  251. columnsType={columnsType.value}
  252. />
  253. </Popup>
  254. <Popup
  255. v-model:show={state.showPopoverOrchestra}
  256. position="bottom"
  257. round
  258. teleport={'body'}
  259. class={'popupBottomSearch'}
  260. >
  261. <Picker
  262. columns={state.actions}
  263. onCancel={() => (state.showPopoverOrchestra = false)}
  264. onConfirm={(val: any) => checkOrchestra(val)}
  265. columnsFieldNames={{ text: 'name', value: 'value' }}
  266. />
  267. </Popup>
  268. <Popup
  269. v-model:show={state.showPopoverSubject}
  270. position="bottom"
  271. round
  272. teleport={'body'}
  273. class={'popupBottomSearch'}
  274. >
  275. <Picker
  276. columns={state.subjects}
  277. onCancel={() => (state.showPopoverSubject = false)}
  278. onConfirm={(val: any) => checkSubject(val)}
  279. columnsFieldNames={{ text: 'name', value: 'value' }}
  280. />
  281. </Popup>
  282. </div>
  283. )
  284. }
  285. })