attend-student.tsx 7.2 KB

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