时空网前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.3 KiB

  1. <template>
  2. <view>
  3. <view class="bg-white lf-p-t-40 lf-p-b-40 flex justify-around align-center text-center solid-bottom">
  4. <view class="tab-item"
  5. :class="current==index?'text-orange':'text-black1'"
  6. v-for="(item, index) in tab_list" :key="index"
  7. @click="changeTab(index)">{{ item.name }}
  8. </view>
  9. </view>
  10. <scroll-view :style="{height: 'calc('+ windowHeight +'px - 120rpx)'}"
  11. :scroll-y="true" :refresher-enabled="true"
  12. :refresher-triggered="isRefresher"
  13. @scrolltolower="onScrolltolower"
  14. @refresherrefresh="onRefresherrefresh"
  15. v-for="(tabItem, tabIndex) in tab_list" :key="tabIndex"
  16. v-if="tabIndex == current">
  17. <view class="flex lf-p-30 solid-bottom" v-for="(item, index) in tabItem.list" :key="index">
  18. <view>
  19. <image :src="item.avatar" style="height: 120rpx;width: 120rpx;" mode="aspectFill"></image>
  20. </view>
  21. <view class="flex flex-direction justify-around lf-p-l-20">
  22. <view class="lf-font-32 text-black1">{{item.username}} <text class="bg-red lf-font-24 lf-m-l-10" style="border-radius: 30rpx;padding: 5rpx 16rpx;">{{item.state}}</text></view>
  23. <view class="lf-font-24 lf-color-gray">{{item.created_at}}</view>
  24. </view>
  25. </view>
  26. <!-- 空数据的情况 -->
  27. <view class="loading-more">
  28. <text v-if="tabItem.list.length" :class="{'loading-more-text': tabItem.loadingClass}">{{ tabItem.loadingText }}</text>
  29. <my-nocontent v-else></my-nocontent>
  30. </view>
  31. </scroll-view>
  32. </view>
  33. </template>
  34. <script>
  35. export default {
  36. data() {
  37. return {
  38. current: 0, // tab下标
  39. pageSize: 10,
  40. isRefresher: false, // scroll-view下拉刷新状态,当前默认没有触发
  41. windowHeight: 0,
  42. tab_list: [{
  43. name: '内部粉丝',
  44. list: [],
  45. page: 1,
  46. isPage: false,
  47. loadingClass: false,
  48. loadingText: '已加载全部数据'
  49. },{
  50. name: '外部粉丝',
  51. list: [],
  52. page: 1,
  53. isPage: false,
  54. loadingClass: true,
  55. loadingText: '正在加载中'
  56. }]
  57. }
  58. },
  59. onLoad(){
  60. this.windowHeight = uni.getSystemInfoSync().windowHeight;
  61. this.getInFans()
  62. },
  63. methods: {
  64. changeTab(index) {
  65. if(this.current == index) {
  66. return
  67. }else {
  68. this.current = index
  69. this.getInFans()
  70. }
  71. },
  72. getInFans() {
  73. let per_page = this.pageSize;
  74. let tab_item = this.tab_list[this.current];
  75. let fansType = this.current+1
  76. this.$http(this.API.API_FANS, {
  77. page: tab_item.page,
  78. limit: per_page,
  79. type: fansType
  80. }).then(res => {
  81. this.isRefresher = false;
  82. let isPage = res.data.has_more_page;
  83. tab_item.isPage = isPage;
  84. if(!isPage){
  85. tab_item.loadingClass = false;
  86. tab_item.loadingText = '没有更多数据啦~';
  87. }
  88. if(tab_item.page == 1){
  89. tab_item.list = res.data.items;
  90. }else{
  91. tab_item.list.push(...res.data.items);
  92. }
  93. })
  94. },
  95. // 页面触底,加载下一页
  96. onScrolltolower(){
  97. let tab_item = this.tab_list[this.current];
  98. if(tab_item.isPage){
  99. tab_item.page = tab_item.page + 1;
  100. this.getInFans()
  101. }
  102. },
  103. // scroll-view 下拉刷新
  104. onRefresherrefresh(){
  105. this.isRefresher = true;
  106. this.getInFans()
  107. }
  108. }
  109. }
  110. </script>
  111. <style lang="scss" scoped>
  112. .tab-item{
  113. width: 50%;
  114. box-sizing: border-box;
  115. font-size: 32rpx;
  116. &:first-child{
  117. border-right: 2rpx solid rgba(0, 0, 0, 0.1);
  118. }
  119. }
  120. </style>