<template>
	<view class="hot-item">
		<image :src="item.cover" class="book-cover" mode="aspectFill"></image>
		<view class="info-right">
			<view class="info-top">
				<text class="title">{{ item.name || '-' }}</text>
				<view class="price-row">
					<text class="currency">¥</text>
					<text class="price">{{ item.productPrice }}</text>
				</view>

				<view class="flex space-between">
					<view class="discount-tag" v-if="item.discountDesc">
						<text class="discount">{{ item.discountDesc }}</text>
						<text class="discount-desc">省{{ item.discountPrice }}元</text>
					</view>

					<view class="btn-cart" @click.stop="handleAddToCart">
						<text>加入购物车</text>
					</view>
				</view>
			</view>
		</view>

		<!-- Product Selection Popup -->
		<SelectGoodPopup ref="popup" @confirm="onPopupConfirm"></SelectGoodPopup>
	</view>
</template>

<script>
import SelectGoodPopup from '../select-good-popup/index.vue';

export default {
	name: 'HotRecommendItem',
	components: {
		SelectGoodPopup
	},
	props: {
		item: {
			type: Object,
			required: true,
			default: () => ({})
		}
	},
	methods: {
		handleAddToCart() {
			this.$refs.popup.open(this.item);
		},
		onPopupConfirm(data) {
			this.$emit('add-cart', data);
		}
	}
}
</script>

<style lang="scss" scoped>
.hot-item {
	display: flex;
	border-radius: 16rpx;

	.book-cover {
		width: 140rpx;
		height: 180rpx;
		border-radius: 4rpx;
		background-color: #f5f5f5;
		margin-right: 20rpx;
		flex-shrink: 0;
	}

	.info-right {
		flex: 1;

		.info-top {
			height: 100%;
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			.title {
				font-size: 30rpx;
				font-weight: bold;
				color: #333;
				margin-bottom: 10rpx;
				display: block;
			}

			.price-row {
				display: flex;
				align-items: baseline;
				margin-bottom: 10rpx;

				.currency {
					font-size: 32rpx;
					color: #D81A00;
					font-weight: bold;
				}

				.price {
					font-size: 36rpx;
					color: #D81A00;
					font-weight: bold;
				}
			}

			.discount-tag {
				display: inline-block;
				border-radius: 10rpx;
				font-family: Source Han Sans SC;
				font-weight: 500;
				font-size: 22rpx;
				height: 40rpx;
				line-height: 40rpx;
				background-color: #fff;
				border: 2rpx solid #D81A00;
				box-sizing: border-box;
				overflow: auto;

				.discount {
					background: #D81A00;
					color: #fff;
					display: inline-block;
					padding: 0 12rpx;
					box-sizing: border-box;
				}

				.discount-desc {
					color: #D81A00;
					padding: 0 10rpx;
				}
			}
		}

		.btn-cart {
			align-self: flex-end;
			background: #38C248;
			border-radius: 30rpx;
			height: 60rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			padding: 0 20rpx;

			text {
				font-size: 28rpx;
				color: #fff;
			}
		}
	}
}
</style>
