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

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