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

164 lines
4.6 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 - 260rpx)', 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. pid: item.pid
  63. }
  64. });
  65. let list = []
  66. tab_list.forEach((item,index) => {
  67. if(item.pid == 0) {
  68. list.push(item)
  69. }
  70. })
  71. this.tab_list = list;
  72. console.log(this.tab_list)
  73. this.getData()
  74. }).catch(err => {
  75. })
  76. },
  77. getData() {
  78. let tab_item = this.tab_list[this.current];
  79. console.log('页数',tab_item.page)
  80. if(this.$shared.isValueType(tab_item) == 'undefined') return;
  81. this.$http(this.API.API_ADVICELIST,{page: tab_item.page,category_id: tab_item.id}).then(res => {
  82. let isPage = res.data.next_page_url == null?false:true;
  83. tab_item.isPage = isPage;
  84. if(!isPage){
  85. tab_item.loadingClass = false;
  86. tab_item.loadingText = '没有更多数据啦~';
  87. }
  88. tab_item.isRefresher = false;
  89. if(tab_item.page == 1){
  90. tab_item.list = res.data.data;
  91. }else{
  92. tab_item.list.push(...res.data.data);
  93. }
  94. }).catch(err => {
  95. })
  96. },
  97. tabChange(index){
  98. this.current = index;
  99. this.clearTabItem()
  100. console.log(this.$refs)
  101. console.log('当前数据',this.tab_list[index])
  102. console.log('组件中的数据',this.$refs.uWaterfallFather[this.current].dataList)
  103. if(this.tab_list[index].list.length <= 0){
  104. this.getData(); // tab下没有数据,请求第一页
  105. }
  106. },
  107. // 滑块下标值变化
  108. swiperChange(event){
  109. this.current = event.detail.current;
  110. if(event.detail.source == '') return; // 如果是被动出发,没有事件类型则不做处理
  111. if(this.tab_list[event.detail.current].list.length <= 0){
  112. this.getData(); // tab下没有数据,请求第一页
  113. }
  114. },
  115. // 页面触底,加载下一页
  116. onScrolltolower(){
  117. let tab_item = this.tab_list[this.current];
  118. if(tab_item.isPage){
  119. tab_item.page = tab_item.page + 1;
  120. this.getData();
  121. }
  122. },
  123. // scroll-view 下拉刷新
  124. onRefresherrefresh(){
  125. this.$u.throttle(() => {
  126. this.clearTabItem();
  127. this.getData();
  128. }, 200);
  129. },
  130. clearTabItem(){
  131. let tab_item = this.tab_list[this.current];
  132. tab_item.page = 1;
  133. tab_item.isPage = true;
  134. tab_item.isRefresher = true;
  135. tab_item.loadingClass = true;
  136. tab_item.loadingText = '正在加载中';
  137. tab_item.list = [];
  138. this.$set(this.tab_list, this.current, tab_item);
  139. this.$refs.uWaterfallFather[this.current].clear();
  140. console.log('当前方法删除',this.$refs.uWaterfallFather[this.current])
  141. }
  142. }
  143. }
  144. </script>
  145. <style>
  146. page{
  147. background-color: #F6F6F6;
  148. }
  149. </style>
  150. <style lang="scss" scoped="scoped">
  151. .head{
  152. background-color: #FFFFFF;
  153. }
  154. .com{
  155. width: 100%;
  156. height: 100%;
  157. box-sizing: border-box;
  158. padding: 0rpx 32rpx;
  159. }
  160. </style>