<template>
	<view class="bg">
		<view class="item" v-for="(item,index) in list" :key="index" @click="gotoDetailByType(item)">
			<image :src="showImg(item.headimg)" mode="aspectFill	"></image>
			<view class="content flex-column">
				<view>
					<view class="title">{{item.title}}</view>
					<view class="tags" v-if="item.display_tags">
						<view class="tag" v-for="(tagItem,tagIndex) in item.display_tags.split(',').slice(0,2)" :key="tagIndex">
							{{tagItem}}
						</view>
					</view>
				</view>
				<view class="item-bottom flex-between">
					<view class="price">{{item.price / 100}}</view>
					<view class="btn">预订</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				finished: false
			}
		},
		onReady() {
			this.getList()
		},
		onReachBottom() {
			setTimeout(() => {
				if (!this.finished) this.getList()
			},1000)
		},
		methods: {
			getList() {
				this.Post({
					offset: this.list.length,
					limit: 10,
					tag_id: 17,
					sort: 'weight'
				},'/api/product/get_product_by_tag').then(res => {
					this.list = [...this.list, ...res.data.list]
					
					if (res.data.list.length < 10) {
						this.finished = true
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.bg {
		min-height: 100vh;
		background-color: rgba(249, 252, 243, 1);
		padding-bottom: 100rpx;
	}
	
	.item {
		margin: 30rpx 26rpx;
		display: flex;
		
		image {
			width: 241rpx;
			height: 295rpx;
			border-radius: 20rpx;
			margin-right: 20rpx;
			flex-shrink: 0;
		}
		
		.content {
			height: 295rpx;
			padding-top: 12rpx;
			justify-content: space-between;
			flex: 1;
			
			.title {
				font-weight: bold;
				font-size: 31rpx;
				color: #333333;
			}
			
			.tags {
				display: flex;
				margin-top: 23rpx;
				
				.tag {
					font-size: 24rpx;
					color: #6A8A27;
					margin-right: 11rpx;
				}
				.tag:not(:last-child)::after{
					content: '|';
					display: inline-block;
					margin-left: 11rpx;
				}
			}
			
			.item-bottom {
				.price {
					font-size: 34.67rpx;
					color: rgba(220, 37, 37, 1);
				}
				.price::before {
					font-size: 22.67rpx;
					content: '￥';
				}
				.price::after {
					font-size: 22.67rpx;
					content: '起';
					color: rgba(153, 153, 153, 1);
				}
				
				.btn {
					width: 133rpx;
					line-height: 53rpx;
					background: #6A8A27;
					border-radius: 12rpx;
					text-align: center;
					font-weight: 500;
					font-size: 31rpx;
					color: #FFFFFF;
				}
			}
		}
	}
</style>