海南旅游项目 前端仓库
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.

149 lines
4.2 KiB

  1. <template>
  2. <view>
  3. <view class="lf-p-t-20 head" v-if="tab_list.length">
  4. <u-tabs :list="tab_list" :is-scroll="true" :current="current" @change="tabChange"></u-tabs>
  5. </view>
  6. <lf-nocontent v-else></lf-nocontent>
  7. <swiper :style="{height: 'calc('+ windowHeight +'px - 60rpx)', width: '750rpx'}" :current="current" @change="swiperChange">
  8. <swiper-item v-for="(tabItem, tabIndex) in tab_list" :key="tabIndex">
  9. <scroll-view class="com" :scroll-y="true" :refresher-enabled="true" :refresher-triggered="tabItem.isRefresher" @scrolltolower="onScrolltolower" @refresherrefresh="onRefresherrefresh">
  10. <view class="lf-m-t-20"></view>
  11. <lf-waterfall :list="tabItem.list" ref="uWaterfall"></lf-waterfall>
  12. <view class="loading-more lf-m-b-10">
  13. <text :class="{'loading-more-text': tabItem.loadingClass}" v-if="tabItem.list.length">{{tabItem.loadingText}}</text>
  14. <lf-nocontent v-else></lf-nocontent>
  15. <!-- <view>
  16. {{tabItem.list.length}}
  17. </view> -->
  18. </view>
  19. </scroll-view>
  20. </swiper-item>
  21. </swiper>
  22. </view>
  23. </template>
  24. <script>
  25. import lfWaterfall from '@/components/lf-waterfall-recom/lf-waterfall.vue';
  26. export default {
  27. data(){
  28. return {
  29. tab_list: [],
  30. current: 0,
  31. windowHeight: 0
  32. }
  33. },
  34. components: {
  35. lfWaterfall
  36. },
  37. onShow(){
  38. this.windowHeight = getApp().globalData.windowHeight;
  39. this.getCategory()
  40. },
  41. onHide() {
  42. this.$refs.uWaterfall[this.current].clear();
  43. },
  44. methods: {
  45. getCategory(options = {}) {
  46. this.$http(this.API.API_CATEGORYLIST).then(res => {
  47. let res_list = res.data || [];
  48. let tab_list = res_list.map(item => {
  49. return {
  50. id: item.id,
  51. name: item.name,
  52. list: [],
  53. isRefresher: false,
  54. loadingClass: true,
  55. loadingText: '正在加载中',
  56. page: 1,
  57. isPage: true
  58. }
  59. });
  60. if(options.type == 'pageRefresh'){
  61. uni.stopPullDownRefresh();
  62. }else if(options.type == 'scrollRefresh'){
  63. this.tab_list[this.current].isRefresher = false;
  64. }
  65. this.tab_list = tab_list;
  66. this.getData()
  67. }).catch(err => {
  68. })
  69. },
  70. getData() {
  71. let tab_item = this.tab_list[this.current];
  72. if(this.$shared.isValueType(tab_item) == 'undefined') return;
  73. this.$http(this.API.API_ADVICELIST,{page: tab_item.page,category_id: tab_item.id}).then(res => {
  74. let isPage = res.data.next_page_url == null?false:true;
  75. tab_item.isPage = isPage;
  76. if(!isPage){
  77. tab_item.loadingClass = false;
  78. tab_item.loadingText = '没有更多数据啦~';
  79. }
  80. if(tab_item.page == 1){
  81. tab_item.list = res.data.data;
  82. }else{
  83. tab_item.list.push(...res.data.data);
  84. }
  85. }).catch(err => {
  86. })
  87. },
  88. tabChange(index){
  89. this.$refs.uWaterfall[index].clear();
  90. this.tab_list[index].list = [];
  91. // this.getCategory({type: 'pageRefresh'});
  92. console.log(this.$refs)
  93. this.current = index;
  94. if(this.tab_list[index].list.length <= 0){
  95. this.getData(); // tab下没有数据,请求第一页
  96. }
  97. },
  98. // 滑块下标值变化
  99. swiperChange(event){
  100. this.current = event.detail.current;
  101. if(event.detail.source == '') return; // 如果是被动出发,没有事件类型则不做处理
  102. if(this.tab_list[event.detail.current].list.length <= 0){
  103. this.getData(); // tab下没有数据,请求第一页
  104. }
  105. },
  106. // 页面触底,加载下一页
  107. onScrolltolower(){
  108. let tab_item = this.tab_list[this.current];
  109. if(tab_item.isPage){
  110. tab_item.page = tab_item.page + 1;
  111. this.getData();
  112. }
  113. },
  114. // scroll-view 下拉刷新
  115. onRefresherrefresh(){
  116. this.$u.throttle(() => {
  117. this.$refs.uWaterfall[this.current].clear();
  118. this.tab_list[this.current].isRefresher = true;
  119. this.getCategory({type: 'scrollRefresh'});
  120. }, 200);
  121. },
  122. // page 下拉刷新
  123. onPullDownRefresh(){
  124. // 新版逻辑,刷新则整个数据全部重新获取
  125. this.getCategory({type: 'pageRefresh'});
  126. },
  127. }
  128. }
  129. </script>
  130. <style>
  131. page{
  132. background-color: #F6F6F6;
  133. }
  134. </style>
  135. <style lang="scss" scoped="scoped">
  136. .head{
  137. background-color: #FFFFFF;
  138. }
  139. .com{
  140. width: 100%;
  141. height: 100%;
  142. box-sizing: border-box;
  143. padding: 0rpx 32rpx;
  144. }
  145. </style>