attend-teacher.tsx 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. } from 'vant'
  15. import { defineComponent, reactive, ref, onMounted } from 'vue'
  16. import { useRouter } from 'vue-router'
  17. import styles from './attent-student.module.less'
  18. import request from '@/helpers/request'
  19. import { state as globalState } from '@/state'
  20. import { courseEmnu } from '@/constant'
  21. import TeacherAttItem from '../modals/teacherAtt-item'
  22. export default defineComponent({
  23. name: 'attend-student',
  24. setup() {
  25. const router = useRouter()
  26. const state = reactive({
  27. showPopoverTime: false,
  28. showPopoverOrchestra: false,
  29. showPopoverSubject: false,
  30. actions: [] as any,
  31. courseList: [] as any,
  32. currentDate: [dayjs().format('YYYY'), dayjs().format('MM')]
  33. })
  34. const forms = reactive({
  35. time: state.currentDate[0] + '-' + state.currentDate[1],
  36. timeName: state.currentDate[0] + '年' + state.currentDate[1] + '月',
  37. keyword: '',
  38. orchestraId: '',
  39. orchestraName: '全部乐团',
  40. courseType: '',
  41. courseTypeName: '所有课程',
  42. page: 1,
  43. rows: 20
  44. })
  45. const minDate = ref(new Date(dayjs().subtract(5, 'year').format('YYYY-MM-DD')))
  46. const maxDate = ref(new Date(dayjs().add(5, 'year').format('YYYY-MM-DD')))
  47. const columnsType = ref<DatePickerColumnType[]>(['year', 'month'])
  48. const refreshing = ref(false)
  49. const loading = ref(false)
  50. const finished = ref(false)
  51. const showContact = ref(false)
  52. const list = ref([])
  53. const getList = async () => {
  54. loading.value = true
  55. try {
  56. if (refreshing.value) {
  57. forms.page = 1
  58. list.value = []
  59. refreshing.value = false
  60. }
  61. const res = await request.post('/api-school/courseSchedule/teacherAttendance', {
  62. data: { ...forms }
  63. })
  64. if (list.value.length > 0 && res.data.pages === 1) {
  65. return
  66. }
  67. forms.page = res.data.current + 1
  68. list.value = list.value.concat(res.data.rows || [])
  69. showContact.value = list.value.length > 0
  70. loading.value = false
  71. finished.value = res.data.current >= res.data.pages
  72. } catch (e: any) {
  73. // console.log(e, 'e')
  74. const message = e.message
  75. showToast(message)
  76. showContact.value = false
  77. finished.value = true
  78. }
  79. }
  80. const getCourseList = () => {
  81. state.courseList = []
  82. for (const key in courseEmnu) {
  83. state.courseList.push({ name: courseEmnu[key], value: key })
  84. }
  85. state.courseList.unshift({ name: '全部课程', value: '' })
  86. }
  87. const checkTimer = (val: any) => {
  88. forms.time = val.selectedValues[0] + '-' + val.selectedValues[1]
  89. forms.timeName = val.selectedValues[0] + '年' + val.selectedValues[1] + '月'
  90. state.showPopoverTime = false
  91. getList()
  92. }
  93. const checkOrchestra = (val: any) => {
  94. forms.orchestraId = val.value
  95. forms.orchestraName = val.name
  96. state.showPopoverOrchestra = false
  97. refreshing.value = true
  98. getList()
  99. }
  100. const checkSubject = (val: any) => {
  101. forms.courseType = val.value
  102. forms.courseTypeName = val.name
  103. refreshing.value = true
  104. getList()
  105. }
  106. const getOrchestraList = async () => {
  107. const schoolId = globalState.user.data.schoolInfos
  108. .map((item) => {
  109. return item.id
  110. })
  111. .join(',')
  112. try {
  113. const res = await request.post('/api-school/orchestra/page', {
  114. data: { page: 1, rows: 9999, schoolId }
  115. })
  116. state.actions = res.data.rows.map((item) => {
  117. return {
  118. name: item.name,
  119. value: item.id as string
  120. }
  121. })
  122. state.actions.unshift({ name: '全部乐团', value: '' })
  123. } catch (e: any) {
  124. const message = e.message
  125. showToast(message)
  126. }
  127. }
  128. onMounted(() => {
  129. getOrchestraList()
  130. getList()
  131. getCourseList()
  132. })
  133. const onRefresh = () => {
  134. finished.value = false
  135. // 重新加载数据
  136. // 将 loading 设置为 true,表示处于加载状态
  137. loading.value = true
  138. getList()
  139. }
  140. return () => (
  141. <>
  142. {/* <OSticky position="top" background="#F8F8F8"> */}
  143. <OSearch
  144. placeholder="请输入伴学指导姓名"
  145. inputBackground="white"
  146. background="#f6f6f6"
  147. onSearch={(val: any) => {
  148. console.log(val, 'onSearch')
  149. forms.keyword = val
  150. refreshing.value = true
  151. getList()
  152. }}
  153. ></OSearch>
  154. <div class={styles.chioseWrap}>
  155. <div style={{ padding: '12px 13px', background: '#F8F8F8' }}>
  156. <div
  157. class={styles.searchBand}
  158. onClick={() => {
  159. state.showPopoverTime = true
  160. }}
  161. >
  162. {forms.timeName}
  163. <Icon name={state.showPopoverTime ? 'arrow-up' : 'arrow-down'} />
  164. </div>
  165. </div>
  166. <div style={{ padding: '12px 13px', background: '#F8F8F8' }}>
  167. <div
  168. class={styles.searchBand}
  169. onClick={() => {
  170. state.showPopoverOrchestra = true
  171. }}
  172. >
  173. {forms.orchestraName}
  174. <Icon name={state.showPopoverOrchestra ? 'arrow-up' : 'arrow-down'} />
  175. </div>
  176. </div>
  177. <div style={{ padding: '12px 13px', background: '#F8F8F8' }}>
  178. <div
  179. class={styles.searchBand}
  180. onClick={() => {
  181. state.showPopoverSubject = true
  182. }}
  183. >
  184. {forms.courseTypeName}
  185. <Icon name={state.showPopoverSubject ? 'arrow-up' : 'arrow-down'} />
  186. </div>
  187. </div>
  188. </div>
  189. {/* </OSticky> */}
  190. {showContact.value ? (
  191. <PullRefresh v-model={refreshing.value} onRefresh={onRefresh}>
  192. <List
  193. v-model:loading={loading.value}
  194. finished={finished.value}
  195. finished-text="没有更多了"
  196. onLoad={getList}
  197. >
  198. {list.value.map((item: any) => (
  199. <TeacherAttItem item={item}></TeacherAttItem>
  200. ))}
  201. </List>
  202. </PullRefresh>
  203. ) : (
  204. <OEmpty />
  205. )}
  206. <Popup v-model:show={state.showPopoverTime} position="bottom" style="{ height: '30%' }">
  207. <DatePicker
  208. onCancel={() => {
  209. state.showPopoverTime = false
  210. }}
  211. onConfirm={checkTimer}
  212. v-model={state.currentDate}
  213. title="选择年月"
  214. minDate={minDate.value}
  215. maxDate={maxDate.value}
  216. columnsType={columnsType.value}
  217. />
  218. </Popup>
  219. <ActionSheet
  220. v-model:show={state.showPopoverOrchestra}
  221. title="选择乐团"
  222. actions={state.actions}
  223. onSelect={checkOrchestra}
  224. ></ActionSheet>
  225. <ActionSheet
  226. style={{ height: '40%' }}
  227. close-on-click-action
  228. v-model:show={state.showPopoverSubject}
  229. title="选择课程"
  230. actions={state.courseList}
  231. onSelect={checkSubject}
  232. ></ActionSheet>
  233. </>
  234. )
  235. }
  236. })