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

150 lines
4.0 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. 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. if(this.$shared.isValueType(tab_item) == 'undefined') return;
  72. this.$http(this.API.API_ADVICELIST,{page: tab_item.page,category_id: tab_item.id}).then(res => {
  73. let isPage = res.data.next_page_url == null?false:true;
  74. tab_item.isPage = isPage;
  75. if(!isPage){
  76. tab_item.loadingClass = false;
  77. tab_item.loadingText = '没有更多数据啦~';
  78. }
  79. tab_item.isRefresher = false;
  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.current = index;
  90. if(this.tab_list[index].list.length <= 0){
  91. this.getData(); // tab下没有数据,请求第一页
  92. }
  93. },
  94. // 滑块下标值变化
  95. swiperChange(event){
  96. this.current = event.detail.current;
  97. if(event.detail.source == '') return; // 如果是被动出发,没有事件类型则不做处理
  98. if(this.tab_list[event.detail.current].list.length <= 0){
  99. this.getData(); // tab下没有数据,请求第一页
  100. }
  101. },
  102. // 页面触底,加载下一页
  103. onScrolltolower(){
  104. let tab_item = this.tab_list[this.current];
  105. if(tab_item.isPage){
  106. tab_item.page = tab_item.page + 1;
  107. this.getData();
  108. }
  109. },
  110. // scroll-view 下拉刷新
  111. onRefresherrefresh(){
  112. this.$u.throttle(() => {
  113. this.clearTabItem();
  114. this.getData();
  115. }, 200);
  116. },
  117. clearTabItem(){
  118. let tab_item = this.tab_list[this.current];
  119. tab_item.page = 1;
  120. tab_item.isPage = true;
  121. tab_item.isRefresher = true;
  122. tab_item.loadingClass = true;
  123. tab_item.loadingText = '正在加载中';
  124. tab_item.list = [];
  125. this.$set(this.tab_list, this.current, tab_item);
  126. this.$refs.uWaterfall[this.current].clear();
  127. }
  128. }
  129. }
  130. </script>
  131. <style>
  132. page{
  133. background-color: #F6F6F6;
  134. }
  135. </style>
  136. <style lang="scss" scoped="scoped">
  137. .head{
  138. background-color: #FFFFFF;
  139. }
  140. .com{
  141. width: 100%;
  142. height: 100%;
  143. box-sizing: border-box;
  144. padding: 0rpx 32rpx;
  145. }
  146. </style>