item.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import { defineComponent } from 'vue'
  2. import styles from './index.module.less'
  3. import iconTeacher from '@/common/images/icon_teacher.png'
  4. import {
  5. ElButton,
  6. ElImage,
  7. ElMessage,
  8. ElMessageBox,
  9. ElRate,
  10. ElTag
  11. } from 'element-plus'
  12. // import iconVip from '../images/icon_vip.png'
  13. import iconVip from '../../user-info/images/icon_vip.png'
  14. import iconVipDefault from '../../user-info/images/icon_vip_default.png'
  15. import request from '@/helpers/request'
  16. export const getAssetsHomeFile = (fileName: string) => {
  17. const path = `../../user-info/images/${fileName}`
  18. const modules = import.meta.globEager('../../user-info/images/*')
  19. return modules[path].default
  20. }
  21. export default defineComponent({
  22. name: 'item',
  23. props: {
  24. item: {
  25. type: Object,
  26. default: {}
  27. },
  28. getList: {
  29. type: Function,
  30. default: () => {}
  31. }
  32. },
  33. computed: {
  34. subjects() {
  35. const { subjectName } = this.item
  36. return subjectName.split(',') || []
  37. }
  38. },
  39. methods: {
  40. async onUnLike() {
  41. // console.log(this.item)
  42. ElMessageBox.confirm('确定取消关注吗?', '提示').then(async () => {
  43. try {
  44. await request.get('/api-website/student/starOrUnStar', {
  45. params: {
  46. userId: this.item.userId,
  47. starStatus: 0
  48. }
  49. })
  50. ElMessage.success('取消关注成功')
  51. this.getList()
  52. } catch {
  53. //
  54. }
  55. })
  56. },
  57. checkBadge(type: string) {
  58. // tag : 老师点亮图标
  59. // STYLE:个人风采
  60. // VIDEO:视频课
  61. // LIVE:直播课,
  62. // MUSIC:曲目 逗号隔开
  63. let status = false
  64. const { teacher } = this.item
  65. switch (type) {
  66. case 'STYLE':
  67. case 'VIDEO':
  68. case 'LIVE':
  69. case 'MUSIC':
  70. if (teacher && teacher.tag) {
  71. status = teacher.tag.indexOf(type) > -1
  72. }
  73. break
  74. case 'VIP':
  75. if (teacher) {
  76. status = teacher.isVip > 0
  77. }
  78. break
  79. default:
  80. status = false
  81. break
  82. }
  83. return status
  84. }
  85. },
  86. render() {
  87. const item = this.item
  88. return (
  89. <div class="w-[334px] rounded-[10px] mb-4 m-auto user-shadow relative">
  90. <div class="bg-[#CFF2FF] absolute right-4 top-5 text-[#0089B9] text-xs py-0.5 px-2 rounded-[10px]">
  91. 老师
  92. </div>
  93. <div class="p-[18px] flex">
  94. <ElImage
  95. src={item.avatar || iconTeacher}
  96. class="w-12 h-12 rounded-full border-2 border-[#2DC7AA] object-cover"
  97. />
  98. <div class="flex flex-col pl-5">
  99. <p class="text-base text-[#333] font-semibold leading-tight pb-0">
  100. {item.userName}
  101. </p>
  102. <div class="flex items-center">
  103. {/* <ElImage
  104. src={
  105. this.checkBadge('VIP')
  106. ? getAssetsHomeFile('icon_vip.png')
  107. : getAssetsHomeFile('icon_vip_default.png')
  108. }
  109. class="h-7 -ml-1"
  110. /> */}
  111. <img
  112. src={
  113. this.checkBadge('STYLE')
  114. ? getAssetsHomeFile('icon_cert.png')
  115. : getAssetsHomeFile('icon_cert_default.png')
  116. }
  117. class="h-[26px] -ml-1"
  118. />
  119. <img
  120. src={
  121. this.checkBadge('VIDEO')
  122. ? getAssetsHomeFile('icon_video.png')
  123. : getAssetsHomeFile('icon_video_default.png')
  124. }
  125. class="h-[26px] px-1"
  126. />
  127. <img
  128. src={
  129. this.checkBadge('LIVE')
  130. ? getAssetsHomeFile('icon_live.png')
  131. : getAssetsHomeFile('icon_live_default.png')
  132. }
  133. class="h-[26px] px-1"
  134. />
  135. <img
  136. src={
  137. this.checkBadge('MUSIC')
  138. ? getAssetsHomeFile('icon_music.png')
  139. : getAssetsHomeFile('icon_music_default.png')
  140. }
  141. class="h-[26px] px-1"
  142. />
  143. </div>
  144. </div>
  145. </div>
  146. <p class="mx-4 mb-3">
  147. {this.subjects.map(subject => (
  148. <ElTag
  149. effect="dark"
  150. size="small"
  151. color="#E0FEF9"
  152. round
  153. style={{
  154. borderColor: '#E0FEF9',
  155. color: '#1B967E',
  156. margin: '0 4px 8px'
  157. }}
  158. >
  159. {subject}
  160. </ElTag>
  161. ))}
  162. </p>
  163. <div class="border-[#E7E6E6] border-t block mx-2.5 pt-1 pb-2 text-center">
  164. <ElButton
  165. type="text"
  166. plain
  167. size="small"
  168. class="!bg-white !text-[#999999] hover:!text-[#FF8B00]"
  169. onClick={this.onUnLike}
  170. >
  171. 取消关注
  172. </ElButton>
  173. </div>
  174. </div>
  175. )
  176. }
  177. })