index.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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: 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. ...n,
  62. coverImg: n.coverImg,
  63. name: n.coursewareName,
  64. id: n.lessonCoursewareId,
  65. courseNum: n.coursewareNum
  66. }
  67. })
  68. data.list = filterData(_data)
  69. console.log("🚀 ~ data.list:", data.list)
  70. }
  71. } catch (error) {}
  72. } else {
  73. try {
  74. const res: any = await request.post(state.platformApi + '/courseSchedule/myCourseware')
  75. if (Array.isArray(res?.data)) {
  76. const _data = data.actionKey
  77. ? res.data.filter((n: any) => n.courseTypeCode === data.actionKey)
  78. : res.data
  79. data.list = filterData(_data)
  80. }
  81. } catch (error) {}
  82. }
  83. data.loading = false
  84. }
  85. onMounted(() => {
  86. getList()
  87. })
  88. const handleClick = (item: any) => {
  89. if (route.query.code === 'select') {
  90. router.push({
  91. path: '/courseList',
  92. query: {
  93. ...route.query,
  94. id: item.id
  95. }
  96. })
  97. return
  98. }
  99. router.push({
  100. path: '/courseList',
  101. query: {
  102. id: item.id
  103. }
  104. })
  105. }
  106. const actions = computed(() => {
  107. const _list = Object.entries(courseEmnu).map(([key, value]) => {
  108. return {
  109. id: key,
  110. name: value,
  111. text: value,
  112. value: key,
  113. color: key === data.actionKey ? 'var(--van-primary)' : ''
  114. }
  115. })
  116. _list.unshift({
  117. id: '',
  118. name: '课程类型',
  119. text: '全部',
  120. value: '',
  121. color: '' === data.actionKey ? 'var(--van-primary)' : ''
  122. })
  123. return _list
  124. })
  125. const handleSelect = (action: any) => {
  126. data.actionKey = action.id
  127. data.actionName = action.name
  128. data.actionShow = false
  129. getList()
  130. }
  131. return () => (
  132. <div
  133. class={[styles.lessonCourseware, !Object.values(data.list).length && 'emptyRootContainer']}
  134. >
  135. <OSticky
  136. onGetHeight={(height: number) => {
  137. document.documentElement.style.setProperty('--header-height', height + 'px')
  138. }}
  139. >
  140. <OHeader
  141. border={false}
  142. background="rgba(255, 232, 206, 1)"
  143. color="rgba(124, 61, 18, 1)"
  144. title="云教材"
  145. >
  146. {{
  147. right: () => (
  148. <>
  149. {data.showRight && (
  150. <div class={styles.filter} onClick={() => (data.actionShow = true)}>
  151. {data.actionName} <Icon style={{ transform: 'rotate(90deg)' }} name="play" />{' '}
  152. </div>
  153. )}
  154. </>
  155. )
  156. }}
  157. </OHeader>
  158. </OSticky>
  159. {Object.keys(data.list).map((key: any) => {
  160. return (
  161. <CourseItem term={key} list={data.list[key]} onItemClick={(row) => handleClick(row)} />
  162. )
  163. })}
  164. {!data.loading && !Object.values(data.list).length && <OEmpty tips="没有课件" />}
  165. <Popup position="bottom" round v-model:show={data.actionShow}>
  166. <Picker
  167. class="popupBottomSearch"
  168. columns={actions.value}
  169. onCancel={() => (data.actionShow = false)}
  170. onConfirm={({ selectedOptions }) => {
  171. handleSelect(selectedOptions[0])
  172. }}
  173. />
  174. </Popup>
  175. </div>
  176. )
  177. }
  178. })