attend-teacher.tsx 9.3 KB

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