<template>
	<view class="content">
		<view class="goods-list">
			<view class="goods-item" v-for="(item, index) in goodsList" :key="index" @click="addCart(item)">
				<image :src="item.image" mode="aspectFill" class="goods-image"></image>
				<view class="goods-name clamp">{{item.store_name}}</view>
				<view class="goods-info">
					<text class="goods-points">{{item.price}} 积分</text>
					<image src="../../../static/icon/cart.png" mode="widthFix" class="add-cart" ></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { getProductList  } from '@/api/good.js'
	export default {
		data() {
			return {
				page: 1,
				limit: 20,
				list: [],
				loaded: false,
				status: 'more',
				goodsList: []
			};
		},
		methods: {
			// 返回
			getProductList() {
				let that = this
				if(that.status == 'noMore' || that.status == 'loading') return;
				that.status = 'loading'
				getProductList({
					page: that.page,
					pageSize: that.limit,
				}).then(res => {
					let list = res.data.list
					that.goodsList = that.goodsList.concat(list)
					if(that.limit == list.length) {
						that.status = 'more'
					}else {
						that.status = 'noMore'
					}
					that.loaded = true
				})
			},
			// 添加到购物车
			addCart(item) {
				uni.navigateTo({
					url:'/pages/user/jf/detail?id=' + item.id
				})
			}
		},
		onLoad() {
			this.getProductList()
		},
		onReachBottom() {
			this.getProductList()
		}
	};
</script>

<style lang="scss">
	page {
		height: 100%;
		background-color: #F5F5F5;
	}

	.content {
		min-height: 100%;
	}

	.header {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 30rpx;
		height: 80rpx;
		background-color: #FF4444;
		
		.back {
			width: 40rpx;
			height: 40rpx;
			
			image {
				width: 100%;
				height: 100%;
			}
		}
		
		.title {
			font-size: 32rpx;
			font-weight: bold;
			color: #FFFFFF;
		}
		
		.right {
			width: 40rpx;
		}
	}



	.goods-list {
		display: flex;
		flex-wrap: wrap;
		padding: 0 15rpx;
		
		.goods-item {
			width: 300rpx;
			margin: 1%;
			background-color: #FFFFFF;
			border-radius: 15rpx;
			overflow: hidden;
			
			.goods-image {
				width: 300rpx;
				height: 300rpx;
			}
			
			.goods-name {
				width: 270rpx;
				padding: 15rpx ;
				font-size: 26rpx;
				color: #333333;
				line-height: 36rpx;
				height: 72rpx;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 2;
				-webkit-box-orient: vertical;
			}
			
			.goods-info {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 0 15rpx 15rpx;
				
				.goods-points {
					font-size: 26rpx;
					font-weight: bold;
					color: #FF4444;
				}
				
				.add-cart {
					width: 40rpx;
					height: 40rpx;
					background-color: #FF4444;
					border-radius: 50%;
					display: flex;
					align-items: center;
					justify-content: center;
					
					.cart-icon {
						width: 24rpx;
						height: 24rpx;
					}
				}
			}
		}
	}
</style>