<!-- 商品详情 -->
<template>
	<scroll-view scroll-y="true" class="shop-detail-page" :style="{'height':show ? '100vh' : 'auto','overflow':show ? 'hidden' : 'auto'}">
		<view class="go-back" :style="{'top':`${statusBarHeight + 20}px`}" @click="goBack">
			<image src="@/static/index/fh.png" mode="" class="back-img"></image>
		</view>
		<swiper class="swiper" circular indicator-dots>
			<swiper-item v-for="(item,index) in detailData.rollingImagesResource" :key="index" class="swiper-item">
				<view class="swiper-img" :style="{'backgroundImage':`url(${item.url})`}"></view>
			</swiper-item>
		</swiper>
		<view class="main">
			<view class="detail">
				<view class="detail-header">
					<view class="header-price">
						<view class="point">
							<image src="@/static/mine/jf.png" mode="" class="ponit-img"></image>
							{{detailData.mallPoint||''}}
						</view>
						<view class="shu"></view>
						<view class="old-price">
							¥{{detailData.price.settlement||0}}
						</view>
					</view>
					<view class="fee">快递：免运费</view>
				</view>
				<view class="name">
					{{detailData.name||''}}
				</view>
				<!-- <view class="detail-price">
					<view class="price">
						¥ <view class="price-val">{{detailData.price.sale||0}}</view>
					</view>
					<view class="shu"></view>
					<view class="point">
						<image src="@/static/mine/jf.png" mode="" class="ponit-img"></image>
						{{detailData.mallPoint||''}}
					</view>
				</view>
				<view class="old-price">
					¥{{detailData.price.settlement||0}}
				</view>
				<view class="name">
					{{detailData.name||''}}
				</view> -->
			</view>
		</view>
		
		<view class="sub-title">商品详情</view>
		<view style="padding: 0 22rpx 140rpx 22rpx;">
			<template v-for="(item,index) in detailData.detailImagesResource">
				<image :src="item.url" mode="widthFix" :key="index" style="width: 100%;"></image>
			</template>
		</view>
		<view class="footer" v-if="!footerType">
			<image src="@/static/index/sc.png" mode="" v-if="detailData.favorite" @click="collect" class="collect-img"></image>
			<image src="@/static/index/sc-n.png" mode="" v-if="!detailData.favorite" @click="collect" class="collect-img"></image>
			<view class="footer-buy" @click="buy">立即购买</view>
		</view>
		<image src="https://box-mall.oss-cn-hangzhou.aliyuncs.com/static/shop/top.png" mode="" class="go-top" @click="goTop" v-if="scroll > 50"></image>
		<popup-view v-model="show" mode="bottom" border-radius="15" zIndex="1">
			<view class="popup-main">
				<view class="popup-header">
					<image :src="detailData.coverResource.url" mode="" class="popup-header-img"></image>
					<view class="popup-info">
						<view class="popup-info-name">{{detailData.name}}</view>
						<view class="popup-info-price">
							<view class="popup-clover">
								<image src="@/static/mine/jf.png" mode="" class="clover-img"></image>
								{{detailData.mallPoint}}
							</view>
							
							<view class="popup-price">
								<text class="popup-symbol">¥</text>{{detailData.price.sale}}
							</view>
						</view>
					</view>
				</view>
				<view class="popup-footer">
					<view class="footer-num">
						<view class="footer-info">
							购买数量
						</view>
						<view class="item-step">
							<image src="@/static/mine/sub.png" class="item-sub" mode="" @click="sub"></image>
							<view class="item-num">{{quantity}}</view>
							<image src="@/static/mine/add.png" class="item-add" mode="" @click="add"></image>
						</view>
					</view>
					<view class="now-buy" @click="confirmBuy">立即支付</view>
				</view>
			</view>
		</popup-view>
		<!-- 所有页面的弹框 -->
		<page-popup page="/pages/product/detail"></page-popup>
	</scroll-view>
</template>

<script>
	
	import { myMixins } from "@/mixins/mixins.js";
	import { productDetailApi,favorItemApi,delFavorItemApi } from '@/API/product.js'
	var statusBarHeight = uni.getSystemInfoSync().statusBarHeight
	export default {
	mixins: [myMixins],
		data() {
			return {
				statusBarHeight,
				id:"",
				show: false, //立即购买弹框
				quantity:1,
				detailData:{
					detailImages:"",
					price:{},
					coverResource:{}
				},//商品详情
				scroll:0,
				footerType:"",//是否现实底部
			}
		},
		onLoad(opation) {
			this.id = opation.id
			this.footerType = opation.footer ? opation.footer : ''
			this.getDetail()
			// this.getdeliveryFee()
		},
		onPageScroll(res){
			this.scroll = res.scrollTop
		},
		methods: {
			// 获取详情
			getDetail(){
				uni.showLoading()
				productDetailApi({id:this.id}).then(res => {
					uni.hideLoading()
					if(res.code === 200){
						res.data.rollingImagesResource.unshift(res.data.coverResource)
						this.detailData = res.data
					}else{
						this.$api.msg(res.message)
					}
				}).catch(err => {
					uni.hideLoading()
				})
			},
			goBack() {
				uni.navigateBack()
			},
			// 滚动到顶部
			goTop() {
				uni.pageScrollTo({
					duration: 300,
					scrollTop: 0 // number number number！
				});
			},
			// 是否收藏
			collect() {
				uni.showLoading()
				if(this.detailData.favorite){
					delFavorItemApi({productId:this.detailData.id}).then(res => {
						uni.hideLoading()
						if(res.code === 200){
							this.$api.msg('取消收藏')
							this.getDetail()
						}else{
							this.$api.msg(res.message)
						}
					}).catch(err => {
						uni.hideLoading()
					})
				}else{
					favorItemApi({productId:this.detailData.id}).then(res => {
						uni.hideLoading()
						if(res.code === 200){
							this.$api.msg('收藏成功')
							this.getDetail()
						}else{
							this.$api.msg(res.message)
						}
					}).catch(err => {
						uni.hideLoading()
					})
				}
			},
			// 减
			sub(){
				if(this.quantity === 1){
					this.$api.msg("不能小于1！");
					return;
				}
				if(this.quantity > 1){
					this.quantity--
				}
			},
			// 加
			add(){
				this.quantity++
			},
			// 立即购买弹框
			buy() {
				this.show = true
			},
			// 确认购买
			confirmBuy(){
				// 清空购买地址
				uni.removeStorageSync('address')
				this.show = false;
				uni.navigateTo({
					url:`/pages/order/confirm?id=${this.id}&quantity=${this.quantity}`
				})
			},
		}
	}
</script>
<style>
	uni-toast {
		z-index: 10000 !important;
	}
</style>
<style lang="scss" scoped>
	page{
		background-image: url('@/static/index/bg.png');
		background-size: 100%;
	}
	.shop-detail-page {
		// height: 100%;
		// overflow: auto;
		// padding-bottom: 140rpx;

		.go-back {
			position: fixed;
			left: 32rpx;
			width: 24rpx;
			height: 40rpx;
			z-index: 999;
			width: 55rpx;
			height: 55rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			border-radius: 50%;
			background-color: rgba(0,0,0,0.5);
			.back-img{
				width: 14rpx;
				height: 26rpx;
			}
		}

		.swiper {
			width: 100%;
			height: 616rpx;
			z-index: 1;

			.swiper-item {
				width: 100%;
				height: 100%;

				z-index: 1;
				.swiper-img {
					width: 100%;
					height: 100%;
					background-position: 50%;
					background-repeat: no-repeat;
					background-size: 100%;
					z-index: 1;
				}
			}
		}
		.main{
			width: 706rpx;
			height: 227rpx;
			margin-left: 22rpx;
			position: relative;
			.detail{
				position: absolute;
				width: 706rpx;
				top: -60rpx;
				background: #FFFFFF;
				box-shadow: 0px 14rpx 31rpx 9rpx rgba(222,222,222,0.26);
				border-radius: 10rpx;
				// z-index: 100;
				padding: 41rpx 28rpx 61rpx 29rpx;
				.detail-header{
					display: flex;
					align-items: center;
					justify-content: space-between;
					.header-price{
						display: flex;
						align-items: center;
						.point{
							display: flex;
							align-items: center;
							font-weight: bold;
							font-size: 42rpx;
							color: #EF4235;
							height: 50rpx;
							.ponit-img{
								margin-right: 12rpx;
								width: 32rpx;
								height: 34rpx;
							}
						}
						.shu{
							width: 1rpx;
							height: 33rpx;
							margin: 0 15rpx;
							border-left: 1px solid #D3D3D3;
						}
						.old-price{
							display: flex;
							align-items: flex-end;
							height: 50rpx;
							font-weight: 300;
							font-size: 20rpx;
							color: #888888;
							text-decoration: line-through;
						}
					}
					.fee{
						font-size: 24rpx;
						color: #888888;
					}
				}
					
				.detail-price{
					display: flex;
					align-items: center;
					.price{
						font-size: 32rpx;
						color: #FF6256;
						.price-val{
							display: inline-block;
							font-size: 49rpx;
							font-weight: bold;
							color: #FF6256;
							margin-left: 4rpx;
						}
					}
					
				}
				
				.name{
					margin-top: 30rpx;
					font-weight: bold;
					font-size: 28rpx;
					color: #333333;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
				}
			}
		}
		.sub-title{
			font-weight: bold;
			font-size: 28rpx;
			color: #333333;
			padding: 37rpx 0 27rpx 53rpx;
		}

		.shop-info {
			padding: 20rpx 32rpx 10rpx 32rpx;
			background-color: #fff;

			.info-price {
				border-bottom: 1px solid #F0F0F0;
				padding-bottom: 12rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.price {
					display: flex;
					align-items: center;

					.now-price {
						font-family: YouSheBiaoTiHei;
						color: #FB2B50;
						font-size: 32rpx;

						.price-num {
							font-size: 52rpx;
						}
					}

					.old-price {
						margin-left: 30rpx;
						font-size: 24rpx;
						color: #999;
						text-decoration: line-through;
					}
				}

				.clover {
					display: flex;
					align-items: center;
					font-size: 24rpx;
					color: #3AD4C6;

					.clover-img {
						margin-right: 6rpx;
						width: 36rpx;
						height: 36rpx;
					}
				}
			}

			
			.footer-sc-view{
				display: flex;
				justify-content: space-between;
				padding: 30rpx 0 20rpx 0;
				// justify-content: flex-end;
				.shop-name {
					width: 580rpx;
					// margin-top: 30rpx;
					font-size: 28rpx;
					font-weight: bold;
					color: #333333;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
				}
				.footer-sc{
					// margin-top: 10rpx;
					display: block;
					width: 40rpx;
					height: 40rpx;
				}
			}
			
			
			.freight {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 70rpx;
				font-size: 24rpx;
				color: #999;
			}
		}

		.heng {
			width: 100%;
			height: 24rpx;
			background-color: #F0F1F5;
		}

		.footer {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 100%;
			height: 100rpx;
			background-color: #fff;
			padding: 0 17rpx 0 64rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.collect-img{
				width: 39rpx;
				height: 37rpx;
			}
			
			.footer-buy {
				width: 565rpx;
				height: 63rpx;
				background: linear-gradient(90deg, #EF4033 0%, #FF9F98 100%);
				border-radius: 32rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 23rpx;
				color: #FFFFFF;
			}
		}

		.go-top {
			position: fixed;
			bottom: 190rpx;
			right: 32rpx;
			z-index: 9;
			width: 74rpx;
			height: 76rpx;
		}

		.popup-main {
			padding: 30rpx 22rpx;
			// padding: 32rpx 32rpx 0rpx 32rpx;
			z-index: 9991;
			// max-height: 900rpx;
			// position: relative;
			.popup-header {
				display: flex;
				align-items: center;
				height: 158rpx;

				.popup-header-img {
					width: 158rpx;
					height: 158rpx;
					border-radius: 10rpx;
				}

				.popup-info {
					margin-left: 25rpx;
					.popup-info-name {
						
						width: 482rpx;
						overflow: hidden;
						white-space: nowrap;
						text-overflow: ellipsis;
						font-weight: bold;
						font-size: 28rpx;
						color: #333333;
					}

					.popup-info-price {
						margin-top: 60rpx;
						display: flex;
						align-items: center;

						.popup-price {
							display: flex;
							align-items: center;
							font-weight: 300;
							font-size: 16rpx;
							color: #888888;
							margin-left: 20rpx;
							height: 50rpx;
							display: flex;
							align-items: flex-end;
							padding-bottom: 8rpx;
							text-decoration: line-through;
							.popup-symbol {
								// font-size: 20rpx;
							}
						}

						.popup-clover {
							display: flex;
							align-items: center;
							font-weight: bold;
							font-size: 42rpx;
							color: #EF4235;
							height: 50rpx;

							.clover-img {
								width: 32rpx;
								height: 34rpx;
								margin-right: 6rpx;
							}
						}
					}
				}
			}

			.popup-title {
				color: #333333;
				font-weight: 800;
				font-size: 28rpx;
				margin-top: 48rpx;
				margin-bottom: 24rpx;
			}
			.specification-list{
				// display: flex;
				// align-items: center;
				// flex-wrap: wrap;
				
				width: 100%;
				max-height: 600rpx;
				margin-bottom: 50rpx;
				padding-bottom: 220rpx;
				overflow-y: auto;
				.specification-item {
					z-index: 9999;
					display: inline-block;
					padding: 0 64rpx;
					// width: 200rpx;
					height: 56rpx;
					line-height: 56rpx;
					border: 2rpx solid #B3B3BE;
					border-radius: 28rpx;
					// display: flex;
					// align-items: center;
					// justify-content: center;
					font-size: 24rpx;
					color: #B3B3BE;
					margin-right: 32rpx;
					margin-bottom: 32rpx;
				}
				.specification-item-active {
					border: 2rpx solid #333333;
					color: #333333;
				}
			}
			
			.popup-footer{
				z-index: 9999;
				background-color: #fff;
				// padding-bottom: 20rpx;
				margin-top: 30rpx;
				.footer-num{
					// display: flex;
					// align-items: center;
					// justify-content: space-between;
					z-index: 9999;
					margin-top: 20rpx;
					.footer-info{
						display: flex;
						align-items: center;
						font-size: 28rpx;
						font-weight: 800;
						color: #333333;
						.footer-info-num{
							margin-left: 10rpx;
							font-size: 24rpx;
							color: #999999;
							font-weight: 400;
						}	
					}
					.item-step {
						margin-top: 17rpx;
						z-index: 9999;
						display: flex;
						align-items: center;
					
						.item-sub {
							width: 41rpx;
							height: 41rpx;
						}
					
						.item-num {
							width: 78rpx;
							font-size: 28rpx;
							color: #333333;
							display: flex;
							align-items: center;
							justify-content: center;
						}
					
						.item-add {
							width: 41rpx;
							height: 41rpx;
						}
					}
				}
				.now-buy{
					z-index: 9999;
					margin-top: 46rpx;
					
					
					width: 706rpx;
					height: 88rpx;
					background: linear-gradient(90deg, #EF4033 0%, #FF9F98 100%);
					border-radius: 44rpx;
					
					
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 32rpx;
					color: #FFFFFF;
				}
			}
		}
	}
</style>
