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

156 lines
4.4 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" :listlength="tab_list.length" :tabindex='tabIndex' ref="uWaterfallFather"></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. show_count: 0
  33. }
  34. },
  35. components: {
  36. lfWaterfall
  37. },
  38. onShow(){
  39. this.windowHeight = getApp().globalData.windowHeight;
  40. if(this.show_count >= 1){
  41. this.clearTabItem();
  42. this.getData();
  43. }else{
  44. this.getCategory();
  45. }
  46. this.show_count++;
  47. },
  48. methods: {
  49. getCategory(options = {}) {
  50. this.$http(this.API.API_CATEGORYLIST).then(res => {
  51. let res_list = res.data || [];
  52. let tab_list = res_list.map(item => {
  53. return {
  54. id: item.id,
  55. name: item.name,
  56. list: [],
  57. isRefresher: false,
  58. loadingClass: true,
  59. loadingText: '正在加载中',
  60. page: 1,
  61. isPage: true
  62. }
  63. });
  64. this.tab_list = tab_list;
  65. this.getData()
  66. }).catch(err => {
  67. })
  68. },
  69. getData() {
  70. let tab_item = this.tab_list[this.current];
  71. console.log('页数',tab_item.page)
  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. tab_item.isRefresher = false;
  81. if(tab_item.page == 1){
  82. tab_item.list = res.data.data;
  83. }else{
  84. tab_item.list.push(...res.data.data);
  85. }
  86. }).catch(err => {
  87. })
  88. },
  89. tabChange(index){
  90. this.current = index;
  91. this.clearTabItem()
  92. console.log(this.$refs)
  93. console.log('当前数据',this.tab_list[index])
  94. console.log('组件中的数据',this.$refs.uWaterfallFather[this.current].dataList)
  95. if(this.tab_list[index].list.length <= 0){
  96. this.getData(); // tab下没有数据,请求第一页
  97. }
  98. },
  99. // 滑块下标值变化
  100. swiperChange(event){
  101. this.current = event.detail.current;
  102. if(event.detail.source == '') return; // 如果是被动出发,没有事件类型则不做处理
  103. if(this.tab_list[event.detail.current].list.length <= 0){
  104. this.getData(); // tab下没有数据,请求第一页
  105. }
  106. },
  107. // 页面触底,加载下一页
  108. onScrolltolower(){
  109. let tab_item = this.tab_list[this.current];
  110. if(tab_item.isPage){
  111. tab_item.page = tab_item.page + 1;
  112. this.getData();
  113. }
  114. },
  115. // scroll-view 下拉刷新
  116. onRefresherrefresh(){
  117. this.$u.throttle(() => {
  118. this.clearTabItem();
  119. this.getData();
  120. }, 200);
  121. },
  122. clearTabItem(){
  123. let tab_item = this.tab_list[this.current];
  124. tab_item.page = 1;
  125. tab_item.isPage = true;
  126. tab_item.isRefresher = true;
  127. tab_item.loadingClass = true;
  128. tab_item.loadingText = '正在加载中';
  129. tab_item.list = [];
  130. this.$set(this.tab_list, this.current, tab_item);
  131. this.$refs.uWaterfallFather[this.current].clear();
  132. console.log('当前方法删除',this.$refs.uWaterfallFather[this.current])
  133. }
  134. }
  135. }
  136. </script>
  137. <style>
  138. page{
  139. background-color: #F6F6F6;
  140. }
  141. </style>
  142. <style lang="scss" scoped="scoped">
  143. .head{
  144. background-color: #FFFFFF;
  145. }
  146. .com{
  147. width: 100%;
  148. height: 100%;
  149. box-sizing: border-box;
  150. padding: 0rpx 32rpx;
  151. }
  152. </style>