attend-teacher.tsx 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. Sticky
  15. } from 'vant'
  16. import { defineComponent, reactive, ref, onMounted, watch } from 'vue'
  17. import { useRouter } from 'vue-router'
  18. import styles from './attent-student.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 OFullRefresh from '@/components/o-full-refresh'
  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-school/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-school/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. <Sticky offsetTop={toTop.value}>
  155. <div>
  156. <OSearch
  157. placeholder="请输入伴学指导姓名"
  158. inputBackground="white"
  159. background="#f6f6f6"
  160. onSearch={(val: any) => {
  161. console.log(val, 'onSearch')
  162. forms.keyword = val
  163. refreshing.value = true
  164. getList()
  165. }}
  166. ></OSearch>
  167. <div class={styles.chioseWrap}>
  168. <div style={{ padding: '12px 13px', background: '#F8F8F8' }}>
  169. <div
  170. class={[styles.searchBand, styles.orchestraBand]}
  171. onClick={() => {
  172. state.showPopoverTime = true
  173. }}
  174. >
  175. {forms.timeName}
  176. <Icon name={state.showPopoverTime ? '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.showPopoverOrchestra = true
  184. }}
  185. >
  186. {forms.orchestraName}
  187. <Icon name={state.showPopoverOrchestra ? 'arrow-up' : 'arrow-down'} />
  188. </div>
  189. </div>
  190. <div style={{ padding: '12px 13px', background: '#F8F8F8' }}>
  191. <div
  192. class={styles.searchBand}
  193. onClick={() => {
  194. state.showPopoverSubject = true
  195. }}
  196. >
  197. {forms.courseTypeName}
  198. <Icon name={state.showPopoverSubject ? 'arrow-up' : 'arrow-down'} />
  199. </div>
  200. </div>
  201. </div>
  202. </div>
  203. </Sticky>
  204. {showContact.value ? (
  205. <OFullRefresh
  206. v-model:modelValue={refreshing.value}
  207. onRefresh={onRefresh}
  208. style="min-height: 100vh;"
  209. >
  210. <List
  211. loading-text=" "
  212. v-model:loading={loading.value}
  213. finished={finished.value}
  214. finished-text="没有更多了"
  215. onLoad={getList}
  216. >
  217. {list.value.map((item: any) => (
  218. <TeacherAttItem item={item}></TeacherAttItem>
  219. ))}
  220. </List>
  221. </OFullRefresh>
  222. ) : (
  223. <OEmpty />
  224. )}
  225. <Popup v-model:show={state.showPopoverTime} position="bottom" style="{ height: '30%' }">
  226. <DatePicker
  227. onCancel={() => {
  228. state.showPopoverTime = false
  229. }}
  230. onConfirm={checkTimer}
  231. v-model={state.currentDate}
  232. title="选择年月"
  233. minDate={minDate.value}
  234. maxDate={maxDate.value}
  235. columnsType={columnsType.value}
  236. />
  237. </Popup>
  238. <ActionSheet
  239. v-model:show={state.showPopoverOrchestra}
  240. title="选择乐团"
  241. actions={state.actions}
  242. onSelect={checkOrchestra}
  243. ></ActionSheet>
  244. <ActionSheet
  245. style={{ height: '40%' }}
  246. close-on-click-action
  247. v-model:show={state.showPopoverSubject}
  248. title="选择课程"
  249. actions={state.courseList}
  250. onSelect={checkSubject}
  251. ></ActionSheet>
  252. </>
  253. )
  254. }
  255. })