index.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import request from '@/helpers/request'
  2. import { state } from '@/state'
  3. import {
  4. ActionSheet,
  5. ActionSheetAction,
  6. Button,
  7. Empty,
  8. Grid,
  9. GridItem,
  10. Icon,
  11. Picker,
  12. Popover,
  13. Popup,
  14. showToast,
  15. Toast
  16. } from 'vant'
  17. import { computed, defineComponent, onMounted, reactive } from 'vue'
  18. import styles from './index.module.less'
  19. import iconLook from './image/look.svg'
  20. import { useRoute, useRouter } from 'vue-router'
  21. import OEmpty from '@/components/o-empty'
  22. import OSticky from '@/components/o-sticky'
  23. import OHeader from '@/components/o-header'
  24. import CourseItem from './component/CourseItem'
  25. import { courseEmnu } from '@/constant'
  26. import { browser } from '@/helpers/utils'
  27. export default defineComponent({
  28. name: 'lessonCourseware',
  29. setup() {
  30. const route = useRoute()
  31. const router = useRouter()
  32. const data = reactive({
  33. loading: true,
  34. list: [] as any,
  35. actionShow: false,
  36. actionName: '课程类型' as string | undefined,
  37. actionKey: '',
  38. showRight: true, // route.query.code != 'select' && browser().isTeacher
  39. })
  40. const filterData = (list: any[]) => {
  41. const schoolTerm = {}
  42. for (let i = 0; i < list.length; i++) {
  43. if (schoolTerm[list[i].sortNo]) {
  44. schoolTerm[list[i].sortNo].push(list[i])
  45. } else {
  46. schoolTerm[list[i].sortNo] = [list[i]]
  47. }
  48. }
  49. return schoolTerm
  50. }
  51. const getList = async () => {
  52. data.loading = true
  53. if (route.query.code === 'select') {
  54. try {
  55. const res: any = await request.post(
  56. state.platformApi + `/courseSchedule/getCourseware/${route.query.courseScheduleId}`
  57. )
  58. if (Array.isArray(res?.data)) {
  59. const data = res.data.map((n: any) => {
  60. return {
  61. coverImg: n.coverImg,
  62. name: n.coursewareName,
  63. id: n.lessonCoursewareId,
  64. courseNum: n.coursewareNum
  65. }
  66. })
  67. data.list = filterData(data)
  68. }
  69. } catch (error) {}
  70. } else {
  71. try {
  72. const res: any = await request.post(state.platformApi + '/courseSchedule/myCourseware')
  73. if (Array.isArray(res?.data)) {
  74. const _data = data.actionKey
  75. ? res.data.filter((n: any) => n.courseTypeCode === data.actionKey)
  76. : res.data
  77. data.list = filterData(_data)
  78. }
  79. } catch (error) {}
  80. }
  81. data.loading = false
  82. }
  83. onMounted(() => {
  84. getList()
  85. })
  86. const handleClick = (item: any) => {
  87. if (route.query.code === 'select') {
  88. router.push({
  89. path: '/courseList',
  90. query: {
  91. ...route.query,
  92. id: item.id
  93. }
  94. })
  95. return
  96. }
  97. router.push({
  98. path: '/courseList',
  99. query: {
  100. id: item.id
  101. }
  102. })
  103. }
  104. const actions = computed(() => {
  105. const _list = Object.entries(courseEmnu).map(([key, value]) => {
  106. return {
  107. id: key,
  108. name: value,
  109. text: value,
  110. value: key,
  111. color: key === data.actionKey ? 'var(--van-primary)' : ''
  112. }
  113. })
  114. _list.unshift({
  115. id: '',
  116. name: '课程类型',
  117. text: '全部',
  118. value: '',
  119. color: '' === data.actionKey ? 'var(--van-primary)' : ''
  120. })
  121. return _list
  122. })
  123. const handleSelect = (action: any) => {
  124. data.actionKey = action.id
  125. data.actionName = action.name
  126. data.actionShow = false
  127. getList()
  128. }
  129. return () => (
  130. <div
  131. class={[styles.lessonCourseware, !Object.values(data.list).length && 'emptyRootContainer']}
  132. >
  133. <OSticky
  134. onGetHeight={(height: number) => {
  135. document.documentElement.style.setProperty('--header-height', height + 'px')
  136. }}
  137. >
  138. <OHeader
  139. border={false}
  140. background="rgba(255, 232, 206, 1)"
  141. color="rgba(124, 61, 18, 1)"
  142. title="我的教材"
  143. >
  144. {{
  145. right: () => (
  146. <>
  147. {data.showRight && (
  148. <div class={styles.filter} onClick={() => (data.actionShow = true)}>
  149. {data.actionName} <Icon style={{ transform: 'rotate(90deg)' }} name="play" />{' '}
  150. </div>
  151. )}
  152. </>
  153. )
  154. }}
  155. </OHeader>
  156. </OSticky>
  157. {Object.keys(data.list).map((key: any) => {
  158. return (
  159. <CourseItem term={key} list={data.list[key]} onItemClick={(row) => handleClick(row)} />
  160. )
  161. })}
  162. {!data.loading && !Object.values(data.list).length && <OEmpty tips="没有课件" />}
  163. {/* <ActionSheet
  164. class='popupBottomSearch'
  165. v-model:show={data.actionShow}
  166. cancelText="全部课程类型"
  167. actions={actions.value}
  168. onCancel={() => {
  169. data.actionKey = ''
  170. data.actionName = '课程类型'
  171. getList()
  172. }}
  173. onSelect={handleSelect}
  174. /> */}
  175. <Popup position='bottom' round v-model:show={data.actionShow}>
  176. <Picker class="popupBottomSearch" columns={actions.value} onConfirm={({selectedOptions}) => {
  177. handleSelect(selectedOptions[0])
  178. }} />
  179. </Popup>
  180. </div>
  181. )
  182. }
  183. })