index.tsx 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. import OSticky from '@/components/o-sticky'
  24. export default defineComponent({
  25. name: 'attend-student',
  26. props: {
  27. toHeight: {
  28. type: Number,
  29. default: 0
  30. }
  31. },
  32. setup(props) {
  33. const router = useRouter()
  34. const state = reactive({
  35. showPopoverTime: false,
  36. showPopoverOrchestra: false,
  37. showPopoverSubject: false,
  38. actions: [] as any,
  39. courseList: [] as any,
  40. currentDate: [dayjs().format('YYYY'), dayjs().format('MM')]
  41. })
  42. const forms = reactive({
  43. time: state.currentDate[0] + '-' + state.currentDate[1],
  44. timeName: state.currentDate[0] + '年' + state.currentDate[1] + '月',
  45. keyword: '',
  46. orchestraId: '',
  47. orchestraName: '全部乐团',
  48. courseType: '',
  49. courseTypeName: '所有课程',
  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. loading.value = true
  64. try {
  65. if (refreshing.value) {
  66. forms.page = 1
  67. list.value = []
  68. refreshing.value = false
  69. }
  70. const res = await request.post('/api-teacher/courseSchedule/teacherAttendance', {
  71. data: { ...forms }
  72. })
  73. if (list.value.length > 0 && res.data.pages === 1) {
  74. return
  75. }
  76. forms.page = res.data.current + 1
  77. for (let i = 0; i < 10; i++) {
  78. list.value = list.value.concat(res.data.rows || [])
  79. }
  80. showContact.value = list.value.length > 0
  81. loading.value = false
  82. finished.value = res.data.current >= res.data.pages
  83. } catch (e: any) {
  84. // console.log(e, 'e')
  85. const message = e.message
  86. showToast(message)
  87. showContact.value = false
  88. finished.value = true
  89. }
  90. }
  91. const getCourseList = () => {
  92. state.courseList = []
  93. for (const key in courseEmnu) {
  94. state.courseList.push({ name: courseEmnu[key], value: key })
  95. }
  96. state.courseList.unshift({ name: '全部课程', value: '' })
  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. refreshing.value = true
  103. getList()
  104. }
  105. const checkOrchestra = (val: any) => {
  106. forms.orchestraId = val.value
  107. forms.orchestraName = val.name
  108. state.showPopoverOrchestra = false
  109. refreshing.value = true
  110. getList()
  111. }
  112. const checkSubject = (val: any) => {
  113. forms.courseType = val.value
  114. forms.courseTypeName = val.name
  115. refreshing.value = true
  116. getList()
  117. }
  118. const getOrchestraList = async () => {
  119. try {
  120. const res = await request.post('/api-teacher/orchestra/page', {
  121. data: { page: 1, rows: 9999 }
  122. })
  123. state.actions = res.data.rows.map((item) => {
  124. return {
  125. name: item.name,
  126. value: item.id as string
  127. }
  128. })
  129. state.actions.unshift({ name: '全部乐团', value: '' })
  130. } catch (e: any) {
  131. const message = e.message
  132. showToast(message)
  133. }
  134. }
  135. watch(
  136. () => props.toHeight,
  137. (val: number) => {
  138. toTop.value = val
  139. console.log(toTop.value, '老师的')
  140. }
  141. )
  142. onMounted(() => {
  143. getOrchestraList()
  144. getList()
  145. getCourseList()
  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">
  157. <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. </OSticky>
  194. {showContact.value ? (
  195. <PullRefresh v-model={refreshing.value} onRefresh={onRefresh} style="min-height: 100vh;">
  196. <List
  197. v-model:loading={loading.value}
  198. finished={finished.value}
  199. finished-text="没有更多了"
  200. onLoad={getList}
  201. >
  202. {list.value.map((item: any) => (
  203. <TeacherAttItem item={item}></TeacherAttItem>
  204. ))}
  205. </List>
  206. </PullRefresh>
  207. ) : (
  208. <OEmpty />
  209. )}
  210. <Popup v-model:show={state.showPopoverTime} position="bottom" style="{ height: '30%' }">
  211. <DatePicker
  212. onCancel={() => {
  213. state.showPopoverTime = false
  214. }}
  215. onConfirm={checkTimer}
  216. v-model={state.currentDate}
  217. title="选择年月"
  218. minDate={minDate.value}
  219. maxDate={maxDate.value}
  220. columnsType={columnsType.value}
  221. />
  222. </Popup>
  223. <ActionSheet
  224. v-model:show={state.showPopoverOrchestra}
  225. title="选择乐团"
  226. actions={state.actions}
  227. onSelect={checkOrchestra}
  228. ></ActionSheet>
  229. <ActionSheet
  230. style={{ height: '40%' }}
  231. close-on-click-action
  232. v-model:show={state.showPopoverSubject}
  233. title="选择课程"
  234. actions={state.courseList}
  235. onSelect={checkSubject}
  236. ></ActionSheet>
  237. </>
  238. )
  239. }
  240. })