attend-teacher.tsx 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. Picker
  16. } from 'vant'
  17. import { defineComponent, reactive, ref, onMounted, watch } from 'vue'
  18. import { useRouter } from 'vue-router'
  19. import styles from './attent-student.module.less'
  20. import request from '@/helpers/request'
  21. import { state as globalState } from '@/state'
  22. import { courseEmnu } from '@/constant'
  23. import TeacherAttItem from '../modals/teacherAtt-item'
  24. import OFullRefresh from '@/components/o-full-refresh'
  25. import { formatterDatePicker } from '@/helpers/utils'
  26. export default defineComponent({
  27. name: 'attend-student',
  28. props: {
  29. toHeight: {
  30. type: Number,
  31. default: 0
  32. }
  33. },
  34. setup(props) {
  35. const router = useRouter()
  36. const state = reactive({
  37. showPopoverTime: false,
  38. showPopoverOrchestra: false,
  39. showPopoverSubject: false,
  40. isClick: false,
  41. actions: [] as any,
  42. courseList: [] as any,
  43. currentDate: [dayjs().format('YYYY'), dayjs().format('MM')]
  44. })
  45. const forms = reactive({
  46. time: state.currentDate[0] + '-' + state.currentDate[1],
  47. timeName: state.currentDate[0] + '年' + state.currentDate[1] + '月',
  48. keyword: '',
  49. orchestraId: '',
  50. orchestraName: '全部乐团',
  51. courseType: '',
  52. courseTypeName: '所有课程',
  53. page: 1,
  54. rows: 20
  55. })
  56. const toTop = ref(props.toHeight)
  57. const minDate = ref(new Date(dayjs().subtract(10, 'year').format('YYYY-MM-DD')))
  58. const maxDate = ref(new Date(dayjs().add(10, 'year').format('YYYY-MM-DD')))
  59. const columnsType = ref<DatePickerColumnType[]>(['year', 'month'])
  60. const refreshing = ref(false)
  61. const loading = ref(false)
  62. const finished = ref(false)
  63. const showContact = ref(false)
  64. const list = ref([])
  65. const getList = async () => {
  66. if (state.isClick) {
  67. return
  68. }
  69. state.isClick = true
  70. loading.value = true
  71. try {
  72. if (refreshing.value) {
  73. forms.page = 1
  74. list.value = []
  75. refreshing.value = false
  76. }
  77. const res = await request.post('/api-school/courseSchedule/teacherAttendance', {
  78. data: { ...forms }
  79. })
  80. if (list.value.length > 0 && res.data.pages === 1) {
  81. return
  82. }
  83. forms.page = res.data.current + 1
  84. list.value = list.value.concat(res.data.rows || [])
  85. showContact.value = list.value.length > 0
  86. loading.value = false
  87. finished.value = res.data.current >= res.data.pages
  88. } catch (e: any) {
  89. // console.log(e, 'e')
  90. const message = e.message
  91. showToast(message)
  92. showContact.value = false
  93. finished.value = true
  94. }
  95. state.isClick = false
  96. }
  97. const getCourseList = () => {
  98. state.courseList = []
  99. for (const key in courseEmnu) {
  100. state.courseList.push({ name: courseEmnu[key], value: key })
  101. }
  102. state.courseList.unshift({ name: '全部课程', value: '' })
  103. }
  104. const checkTimer = (val: any) => {
  105. forms.time = val.selectedValues[0] + '-' + val.selectedValues[1]
  106. forms.timeName = val.selectedValues[0] + '年' + val.selectedValues[1] + '月'
  107. state.showPopoverTime = false
  108. refreshing.value = true
  109. getList()
  110. }
  111. const checkOrchestra = (val: any) => {
  112. const selectedOptions = val.selectedOptions[0] || {}
  113. forms.orchestraId = selectedOptions.value
  114. forms.orchestraName = selectedOptions.name
  115. state.showPopoverOrchestra = false
  116. refreshing.value = true
  117. getList()
  118. }
  119. const checkSubject = (val: any) => {
  120. const selectedOptions = val.selectedOptions[0] || {}
  121. // forms.courseType = val.value
  122. // forms.courseTypeName = val.name
  123. forms.courseType = selectedOptions.value
  124. forms.courseTypeName = selectedOptions.name
  125. state.showPopoverSubject = false
  126. refreshing.value = true
  127. getList()
  128. }
  129. const getOrchestraList = async () => {
  130. try {
  131. const res = await request.post('/api-school/orchestra/page', {
  132. data: { page: 1, rows: 9999, status: 'DONE' }
  133. })
  134. state.actions = res.data.rows.map((item) => {
  135. return {
  136. name: item.name,
  137. value: item.id as string
  138. }
  139. })
  140. state.actions.unshift({ name: '全部乐团', value: '' })
  141. } catch (e: any) {
  142. const message = e.message
  143. showToast(message)
  144. }
  145. }
  146. watch(
  147. () => props.toHeight,
  148. (val: number) => {
  149. toTop.value = val
  150. console.log(toTop.value, '老师的')
  151. }
  152. )
  153. onMounted(() => {
  154. getOrchestraList()
  155. getList()
  156. getCourseList()
  157. })
  158. const onRefresh = () => {
  159. finished.value = false
  160. // 重新加载数据
  161. // 将 loading 设置为 true,表示处于加载状态
  162. loading.value = true
  163. getList()
  164. }
  165. return () => (
  166. <div>
  167. <>
  168. <OSearch
  169. placeholder="请输入伴学老师姓名"
  170. // inputBackground="white"
  171. // background="#f6f6f6"
  172. class={styles.searchInput}
  173. onSearch={(val: any) => {
  174. console.log(val, 'onSearch')
  175. forms.keyword = val
  176. refreshing.value = true
  177. getList()
  178. }}
  179. ></OSearch>
  180. <div class={'searchGroup'}>
  181. <div
  182. class={['searchItem', state.showPopoverTime && 'searchItem-active']}
  183. onClick={() => {
  184. state.showPopoverTime = true
  185. }}
  186. >
  187. {forms.timeName}
  188. <i class={'arrow'}></i>
  189. </div>
  190. <div
  191. class={['searchItem', state.showPopoverOrchestra && 'searchItem-active']}
  192. onClick={() => {
  193. state.showPopoverOrchestra = true
  194. }}
  195. >
  196. <span>{forms.orchestraName}</span>
  197. <i class={'arrow'}></i>
  198. </div>
  199. <div
  200. class={['searchItem', state.showPopoverSubject && 'searchItem-active']}
  201. onClick={() => {
  202. state.showPopoverSubject = true
  203. }}
  204. >
  205. {forms.courseTypeName}
  206. <i class={'arrow'}></i>
  207. </div>
  208. </div>
  209. </>
  210. <div
  211. style={{
  212. overflowY: 'auto',
  213. height: 'calc(100vh - var(--van-tabs-line-height) - var(--header-height) - 2.61334rem)'
  214. }}
  215. >
  216. {showContact.value ? (
  217. <OFullRefresh
  218. v-model:modelValue={refreshing.value}
  219. onRefresh={onRefresh}
  220. style="min-height: calc(100vh - var(--van-tabs-line-height) - var(--header-height) - 2.61334rem)"
  221. >
  222. <List
  223. loading-text=" "
  224. // v-model:loading={loading.value}
  225. finished={finished.value}
  226. finished-text=" "
  227. onLoad={getList}
  228. style={{ paddingTop: '12px' }}
  229. >
  230. {list.value.map((item: any) => (
  231. <TeacherAttItem item={item}></TeacherAttItem>
  232. ))}
  233. </List>
  234. </OFullRefresh>
  235. ) : (
  236. <OEmpty tips="暂无考勤" />
  237. )}
  238. </div>
  239. <Popup
  240. v-model:show={state.showPopoverTime}
  241. position="bottom"
  242. round
  243. teleport={'body'}
  244. class={'popupBottomSearch'}
  245. >
  246. <DatePicker
  247. onCancel={() => {
  248. state.showPopoverTime = false
  249. }}
  250. onConfirm={checkTimer}
  251. v-model={state.currentDate}
  252. formatter={formatterDatePicker}
  253. minDate={minDate.value}
  254. maxDate={maxDate.value}
  255. columnsType={columnsType.value}
  256. />
  257. </Popup>
  258. <Popup
  259. v-model:show={state.showPopoverOrchestra}
  260. position="bottom"
  261. round
  262. teleport={'body'}
  263. class={'popupBottomSearch'}
  264. >
  265. <Picker
  266. columns={state.actions}
  267. onCancel={() => (state.showPopoverOrchestra = false)}
  268. onConfirm={(val: any) => checkOrchestra(val)}
  269. columnsFieldNames={{ text: 'name', value: 'value' }}
  270. />
  271. </Popup>
  272. <Popup
  273. v-model:show={state.showPopoverSubject}
  274. position="bottom"
  275. round
  276. teleport={'body'}
  277. class={'popupBottomSearch'}
  278. >
  279. <Picker
  280. columns={state.courseList}
  281. onCancel={() => (state.showPopoverSubject = false)}
  282. onConfirm={(val: any) => checkSubject(val)}
  283. columnsFieldNames={{ text: 'name', value: 'value' }}
  284. />
  285. </Popup>
  286. </div>
  287. )
  288. }
  289. })