<template>
	<view class="list">
		<view class="item" v-for="(item, index) in list"
			@click="$utils.navigateTo('/pages_order/product/productDetail?id=' + item.id)" :key="index">
			<image class="image" :src="item.image &&
			item.image.split(',')[0]" mode="aspectFill"></image>
			<view class="product-info">
				<view class="product-title">
					{{ item.title }}
				</view>

				<view class="product-main">
					<view class="sale-information">
						<view style="display: flex;align-items: flex-end;">
							<view class="price">
								<text>￥{{ item.price }}</text>/件
							</view>
							<view class="oldPrice">
								<text>￥{{ item.oldPrice }}</text>
							</view>
						</view>
						<view class="num">
							已售卖{{ item.num }}+件
						</view>
					</view>

					<view @click.stop="purchase(item.id)" class="btn">
						购买
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "productList",
		props: {
			list: {
				default: []
			},
		},
		data() {
			return {

			};
		},
		methods: {
			// 购买商品(创建订单)
			purchase(id) {
				this.$api('getRiceProductDetail', {
					id
				}, res => {
					if (res.code == 200) {
						res.result.num = 1
						this.$store.commit('setPayOrderProduct', [
							res.result
						])
						this.$utils.navigateTo('/pages_order/order/createOrder')
					}
				})
			},
		},
	}
</script>

<style scoped lang="scss">
	.list {
		display: flex;
		flex-wrap: wrap;

		.item {
			position: relative;
			width: 345rpx;
			padding: 20rpx;
			box-sizing: border-box;
			background-color: #fff;
			border-radius: 20rpx;
			margin-left: 20rpx;
			margin-bottom: 20rpx;

			.image {
				width: 300rpx;
				height: 250rpx;
				border-radius: 20rpx;
			}

			.product-info {
				font-size: 24rpx;

				.product-title {
					font-weight: bold;
					display: -webkit-box;
					/* 兼容WebKit内核浏览器 */
					-webkit-line-clamp: 2;
					/* 显示最大3行 */
					-webkit-box-orient: vertical;
					/* 设置垂直方向上的排列方式 */
					overflow: hidden;
					/* 隐藏溢出内容 */
					text-overflow: ellipsis;
					/* 当文本溢出时显示省略号 */
				}

				.product-main {
					display: flex;
					align-items: flex-end;

					.sale-information {
						width: 75%;

						.title {
							font-size: 28rpx;
							overflow: hidden; //超出的文本隐藏
							text-overflow: ellipsis; //溢出用省略号显示
							white-space: nowrap; //溢出不换行
						}

						.price {
							color: $uni-color;
							margin-top: 6rpx;

							text {
								font-size: 30rpx;
								font-weight: 900;
							}
						}

						.oldPrice {
							color: #888;
							text-decoration: line-through;
						}

						.num {
							margin-top: 6rpx;
							font-size: 22rpx;
							color: #888;
						}
					}

					.btn {
						display: flex;
						align-items: center;
						justify-content: center;
						border-radius: 10rpx;
						font-size: 24rpx;
						height: 60rpx;
						width: 25%;
						color: #fff;
						background-color: $uni-color;
					}
				}
			}
		}
	}
</style>