<template>
    <view>
        
        <rowList :listdata="newsList" ></rowList>

        <view class="loadmore" @click="loadmore()" >
            {{jiazaitext}}
        </view>
    </view>
</template>
<script>
import rowList from '@/pages/market/base/rowList.vue' //左右布局
import {collectionList,browsingHistoryPage} from '@/http/api/common.js'
export default {
components: {
    rowList,
},
data() {
    return {
        newsList:[],
        jiazaitext:'加载更多',
        pageNum:1,
        pageSize:10,
        showType:'jilu'
    }
},
async onLoad(e) {
    this.newsList = []
    if (e.showType) {
        if (e.showType == 'shouchang') {
            uni.setNavigationBarTitle({
                title: '收藏列表'
            })
        }
        this.showType = e.showType
    }
    //获取商品列表
    await this.getList()
   
},
onReachBottom() {
    this.loadmore()
},
methods: {
    //加载更多
    loadmore(){
        console.log('下拉加载',this.jiazaitext);
        if (this.jiazaitext=="加载更多") {
            this.pageNum=this.pageNum+1
            this.jiazaitext="加载中..."
            this.getList()
        }
    },
    async getList(){
        let res = {
            data:null
        }
        if (this.showType == 'shouchang') {
            //获取收藏列表
            res = await collectionList({
                pageSize:this.pageSize,
                pageNum:this.pageNum,
            })
        }else{
             //获取浏览记录
             res = await browsingHistoryPage({
                pageSize:this.pageSize,
                pageNum:this.pageNum,
            })
        }
        if (res.data?.code == 200) {
            let newrows = res.data.data?.rows || []

            this.newsList.push(...newrows)
            
            if(this.newsList.length!=res.data.data.total){
                this.jiazaitext="加载更多"
            }else{
                this.jiazaitext="已经到底"
            }
        }
    },
    
}
}
</script>

<style>
.loadmore{
    height:200rpx;
    text-align: center;
    font-size: 28rpx;
    font-weight: 400;
    color: #999;
    padding-top: 24rpx;
}
</style>
    