index.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import ColHeader from '@/components/col-header'
  2. import ColSearch from '@/components/col-search'
  3. import { Sticky, Image, List, Icon, Popup } from 'vant'
  4. import { defineComponent } from 'vue'
  5. import styles from './index.module.less'
  6. import request from '@/helpers/request'
  7. import ColResult from '@/components/col-result'
  8. import LiveItem from './live-item'
  9. import banner from '../video-class/images/banner.png'
  10. import { state } from '@/state'
  11. import OrganSearch from '../practice-class/model/organ-search'
  12. import { useEventTracking } from '@/helpers/hooks'
  13. export default defineComponent({
  14. name: 'liveClass',
  15. data() {
  16. const sessionSubjectId = sessionStorage.getItem('liveClassSubjectId')
  17. return {
  18. list: [],
  19. dataShow: true, // 判断是否有数据
  20. loading: false,
  21. finished: false,
  22. searchStatus: false,
  23. openStatus: false,
  24. subjectList: [],
  25. sessionSubjectId,
  26. params: {
  27. search: '',
  28. courseType: "GROUP",
  29. subjectId: (sessionSubjectId ||
  30. state.user.data?.subjectId ||
  31. null) as any,
  32. subjectName: '',
  33. groupStatus: 'APPLY',
  34. page: 1,
  35. rows: 20
  36. }
  37. }
  38. },
  39. async mounted() {
  40. try {
  41. const res = await request.get('/api-student/subject/subjectSelect')
  42. this.subjectList = res.data || []
  43. } catch {}
  44. let subjectName = ''
  45. this.subjectList.forEach((item: any) => {
  46. item.subjects?.forEach((child: any) => {
  47. if (child.id === Number(this.sessionSubjectId)) {
  48. subjectName = child.name
  49. }
  50. })
  51. })
  52. this.params.subjectName = subjectName || state.user.data?.subjectName || ''
  53. sessionStorage.removeItem('liveClassSubjectId')
  54. useEventTracking('直播课')
  55. },
  56. methods: {
  57. onSort() {
  58. this.params.page = 1
  59. this.list = []
  60. this.dataShow = true // 判断是否有数据
  61. this.loading = false
  62. this.finished = false
  63. this.searchStatus = false
  64. this.getList()
  65. },
  66. onSearch(value: string) {
  67. this.params.search = value
  68. this.onSort()
  69. },
  70. async getList() {
  71. try {
  72. const params: any = {
  73. ...this.params
  74. }
  75. if (state.version) {
  76. params.version = state.version || '' // 处理ios审核版本
  77. params.platform = 'ios-student'
  78. }
  79. const res = await request.post(
  80. '/api-student/courseGroup/queryPageCourseGroup',
  81. {
  82. data: {
  83. ...params
  84. }
  85. }
  86. )
  87. this.loading = false
  88. const result = res.data || {}
  89. // 处理重复请求数据
  90. if (this.list.length > 0 && result.pageNo === 1) {
  91. return
  92. }
  93. this.list = this.list.concat(result.rows || [])
  94. this.finished = result.pageNo >= result.totalPage
  95. this.params.page = result.pageNo + 1
  96. this.dataShow = this.list.length > 0
  97. } catch {
  98. this.dataShow = false
  99. this.finished = true
  100. }
  101. },
  102. onDetail(item: any) {
  103. this.params.subjectId &&
  104. sessionStorage.setItem('liveClassSubjectId', this.params.subjectId)
  105. this.$router.push({
  106. path: '/groupDetail',
  107. query: {
  108. groupId: item.courseGroupId
  109. }
  110. })
  111. }
  112. },
  113. render() {
  114. return (
  115. <div class={styles.liveClass}>
  116. <Sticky offsetTop={0} position="top">
  117. <ColHeader
  118. class={styles.classHeader}
  119. border={false}
  120. isFixed={false}
  121. background="transparent"
  122. />
  123. <ColSearch
  124. placeholder="请输入老师名称/课程名称"
  125. onSearch={this.onSearch}
  126. v-slots={{
  127. left: () => (
  128. <div
  129. class={styles.label}
  130. onClick={() => {
  131. this.searchStatus = !this.searchStatus
  132. this.openStatus = !this.openStatus
  133. }}
  134. >
  135. {this.params.subjectName}
  136. <Icon
  137. classPrefix="iconfont"
  138. name="down"
  139. size={12}
  140. color="#333"
  141. />
  142. </div>
  143. )
  144. }}
  145. />
  146. </Sticky>
  147. <div class={styles.banner}>
  148. <Image src={banner} />
  149. </div>
  150. {this.dataShow ? (
  151. <List
  152. v-model:loading={this.loading}
  153. finished={this.finished}
  154. finishedText=" "
  155. class={[styles.liveList]}
  156. onLoad={this.getList}
  157. >
  158. {this.list.map((item: any) => (
  159. <LiveItem onClick={this.onDetail} liveInfo={item} />
  160. ))}
  161. </List>
  162. ) : (
  163. <ColResult btnStatus={false} classImgSize="SMALL" tips="暂无小组课" />
  164. )}
  165. <Popup
  166. show={this.searchStatus}
  167. position="bottom"
  168. round
  169. closeable
  170. safe-area-inset-bottom
  171. onClose={() => (this.searchStatus = false)}
  172. onClosed={() => (this.openStatus = false)}
  173. >
  174. {this.openStatus && (
  175. <OrganSearch
  176. subjectList={this.subjectList}
  177. onSort={this.onSort}
  178. v-model={this.params.subjectId}
  179. v-model:subjectName={this.params.subjectName}
  180. />
  181. )}
  182. </Popup>
  183. </div>
  184. )
  185. }
  186. })