海南旅游项目 前端仓库
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.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="false" :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. methods: {
  42. getCategory(options = {}) {
  43. this.$http(this.API.API_CATEGORYLIST).then(res => {
  44. let res_list = res.data || [];
  45. let tab_list = res_list.map(item => {
  46. return {
  47. id: item.id,
  48. name: item.name,
  49. list: [],
  50. isRefresher: false,
  51. loadingClass: true,
  52. loadingText: '正在加载中',
  53. page: 1,
  54. isPage: true
  55. }
  56. });
  57. if(options.type == 'pageRefresh'){
  58. uni.stopPullDownRefresh();
  59. }else if(options.type == 'scrollRefresh'){
  60. this.tab_list[this.current].isRefresher = false;
  61. }
  62. this.tab_list = tab_list;
  63. this.getData()
  64. }).catch(err => {
  65. })
  66. },
  67. getData() {
  68. let tab_item = this.tab_list[this.current];
  69. if(this.$shared.isValueType(tab_item) == 'undefined') return;
  70. this.$http(this.API.API_ADVICELIST,{page: tab_item.page,category_id: tab_item.id}).then(res => {
  71. let isPage = res.data.next_page_url == null?false:true;
  72. tab_item.isPage = isPage;
  73. if(!isPage){
  74. tab_item.loadingClass = false;
  75. tab_item.loadingText = '没有更多数据啦~';
  76. }
  77. console.log('page',tab_item.page)
  78. if(tab_item.page == 1){
  79. console.log('zhix1')
  80. tab_item.list = res.data.data;
  81. console.log('zhix1数据',tab_item.list)
  82. }else{
  83. console.log('zhix2')
  84. tab_item.list.push(...res.data.data);
  85. console.log('zhix2数据',tab_item.list)
  86. }
  87. }).catch(err => {
  88. })
  89. },
  90. tabChange(index){
  91. this.$refs.uWaterfall[index].clear();
  92. this.tab_list = []
  93. this.getCategory({type: 'pageRefresh'});
  94. console.log(this.$refs)
  95. this.current = index;
  96. if(this.tab_list[index].list.length <= 0){
  97. this.getData(); // tab下没有数据,请求第一页
  98. }
  99. },
  100. // 滑块下标值变化
  101. swiperChange(event){
  102. this.current = event.detail.current;
  103. if(event.detail.source == '') return; // 如果是被动出发,没有事件类型则不做处理
  104. if(this.tab_list[event.detail.current].list.length <= 0){
  105. this.getData(); // tab下没有数据,请求第一页
  106. }
  107. },
  108. // 页面触底,加载下一页
  109. onScrolltolower(){
  110. let tab_item = this.tab_list[this.current];
  111. if(tab_item.isPage){
  112. tab_item.page = tab_item.page + 1;
  113. this.getData();
  114. }
  115. },
  116. // scroll-view 下拉刷新
  117. onRefresherrefresh(){
  118. this.$u.throttle(() => {
  119. this.tab_list[this.current].isRefresher = true;
  120. this.getCategory({type: 'scrollRefresh'});
  121. }, 200);
  122. },
  123. // page 下拉刷新
  124. onPullDownRefresh(){
  125. // 新版逻辑,刷新则整个数据全部重新获取
  126. this.getCategory({type: 'pageRefresh'});
  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>