index.tsx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 { defineComponent, reactive, ref, onMounted, watch } from 'vue'
  17. import { useRouter } from 'vue-router'
  18. import styles from './index.module.less'
  19. import request from '@/helpers/request'
  20. import { state as globalState } from '@/state'
  21. import { courseEmnu } from '@/constant'
  22. import TeacherAttItem from './modals/teacherAtt-item'
  23. export default defineComponent({
  24. name: 'attend-student',
  25. props: {
  26. toHeight: {
  27. type: Number,
  28. default: 0
  29. }
  30. },
  31. setup(props) {
  32. const router = useRouter()
  33. const state = reactive({
  34. showPopoverTime: false,
  35. showPopoverOrchestra: false,
  36. showPopoverSubject: false,
  37. actions: [] as any,
  38. courseList: [] as any,
  39. currentDate: [dayjs().format('YYYY'), dayjs().format('MM')]
  40. })
  41. const forms = reactive({
  42. time: state.currentDate[0] + '-' + state.currentDate[1],
  43. timeName: state.currentDate[0] + '年' + state.currentDate[1] + '月',
  44. keyword: '',
  45. orchestraId: '',
  46. orchestraName: '全部乐团',
  47. courseType: '',
  48. courseTypeName: '所有课程',
  49. page: 1,
  50. rows: 20
  51. })
  52. const toTop = ref(props.toHeight)
  53. const minDate = ref(new Date(dayjs().subtract(10, 'year').format('YYYY-MM-DD')))
  54. const maxDate = ref(new Date(dayjs().add(10, 'year').format('YYYY-MM-DD')))
  55. const columnsType = ref<DatePickerColumnType[]>(['year', 'month'])
  56. const refreshing = ref(false)
  57. const loading = ref(false)
  58. const finished = ref(false)
  59. const showContact = ref(false)
  60. const list = ref([])
  61. const getList = async () => {
  62. loading.value = true
  63. try {
  64. if (refreshing.value) {
  65. forms.page = 1
  66. list.value = []
  67. refreshing.value = false
  68. }
  69. const res = await request.post('/api-teacher/courseSchedule/teacherAttendance', {
  70. data: { ...forms }
  71. })
  72. if (list.value.length > 0 && res.data.pages === 1) {
  73. return
  74. }
  75. forms.page = res.data.current + 1
  76. for (let i = 0; i < 10; i++) {
  77. list.value = list.value.concat(res.data.rows || [])
  78. }
  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. <Sticky offsetTop={toTop.value}>
  156. <div>
  157. <OHeader></OHeader>
  158. <div class={styles.chioseWrap}>
  159. <div style={{ padding: '12px 13px', background: '#F8F8F8' }}>
  160. <div
  161. class={styles.searchBand}
  162. onClick={() => {
  163. state.showPopoverTime = true
  164. }}
  165. >
  166. {forms.timeName}
  167. <Icon name={state.showPopoverTime ? 'arrow-up' : 'arrow-down'} />
  168. </div>
  169. </div>
  170. <div style={{ padding: '12px 13px', background: '#F8F8F8' }}>
  171. <div
  172. class={styles.searchBand}
  173. onClick={() => {
  174. state.showPopoverOrchestra = true
  175. }}
  176. >
  177. {forms.orchestraName}
  178. <Icon name={state.showPopoverOrchestra ? 'arrow-up' : 'arrow-down'} />
  179. </div>
  180. </div>
  181. <div style={{ padding: '12px 13px', background: '#F8F8F8' }}>
  182. <div
  183. class={styles.searchBand}
  184. onClick={() => {
  185. state.showPopoverSubject = true
  186. }}
  187. >
  188. {forms.courseTypeName}
  189. <Icon name={state.showPopoverSubject ? 'arrow-up' : 'arrow-down'} />
  190. </div>
  191. </div>
  192. </div>
  193. </div>
  194. </Sticky>
  195. {showContact.value ? (
  196. <PullRefresh v-model={refreshing.value} onRefresh={onRefresh}>
  197. <List
  198. v-model:loading={loading.value}
  199. finished={finished.value}
  200. finished-text="没有更多了"
  201. onLoad={getList}
  202. >
  203. {list.value.map((item: any) => (
  204. <TeacherAttItem item={item}></TeacherAttItem>
  205. ))}
  206. </List>
  207. </PullRefresh>
  208. ) : (
  209. <OEmpty />
  210. )}
  211. <Popup v-model:show={state.showPopoverTime} position="bottom" style="{ height: '30%' }">
  212. <DatePicker
  213. onCancel={() => {
  214. state.showPopoverTime = false
  215. }}
  216. onConfirm={checkTimer}
  217. v-model={state.currentDate}
  218. title="选择年月"
  219. minDate={minDate.value}
  220. maxDate={maxDate.value}
  221. columnsType={columnsType.value}
  222. />
  223. </Popup>
  224. <ActionSheet
  225. v-model:show={state.showPopoverOrchestra}
  226. title="选择乐团"
  227. actions={state.actions}
  228. onSelect={checkOrchestra}
  229. ></ActionSheet>
  230. <ActionSheet
  231. style={{ height: '40%' }}
  232. close-on-click-action
  233. v-model:show={state.showPopoverSubject}
  234. title="选择课程"
  235. actions={state.courseList}
  236. onSelect={checkSubject}
  237. ></ActionSheet>
  238. </>
  239. )
  240. }
  241. })