index.tsx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. import OHeader from '@/components/o-header'
  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 OFullRefresh from '@/components/o-full-refresh'
  17. import { defineComponent, reactive, ref, onMounted, watch } from 'vue'
  18. import { useRouter } from 'vue-router'
  19. import styles from './index.module.less'
  20. import request from '@/helpers/request'
  21. import { state as globalState } from '@/state'
  22. import { courseEmnu } from '@/constant'
  23. import TeacherAttItem from './modals/teacherAtt-item'
  24. import OSticky from '@/components/o-sticky'
  25. export default defineComponent({
  26. name: 'attend-student',
  27. props: {
  28. toHeight: {
  29. type: Number,
  30. default: 0
  31. }
  32. },
  33. setup(props) {
  34. const router = useRouter()
  35. const state = reactive({
  36. showPopoverTime: false,
  37. showPopoverOrchestra: false,
  38. showPopoverSubject: false,
  39. actions: [] as any,
  40. courseList: [] 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. keyword: '',
  47. orchestraId: '',
  48. orchestraName: '全部乐团',
  49. courseType: '',
  50. courseTypeName: '所有课程',
  51. page: 1,
  52. rows: 20
  53. })
  54. const toTop = ref(props.toHeight)
  55. const minDate = ref(new Date(dayjs().subtract(10, 'year').format('YYYY-MM-DD')))
  56. const maxDate = ref(new Date(dayjs().add(10, 'year').format('YYYY-MM-DD')))
  57. const columnsType = ref<DatePickerColumnType[]>(['year', 'month'])
  58. const refreshing = ref(false)
  59. const loading = ref(false)
  60. const finished = ref(false)
  61. const showContact = ref(false)
  62. const list = ref([])
  63. const getList = async () => {
  64. loading.value = true
  65. try {
  66. if (refreshing.value) {
  67. forms.page = 1
  68. list.value = []
  69. refreshing.value = false
  70. }
  71. const res = await request.post('/api-teacher/courseSchedule/teacherAttendance', {
  72. data: { ...forms }
  73. })
  74. if (list.value.length > 0 && res.data.pages === 1) {
  75. return
  76. }
  77. forms.page = res.data.current + 1
  78. list.value = list.value.concat(res.data.rows || [])
  79. showContact.value = list.value.length > 0
  80. loading.value = false
  81. finished.value = res.data.current >= res.data.pages
  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 getCourseList = () => {
  91. state.courseList = []
  92. for (const key in courseEmnu) {
  93. state.courseList.push({ name: courseEmnu[key], value: key })
  94. }
  95. state.courseList.unshift({ name: '全部课程', value: '' })
  96. }
  97. const checkTimer = (val: any) => {
  98. forms.time = val.selectedValues[0] + '-' + val.selectedValues[1]
  99. forms.timeName = val.selectedValues[0] + '年' + val.selectedValues[1] + '月'
  100. state.showPopoverTime = false
  101. refreshing.value = true
  102. getList()
  103. }
  104. const checkOrchestra = (val: any) => {
  105. forms.orchestraId = val.value
  106. forms.orchestraName = val.name
  107. state.showPopoverOrchestra = false
  108. refreshing.value = true
  109. getList()
  110. }
  111. const checkSubject = (val: any) => {
  112. forms.courseType = val.value
  113. forms.courseTypeName = val.name
  114. refreshing.value = true
  115. getList()
  116. }
  117. const getOrchestraList = async () => {
  118. try {
  119. const res = await request.post('/api-teacher/orchestra/page', {
  120. data: { page: 1, rows: 9999 }
  121. })
  122. state.actions = res.data.rows.map((item) => {
  123. return {
  124. name: item.name,
  125. value: item.id as string
  126. }
  127. })
  128. state.actions.unshift({ name: '全部乐团', value: '' })
  129. } catch (e: any) {
  130. const message = e.message
  131. showToast(message)
  132. }
  133. }
  134. watch(
  135. () => props.toHeight,
  136. (val: number) => {
  137. toTop.value = val
  138. console.log(toTop.value, '老师的')
  139. }
  140. )
  141. onMounted(() => {
  142. getOrchestraList()
  143. getList()
  144. getCourseList()
  145. })
  146. const onRefresh = () => {
  147. finished.value = false
  148. // 重新加载数据
  149. // 将 loading 设置为 true,表示处于加载状态
  150. loading.value = true
  151. getList()
  152. }
  153. return () => (
  154. <>
  155. <OSticky position="top">
  156. <OHeader />
  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, styles.orchestraBand]}
  172. onClick={() => {
  173. state.showPopoverOrchestra = true
  174. }}
  175. >
  176. <div class={['van-ellipsis', styles.bandName]}>{forms.orchestraName}</div>
  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.courseTypeName}
  188. <Icon name={state.showPopoverSubject ? 'arrow-up' : 'arrow-down'} />
  189. </div>
  190. </div>
  191. </div>
  192. </OSticky>
  193. {showContact.value ? (
  194. <OFullRefresh
  195. v-model:modelValue={refreshing.value}
  196. onRefresh={onRefresh}
  197. style="min-height: 100vh;"
  198. >
  199. <List
  200. loading-text=" "
  201. v-model:loading={loading.value}
  202. finished={finished.value}
  203. finished-text="没有更多了"
  204. onLoad={getList}
  205. >
  206. {list.value.map((item: any) => (
  207. <TeacherAttItem item={item}></TeacherAttItem>
  208. ))}
  209. </List>
  210. </OFullRefresh>
  211. ) : (
  212. <OEmpty />
  213. )}
  214. <Popup v-model:show={state.showPopoverTime} position="bottom" style="{ height: '30%' }">
  215. <DatePicker
  216. onCancel={() => {
  217. state.showPopoverTime = false
  218. }}
  219. onConfirm={checkTimer}
  220. v-model={state.currentDate}
  221. title="选择年月"
  222. minDate={minDate.value}
  223. maxDate={maxDate.value}
  224. columnsType={columnsType.value}
  225. />
  226. </Popup>
  227. <ActionSheet
  228. v-model:show={state.showPopoverOrchestra}
  229. title="选择乐团"
  230. actions={state.actions}
  231. onSelect={checkOrchestra}
  232. ></ActionSheet>
  233. <ActionSheet
  234. style={{ height: '40%' }}
  235. close-on-click-action
  236. v-model:show={state.showPopoverSubject}
  237. title="选择课程"
  238. actions={state.courseList}
  239. onSelect={checkSubject}
  240. ></ActionSheet>
  241. </>
  242. )
  243. }
  244. })