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

183 lines
5.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 - 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. // 处理从首页跳转到该页面的情况,动态显示tab
  41. if(this.tab_list.length){ // 这是该页面已经存在页面栈中的情况
  42. let channel_id = uni.getStorageSync('channel_id');
  43. if(channel_id){
  44. this.tab_list.map((item, index) => {
  45. if(item.id == channel_id){
  46. this.current = index;
  47. }
  48. })
  49. uni.removeStorage('channel_id');
  50. }
  51. }
  52. if(this.show_count >= 1){
  53. this.clearTabItem();
  54. this.getData();
  55. }else{
  56. this.getCategory();
  57. }
  58. this.show_count++;
  59. },
  60. methods: {
  61. getCategory(options = {}) {
  62. this.$http(this.API.API_CATEGORYLIST).then(res => {
  63. let res_list = res.data || [];
  64. let current = 0;
  65. let channel_id = uni.getStorageSync('channel_id');
  66. let tab_list = res_list.map((item, index) => {
  67. return {
  68. id: item.id,
  69. name: item.name,
  70. list: [],
  71. isRefresher: false,
  72. loadingClass: true,
  73. loadingText: '正在加载中',
  74. page: 1,
  75. isPage: true,
  76. pid: item.pid
  77. }
  78. });
  79. let list = []
  80. tab_list.forEach((item,index) => {
  81. if(item.pid == 0) {
  82. list.push(item);
  83. if(channel_id && item.id == channel_id){ // 这是页面首次打开的情况,判断是否有无频道id
  84. current = index;
  85. uni.removeStorage('channel_id');
  86. }
  87. }
  88. })
  89. this.current = current;
  90. this.tab_list = list;
  91. this.getData()
  92. }).catch(err => {
  93. })
  94. },
  95. getData() {
  96. let tab_item = this.tab_list[this.current];
  97. console.log('页数',tab_item.page)
  98. if(this.$shared.isValueType(tab_item) == 'undefined') return;
  99. this.$http(this.API.API_ADVICELIST,{page: tab_item.page,category_id: tab_item.id}).then(res => {
  100. let isPage = res.data.next_page_url == null?false:true;
  101. tab_item.isPage = isPage;
  102. if(!isPage){
  103. tab_item.loadingClass = false;
  104. tab_item.loadingText = '没有更多数据啦~';
  105. }
  106. tab_item.isRefresher = false;
  107. if(tab_item.page == 1){
  108. tab_item.list = res.data.data;
  109. }else{
  110. tab_item.list.push(...res.data.data);
  111. }
  112. }).catch(err => {
  113. })
  114. },
  115. tabChange(index){
  116. this.current = index;
  117. this.clearTabItem()
  118. console.log(this.$refs)
  119. console.log('当前数据',this.tab_list[index])
  120. console.log('组件中的数据',this.$refs.uWaterfallFather[this.current].dataList)
  121. if(this.tab_list[index].list.length <= 0){
  122. this.getData(); // tab下没有数据,请求第一页
  123. }
  124. },
  125. // 滑块下标值变化
  126. swiperChange(event){
  127. this.current = event.detail.current;
  128. if(event.detail.source == '') return; // 如果是被动出发,没有事件类型则不做处理
  129. if(this.tab_list[event.detail.current].list.length <= 0){
  130. this.getData(); // tab下没有数据,请求第一页
  131. }
  132. },
  133. // 页面触底,加载下一页
  134. onScrolltolower(){
  135. let tab_item = this.tab_list[this.current];
  136. if(tab_item.isPage){
  137. tab_item.page = tab_item.page + 1;
  138. this.getData();
  139. }
  140. },
  141. // scroll-view 下拉刷新
  142. onRefresherrefresh(){
  143. this.$u.throttle(() => {
  144. this.clearTabItem();
  145. this.getData();
  146. }, 200);
  147. },
  148. clearTabItem(){
  149. let tab_item = this.tab_list[this.current];
  150. tab_item.page = 1;
  151. tab_item.isPage = true;
  152. tab_item.isRefresher = true;
  153. tab_item.loadingClass = true;
  154. tab_item.loadingText = '正在加载中';
  155. tab_item.list = [];
  156. this.$set(this.tab_list, this.current, tab_item);
  157. this.$refs.uWaterfallFather[this.current].clear();
  158. console.log('当前方法删除',this.$refs.uWaterfallFather[this.current])
  159. }
  160. }
  161. }
  162. </script>
  163. <style>
  164. page{
  165. background-color: #F6F6F6;
  166. }
  167. </style>
  168. <style lang="scss" scoped="scoped">
  169. .head{
  170. background-color: #FFFFFF;
  171. }
  172. .com{
  173. width: 100%;
  174. height: 100%;
  175. box-sizing: border-box;
  176. padding: 0rpx 32rpx;
  177. }
  178. </style>