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

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