index.tsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import ColEmpty from '@/components/col-empty'
  2. import Pagination from '@/components/pagination'
  3. import request from '@/helpers/request'
  4. import { ElImage, ElMessage, ElMessageBox, ElSkeleton, ElSkeletonItem, ElTag } from 'element-plus'
  5. import { defineComponent } from 'vue'
  6. import styles from './index.module.less'
  7. import iconVip from '../images/icon_vip.png'
  8. import iconSvip from '../images/icon_svip.png'
  9. import iconVipDefault from '../images/icon_vip_default.png'
  10. import { getUserInfo } from '@/state'
  11. export default defineComponent({
  12. name: 'MyFans',
  13. data() {
  14. return {
  15. pageInfo: {
  16. // 分页规则
  17. limit: 12, // 限制显示条数
  18. page: 1, // 当前页
  19. total: 0, // 总条数
  20. page_size: [12, 24, 48, 60] // 选择限制显示条数
  21. },
  22. list: [] as any[],
  23. loading: false,
  24. dataShow: false // 是否有数据
  25. }
  26. },
  27. mounted() {
  28. this.getList()
  29. },
  30. methods: {
  31. async getList() {
  32. this.loading = true
  33. try {
  34. const { data } = await request.post(
  35. '/api-website/teacher/queryMyFans',
  36. {
  37. requestType: 'json',
  38. data: {
  39. page: this.pageInfo.page,
  40. rows: this.pageInfo.limit
  41. }
  42. }
  43. )
  44. this.list = data.rows || []
  45. this.pageInfo.total = data.total
  46. if (data.total <= 0) {
  47. this.dataShow = true
  48. }
  49. } catch {}
  50. if (this.dataShow) {
  51. this.loading = false
  52. } else {
  53. setTimeout(() => {
  54. this.loading = false
  55. }, 200)
  56. }
  57. },
  58. onRemove(item: any) {
  59. ElMessageBox.confirm(`确定移除该粉丝吗?`, '提示', {
  60. confirmButtonText: '确定',
  61. cancelButtonText: '取消',
  62. type: 'warning'
  63. }).then(async () => {
  64. try {
  65. await request.post('/api-teacher/teacher/delFans/' + item.userId)
  66. await getUserInfo()
  67. ElMessage.success('移除成功')
  68. this.pageInfo.page = 1
  69. this.getList()
  70. } catch {}
  71. })
  72. }
  73. },
  74. render() {
  75. return (
  76. <div class="rounded-md overflow-hidden">
  77. <div class="text-2xl font-semibold text-black leading-none px-6 py-5 ">
  78. 我的粉丝
  79. </div>
  80. <div class={!this.dataShow && 'pt-4'}>
  81. <ElSkeleton
  82. loading={this.loading}
  83. animated
  84. class=" w-full m-auto px-[14px] flex"
  85. count={4}
  86. v-slots={{
  87. template: () => (
  88. <div class="w-[158px] rounded-[10px] pt-10 pb-7 mb-4 m-auto flex items-center justify-center flex-col user-shadow relative">
  89. <ElSkeletonItem
  90. variant="circle"
  91. style={{ width: '48px', height: '48px' }}
  92. ></ElSkeletonItem>
  93. <ElSkeletonItem
  94. variant="h3"
  95. style={{
  96. width: '50%',
  97. marginTop: '8px',
  98. marginBottom: '20px'
  99. }}
  100. ></ElSkeletonItem>
  101. <ElSkeletonItem
  102. variant="p"
  103. style={{ width: '60%', marginTop: '6px' }}
  104. ></ElSkeletonItem>
  105. </div>
  106. )
  107. }}
  108. >
  109. <div class="flex flex-wrap px-3">
  110. {this.list.map((item: any) => (
  111. <div class="basis-1/4 ">
  112. <div class="w-[158px] rounded-[10px] pt-10 pb-7 mb-4 m-auto flex items-center justify-center flex-col user-shadow relative">
  113. <div class="bg-[#FFE7CF] absolute left-2.5 top-2.5 text-[#AB5400] text-xs py-0.5 px-2 rounded-[10px]">
  114. 学生
  115. </div>
  116. <div class="flex flex-col items-center" style="position: relative">
  117. <ElImage
  118. src={item.avatar}
  119. class={['w-12 h-12 rounded-full border-2 border-[#FFFFFF]', item.vipType !== 'NORMAL' ? item.vipType === 'VIP' ? 'border-[#FADA9B]' : 'border-[#F0AF88]' : '' ]}
  120. />
  121. {item.vipType && item.vipType !== 'NORMAL' && (
  122. <ElImage
  123. style="position: absolute;bottom: -5px; height: 18px;"
  124. src={item.vipType === 'VIP' ? iconVip : iconSvip}
  125. class="-mt-4"
  126. />
  127. )}
  128. </div>
  129. <p class="text-base text-[#333] font-semibold leading-tight pb-1 pt-2 text-center max-w-[120px] whitespace-nowrap overflow-hidden text-ellipsis" title={item.userName}>
  130. {item.userName}
  131. </p>
  132. <p class="h-6">
  133. {item.subjectName && (
  134. <span style="font-size: 12px;color: #777777;">{item.subjectName}</span>
  135. )}
  136. </p>
  137. <p>
  138. <span class={styles.removeBtn} onClick={() => this.onRemove(item)}>移除</span>
  139. </p>
  140. </div>
  141. </div>
  142. ))}
  143. </div>
  144. </ElSkeleton>
  145. </div>
  146. <Pagination
  147. total={this.pageInfo.total}
  148. v-model:page={this.pageInfo.page}
  149. v-model:limit={this.pageInfo.limit}
  150. pageSizes={this.pageInfo.page_size}
  151. pagination={this.getList}
  152. />
  153. {this.dataShow && <ColEmpty />}
  154. </div>
  155. )
  156. }
  157. })