123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- <template>
- <view>
-
- <me-tabs v-if="isShowSticky" v-model="tabIndex" :fixed="true" :tabs="tabs" @change="tabChange"></me-tabs>
-
- <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :up="upOption" @scroll="scroll" @topclick="topClick">
-
- <swiper style="min-height: 300rpx" autoplay="true" interval="3000" duration="300" circular="true">
- <swiper-item>
- <image style="width: 100%;height: auto;" src="https://www.mescroll.com/img/swiper1.jpg" mode="widthFix"/>
- </swiper-item>
- <swiper-item>
- <image style="width: 100%;height: auto;" src="https://www.mescroll.com/img/swiper2.jpg" mode="widthFix"/>
- </swiper-item>
- </swiper>
-
- <view class="demo-tip">
- <view>列表只初始化一次,切换菜单缓存数据</view>
- <view>吸顶通过监听滚动条实现, 比sticky复杂, 但APP端可兼容低端机</view>
- </view>
-
-
- <view id="tabInList">
- <me-tabs v-model="tabIndex" :tabs="tabs" @change="tabChange"></me-tabs>
- </view>
-
-
- <good-list :list="goods"></good-list>
- </mescroll-body>
- </view>
- </template>
- <script>
- import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
- import {apiSearch} from "@/api/mock.js"
-
- export default {
- mixins: [MescrollMixin],
- data() {
- return {
- upOption: {
-
-
- },
- tabs:[
- {name:'全部', goods: null, num:1, y:0, curPageLen:0, hasNext:true},
- {name:'母婴', goods: null, num:1, y:0, curPageLen:0, hasNext:true},
- {name:'图书', goods: null, num:1, y:0, curPageLen:0, hasNext:true}
- ],
- tabIndex: 0,
- preIndex: 0,
- navTop: null,
- isShowSticky: false
- }
- },
- computed: {
-
- goods() {
- return this.tabs[this.tabIndex].goods
- }
- },
- methods: {
-
- downCallback() {
-
-
-
- this.mescroll.resetUpScroll()
- },
-
- upCallback(page) {
-
- if(this.isChangeTab){
- this.mescroll.hideUpScroll();
- uni.showLoading();
- }
- let keyword = this.tabs[this.tabIndex].name;
- apiSearch(page.num, page.size, keyword).then(curPageData=>{
-
-
-
- let curTab = this.tabs[this.tabIndex]
-
-
- if(page.num == 1) curTab.goods = [];
- curTab.goods=curTab.goods.concat(curPageData);
-
-
-
- setTimeout(()=>{
-
- this.mescroll.endSuccess(curPageData.length);
-
- curTab.num = page.num;
- curTab.curPageLen = curPageData.length;
- curTab.hasNext = this.mescroll.optUp.hasNext;
-
-
-
- if(!this.navTop) this.setNavTop()
-
- if(this.isChangeTab){
- this.isChangeTab = false;
- uni.hideLoading();
- if(this.isShowSticky) this.mescroll.scrollTo(this.navTop, 0)
- }
- },20)
- }).catch(()=>{
-
- this.mescroll.endErr();
- })
- },
-
- setNavTop(){
- let view = uni.createSelectorQuery().select('#tabInList');
- view.boundingClientRect(data => {
- console.log('tabInList基本信息 = ' + JSON.stringify(data));
- this.navTop = data.top
- }).exec();
- },
-
-
- scroll(){
- console.log('滚动条位置 = ' + this.mescroll.getScrollTop() + ', navTop = ' + this.navTop);
-
- if (this.mescroll.getScrollTop() >= this.navTop) {
- this.isShowSticky = true
- } else {
- this.isShowSticky = false
- }
- },
-
- topClick(){
- this.isShowSticky = false
- },
-
- tabChange (index) {
-
- let preTab = this.tabs[this.preIndex]
- preTab.y = this.mescroll.getScrollTop();
- this.preIndex = index;
-
- let curTab = this.tabs[index]
- if (!curTab.goods) {
-
- this.isChangeTab = true;
- this.mescroll.resetUpScroll()
- } else{
-
- this.mescroll.setPageNum(curTab.num + 1);
- this.mescroll.endSuccess(curTab.curPageLen, curTab.hasNext);
- this.$nextTick(()=>{
- this.mescroll.scrollTo(curTab.y, 0)
- })
- }
- }
- },
-
- onPageScroll(e){
- console.log('滚动条位置 = ' + e.scrollTop + ', navTop = ' + this.navTop);
- if (e.scrollTop >= this.navTop) {
- this.isShowSticky = true
- } else {
- this.isShowSticky = false
- }
- }
- }
- </script>
- <style>
- .demo-tip{
- padding: 18rpx;
- font-size: 24rpx;
- text-align: center;
- }
- </style>
|