<template>
	<view class='look-page'>
		<view class='look-mian' v-if="IndexList && IndexList.length>0">
			<scroll-view
				class='scroll-y-hs'
				scroll-y="true" 
				style="height: 600px;"
				refresher-default-style="none"
				@scrolltoupper="toupperTop"
				@scrolltolower="lowerMore">
				
					<view class='mian-box'>
						<view class='box-item' v-for="item in IndexList" :key="item.id" @click="goItem(item)">
							<view class='item-top'>
								<image :src="item.goodsImage" class='top-img'></image>
								<i class='top-icon'></i>
							</view>
							<view class='item-footer'>
								<view class='footer-des'>{{item.goodsName}}</view>
								<view class='footer-box'>
									<view class='box-num'>
										<view class='num-icon'>¥</view>
										{{item.goodsMoney}}
									</view>
									
								</view>
								<view class='footer-line'>
									<view class='box-btn'>可置换</view>
									<view class="box-last">{{item.lookSum}}次浏览</view>
								</view>
							</view>
						</view>
					</view>
				
				
			</scroll-view>
		</view>
		<view class='look-footer' v-else>
			<image class="footer-img" src='https://ddh.yyhock.com/ddhMall/result-null.png'></image> 
			<view class='footer-text'>暂无数据哦！</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				titleText:'',
				pageNum: 1,
				pageSize: 10,
				total: 0,
				hasNextText:'上拉加载更多',
				loadFlag:true,
				hasNextPage:false,
				goodType:0,
				IndexList:[]
			}
		},
		onReady() {	
			uni.setNavigationBarTitle({
				title: this.titleText
			})
		},
		onLoad(options) {
			console.log(options,'09')
			if(options.loanStatus=='我的关注'){
				this.titleText=options.loanStatus
				this.goodType=1
			}else{
				this.titleText=options.loanStatus
				this.goodType=2
			}
			this.buryingPoint('app:lookGoods_pageView')
			this.init()
		},
		methods: {
			init(){
				const self=this
				const params={
					"current": self.pageNum,
					"size": self.pageSize,
					"sort": "id desc",
					"type": self.goodType  //1收藏，2 足迹
				}
				console.log(params,'params')
				self.$request('/pawn/category/getGoodsByUserId','POST',params).then(res => {
					console.log(res.result,'getGoodsByUserId');
					const {current,total,size,records }=res.result
					const hasNextPage=total-self.pageSize*self.pageNum>0?true:false //是否有下一页
					if(self.loadFlag){
						console.log(33);
						self.IndexList=self.IndexList.concat(records)
					}else{
						console.log(34);
						self.IndexList=records
					}
					self.hasNextPage=hasNextPage
					self.loadFlag=false
				
					
				}).catch(err=>{
				  console.log(err,'请求出错')
				})
			},
			goItem(item){
				const params={
					goodId:item.id
				}
				uni.navigateTo({
					url:'/pages/productDetails/productDetails?mydata='+encodeURIComponent(JSON.stringify(params))
				})
			},
			toupperTop(e){
				console.log(e,'到顶了');
			},
			lowerMore(e){
				console.log(e,'触底了');
				if(!this.hasNextPage){
					uni.showToast({
						icon: 'none',
						title: '到底了',
					})
					return false;
				} 
				if(this.loadFlag) return;
				this.loadFlag=true,
				this.pageNum=this.pageNum+1
				this.init();
			}
		},
		onShow() {
			this.init()
		}
	}
</script>

<style src='./index.less' lang="less" scoped></style>
