index.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import { Button, Cell, CellGroup, Col, Row } from 'vant'
  2. import { defineComponent } from 'vue'
  3. import styles from './index.module.less'
  4. import iconTimer from '@/common/images/icon_timer2.png'
  5. import dayjs from 'dayjs'
  6. import { courseType } from '@/constant'
  7. import { postMessage } from '@/helpers/native-message'
  8. export const getAssetsHomeFile = (fileName: string) => {
  9. const path = `../../images/${fileName}`
  10. const modules = import.meta.globEager('../../images/*')
  11. return modules[path].default
  12. }
  13. export default defineComponent({
  14. name: 'course',
  15. props: {
  16. item: {
  17. type: Object
  18. },
  19. operation: {
  20. type: Boolean,
  21. default: true
  22. },
  23. // 学员调整
  24. onStudentAdjust: {
  25. type: Function,
  26. default: (item: any) => {}
  27. },
  28. // 时间调整
  29. onTimeAdjust: {
  30. type: Function,
  31. default: (item: any) => {}
  32. },
  33. // 删除课程
  34. onCourseDelete: {
  35. type: Function,
  36. default: (item: any) => {}
  37. }
  38. },
  39. computed: {
  40. timer() {
  41. const item: any = this.item
  42. return (
  43. dayjs(item.startTime).format('YYYY/MM/DD HH:mm') +
  44. ' ~ ' +
  45. dayjs(item.endTime).format('HH:mm')
  46. )
  47. }
  48. },
  49. methods: {
  50. onJoinChat(e: any) {
  51. e.stopPropagation()
  52. const item: any = this.item
  53. // 进入聊天
  54. postMessage({
  55. api: 'joinChatGroup',
  56. content: {
  57. type: 'multi', // single 单人 multi 多人
  58. id: item.imGroupId,
  59. role: 'TEACHER'
  60. }
  61. })
  62. },
  63. onDetail() {
  64. // 详情
  65. postMessage({
  66. api: 'openCourseDetail',
  67. content: {
  68. type: 'pianoRoom',
  69. courseId: this.item?.courseId
  70. }
  71. })
  72. }
  73. },
  74. render() {
  75. const item: any = this.item
  76. return (
  77. <CellGroup class={styles.course} border={false}>
  78. <Cell
  79. center
  80. class={styles.courseItem}
  81. onClick={this.onDetail}
  82. v-slots={{
  83. title: () => (
  84. <div class={styles.courseTimer}>
  85. <img src={iconTimer} />
  86. <span>{this.timer}</span>
  87. </div>
  88. ),
  89. value: () => (
  90. <div class={styles.courseNum}>
  91. <span>{item.studentCount}人</span>
  92. <img
  93. src={getAssetsHomeFile('icon_num.png')}
  94. style={{ marginRight: '14px' }}
  95. />
  96. {this.operation ? (
  97. <img
  98. onClick={this.onJoinChat}
  99. src={getAssetsHomeFile('icon_message.png')}
  100. />
  101. ) : (
  102. <span class={styles.munis}>-{item.consumTime}分钟</span>
  103. )}
  104. </div>
  105. )
  106. }}
  107. />
  108. <Cell>
  109. <div class={styles.courseInfo} onClick={this.onDetail}>
  110. <div class={styles.courseImg}>小课</div>
  111. <div class={styles.courseName}>
  112. <p class={styles.name}>{item.groupName}</p>
  113. <p>
  114. <span class={styles.subject}>{item.subjectName}</span>
  115. </p>
  116. </div>
  117. <Button
  118. type={item.status !== 'NOT_START' ? 'default' : 'primary'}
  119. round
  120. disabled
  121. size="small"
  122. >
  123. {courseType[item.status]}
  124. </Button>
  125. </div>
  126. {this.operation && (
  127. <Row class={styles.courseOperation}>
  128. <Col span={8} class="van-hairline--right">
  129. <span
  130. onClick={() => {
  131. this.onStudentAdjust(this.item)
  132. }}
  133. >
  134. 学员调整
  135. </span>
  136. </Col>
  137. <Col span={8} class="van-hairline--right">
  138. <span
  139. onClick={() => {
  140. this.onTimeAdjust(this.item)
  141. }}
  142. >
  143. 时间调整
  144. </span>
  145. </Col>
  146. <Col span={8}>
  147. <span
  148. onClick={() => {
  149. this.onCourseDelete(this.item)
  150. }}
  151. >
  152. 删除课程
  153. </span>
  154. </Col>
  155. </Row>
  156. )}
  157. </Cell>
  158. </CellGroup>
  159. )
  160. }
  161. })