<template>
	<view>
		<!-- 产品封面 -->
		<view class="goods-swiper">
			<swiper :indicator-dots="false" @change="current = $event.detail.current + 1">
				<swiper-item v-for="(item, index) in goods.pictures" :key="index">
					<view class="swiper-cover">
						<image :src="item" mode="aspectFill" />
					</view>
				</swiper-item>
			</swiper>
			<view class="swiper-pages">
				{{current}}/{{goods.pictures.length}}
			</view>
		</view>
		<!-- 详情 -->
		<view class="main">
			<view class="title">{{goods.name}}</view>
			<view class="sub-title">{{goods.description}}</view>
			<view class="box-flex">
				<view class="price">
					<text>¥</text>{{goods.price.show}}
				</view>
				<view class="sales">销量{{goods.sales}}</view>
			</view>
			<!-- <view class="hr">
				<text>详情</text>
			</view> -->
			<view class="imgs">
				<block v-for="(item, index) in goods.content" :key="index">
					<image :src="item" mode="widthFix"></image>
				</block>
			</view>
		</view>
		<!-- 立即购买 -->
		<view class="footer">
			<button type="default" hover-class="none" @click="buy">立即购买</button>
		</view>
	</view>
</template>

<script>
	import { goods } from '@/apis/interfaces/store'
	export default {
		data() {
			return {
				current: 1,
				goods  : {
					pictures	: [],
					name		: "",
					description	: "",
					content		: [],
					price		: {
						show: 0
					}
				}
			};
		},
		mounted() {
			this.getGoods()
		},
		methods:{
			getGoods(){
				goods(this.$Route.query.id).then(res => {
					this.goods = res
				})
			},
			buy(){
				this.$Router.push({
					name: 'StoreBuy',
					params: {
						skuId: this.goods.skus[0].sku_id
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.goods-swiper{
		position: relative;
		width: 100%;
		padding-top: 110%;
		background: $window-color;
		&> swiper{
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
			.swiper-cover{
				width: 100%;
				height: 100%;
				image{
					position: absolute;
					top: 0;
					left: 0;
					width: 100%;
					height: 100%;
				}
			}
		}
		.swiper-pages{
			position: absolute;
			bottom:20rpx;
			left: 0;
			right: 0;
			z-index: 9;
			line-height: 90rpx;
			text-align: center;
			color: white;
			font-size: $title-size-m;
			text-shadow: 0 5rpx 5rpx rgba($color: #000000, $alpha: .02);
		}
	}
	// 详情
	.main{
		position: relative;
		z-index: 9;
		margin-top: -20rpx;
		background: white;
		border-radius: $radius $radius 0 0;
		box-shadow: 0 0 10rpx 10rpx rgba($color: #000000, $alpha: .02);
		padding-bottom: ($padding*2) + 90;
		.hr{
			position: relative;
			min-height: 1rpx;
			margin: 0 $margin;
			text-align: center;
			text{
				position: relative;
				z-index: 1;
				color: $text-gray;
				font-size: $title-size-m;
				background: white;
				padding: 0 $padding;
			}
			&::after{
				content: " ";
				background: $border-color;
				width: 100%;
				height: 1rpx;
				position: absolute;
				left: 0;
				top: 50%;
			}
		}
		.title{
			padding: $padding;
			font-weight: bold;
			font-size: $title-size + 14;
		}
		.sub-title{
			padding: 0 $padding;
			font-size: $title-size-m;
			color: $text-gray;
		}
		.box-flex{
			padding: $padding;
			display: flex;
			justify-content: space-between;
			align-items: center;
			.price{
				font-weight: bold;
				color: $text-price;
				font-size: $title-size + 10;
				text{
					font-size: 80%;
					margin-right: 10rpx;
				}
			}
			.sales{
				font-size: $title-size-m;
				color: $text-gray;
			}
		}
		.imgs{
			image{
				vertical-align: top;
				width: 100%;
			}
		}
	}
	// 购买
	.footer{
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		padding: $padding;
		z-index: 98;
		background: white;
		// linear-gradient(to top, white 86%, rgba(255,255,255,.0))
		button{
			background: $main-color;
			color: white;
			border-radius: $radius-lg;
			height: 90rpx;
			line-height: 90rpx;
			font-weight: bold;
			font-size: $title-size;
			&::after{
				display: none;
			}
		}
	}
</style>
