index.tsx 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. list.value = list.value.concat(res.data.rows || [])
  78. showContact.value = list.value.length > 0
  79. loading.value = false
  80. finished.value = res.data.current >= res.data.pages
  81. } catch (e: any) {
  82. // console.log(e, 'e')
  83. const message = e.message
  84. showToast(message)
  85. showContact.value = false
  86. finished.value = true
  87. }
  88. }
  89. const getCourseList = () => {
  90. state.courseList = []
  91. for (const key in courseEmnu) {
  92. state.courseList.push({ name: courseEmnu[key], value: key })
  93. }
  94. state.courseList.unshift({ name: '全部课程', value: '' })
  95. }
  96. const checkTimer = (val: any) => {
  97. forms.time = val.selectedValues[0] + '-' + val.selectedValues[1]
  98. forms.timeName = val.selectedValues[0] + '年' + val.selectedValues[1] + '月'
  99. state.showPopoverTime = false
  100. refreshing.value = true
  101. getList()
  102. }
  103. const checkOrchestra = (val: any) => {
  104. forms.orchestraId = val.value
  105. forms.orchestraName = val.name
  106. state.showPopoverOrchestra = false
  107. refreshing.value = true
  108. getList()
  109. }
  110. const checkSubject = (val: any) => {
  111. forms.courseType = val.value
  112. forms.courseTypeName = val.name
  113. refreshing.value = true
  114. getList()
  115. }
  116. const getOrchestraList = async () => {
  117. try {
  118. const res = await request.post('/api-teacher/orchestra/page', {
  119. data: { page: 1, rows: 9999 }
  120. })
  121. state.actions = res.data.rows.map((item) => {
  122. return {
  123. name: item.name,
  124. value: item.id as string
  125. }
  126. })
  127. state.actions.unshift({ name: '全部乐团', value: '' })
  128. } catch (e: any) {
  129. const message = e.message
  130. showToast(message)
  131. }
  132. }
  133. watch(
  134. () => props.toHeight,
  135. (val: number) => {
  136. toTop.value = val
  137. console.log(toTop.value, '老师的')
  138. }
  139. )
  140. onMounted(() => {
  141. getOrchestraList()
  142. getList()
  143. getCourseList()
  144. })
  145. const onRefresh = () => {
  146. finished.value = false
  147. // 重新加载数据
  148. // 将 loading 设置为 true,表示处于加载状态
  149. loading.value = true
  150. getList()
  151. }
  152. return () => (
  153. <>
  154. <OSticky position="top">
  155. <OHeader />
  156. <div class={styles.chioseWrap}>
  157. <div style={{ padding: '12px 13px', background: '#F8F8F8' }}>
  158. <div
  159. class={styles.searchBand}
  160. onClick={() => {
  161. state.showPopoverTime = true
  162. }}
  163. >
  164. {forms.timeName}
  165. <Icon name={state.showPopoverTime ? 'arrow-up' : 'arrow-down'} />
  166. </div>
  167. </div>
  168. <div style={{ padding: '12px 13px', background: '#F8F8F8' }}>
  169. <div
  170. class={styles.searchBand}
  171. onClick={() => {
  172. state.showPopoverOrchestra = true
  173. }}
  174. >
  175. {forms.orchestraName}
  176. <Icon name={state.showPopoverOrchestra ? 'arrow-up' : 'arrow-down'} />
  177. </div>
  178. </div>
  179. <div style={{ padding: '12px 13px', background: '#F8F8F8' }}>
  180. <div
  181. class={styles.searchBand}
  182. onClick={() => {
  183. state.showPopoverSubject = true
  184. }}
  185. >
  186. {forms.courseTypeName}
  187. <Icon name={state.showPopoverSubject ? 'arrow-up' : 'arrow-down'} />
  188. </div>
  189. </div>
  190. </div>
  191. </OSticky>
  192. {showContact.value ? (
  193. <PullRefresh v-model={refreshing.value} onRefresh={onRefresh} style="min-height: 100vh;">
  194. <List
  195. v-model:loading={loading.value}
  196. finished={finished.value}
  197. finished-text="没有更多了"
  198. onLoad={getList}
  199. >
  200. {list.value.map((item: any) => (
  201. <TeacherAttItem item={item}></TeacherAttItem>
  202. ))}
  203. </List>
  204. </PullRefresh>
  205. ) : (
  206. <OEmpty />
  207. )}
  208. <Popup v-model:show={state.showPopoverTime} position="bottom" style="{ height: '30%' }">
  209. <DatePicker
  210. onCancel={() => {
  211. state.showPopoverTime = false
  212. }}
  213. onConfirm={checkTimer}
  214. v-model={state.currentDate}
  215. title="选择年月"
  216. minDate={minDate.value}
  217. maxDate={maxDate.value}
  218. columnsType={columnsType.value}
  219. />
  220. </Popup>
  221. <ActionSheet
  222. v-model:show={state.showPopoverOrchestra}
  223. title="选择乐团"
  224. actions={state.actions}
  225. onSelect={checkOrchestra}
  226. ></ActionSheet>
  227. <ActionSheet
  228. style={{ height: '40%' }}
  229. close-on-click-action
  230. v-model:show={state.showPopoverSubject}
  231. title="选择课程"
  232. actions={state.courseList}
  233. onSelect={checkSubject}
  234. ></ActionSheet>
  235. </>
  236. )
  237. }
  238. })