<template>
	<view class="page">
		<navbar
		bgColor="transparent"
		style="position: absolute;"
		leftClick @leftClick="$utils.navigateBack" />
		
		<view class="swipe">
			<uv-swiper 
			:list="productDetail.image
			&& productDetail.image.split(',')" 
			indicator
			height="520rpx"></uv-swiper>
		</view>
		
		<view class="info">
			<view style="width: 440rpx;">
				<view class="title">
					{{ productDetail.title }}
				</view>
				<view class="desc">
					{{ productDetail.sku }}
				</view>
			</view>
			<view class=""
			v-if="[2].includes(productDetail.type)">
				<view class="price">
					会员价￥<text>{{ productDetail.vipPrice }}</text>
				</view>
				<view class="oldPrice">
					零售价￥<text>{{ productDetail.price }}</text>
				</view>
			</view>
			
			<view class=""
			v-else>
				<view class="price">
					价格￥<text>{{ productDetail.price }}</text>
				</view>
				<view class="oldPrice">
					原价￥<text>{{ productDetail.oldPrice }}</text>
				</view>
			</view>
		</view>
		
		<uv-parse :content="productDetail.details"></uv-parse>
		
		<!-- 分享和购买按钮 -->
		<submit 
		@addCart="addCart"
		@submit="submit"
		:detail="productDetail"
		/>
		
		<!-- <submit
		@submit="$refs.submitUnitSelect.open()"
		@share="share"/> -->
		
		<!-- 选择规格 -->
		<!-- <submitUnitSelect 
		:detail="productDetail"
		ref="submitUnitSelect"/> -->
	</view>
</template>

<script>
	import submit from '../components/product/submit.vue'
	import submitUnitSelect from '../components/product/submitUnitSelect.vue'
	export default {
		components : {
			submit,
			submitUnitSelect
		},
		data() {
			return {
				productDetail : {
					image : '',
					details : '',
				},
				id : 0,
			}
		},
		onLoad(args) {
			this.id = args.id
		},
		onShow() {
			this.getRiceProductDetail()
		},
		methods: {
			// 分享商品
			share(){
				
			},
			// 立即下单
			submit(){
				
				this.$store.commit('setPayOrderProduct', [
					this.productDetail
				])
				
				this.$utils.navigateTo('/pages_order/order/createOrder')
			},
			// 获取商品
			getRiceProductDetail(){
				this.$api('getRiceProductDetail', {
					id : this.id
				}, res => {
					if(res.code == 200){
						res.result.num = 1
						this.productDetail = res.result
					}
				})
			},
			// 添加购物车
			addCart(){
				this.$api('addCart', {
					shopId : this.id,
					num : 1,
				}, res => {
					if(res.code == 200){
						uni.showToast({
							title: '加入购物车成功',
							icon: 'none'
						})
					}
				})
			},
		}
	}
</script>

<style scoped lang="scss">
.page{
	.swipe{
		
	}
	.info{
		padding: 30rpx;
		background-color: #fff;
		display: flex;
		justify-content: space-between;
		.title{
			font-size: 34rpx;
			font-weight: 900;
		}
		.price{
			font-size: 34rpx;
			color: $uni-color;
			font-weight: 900;
			text-align: right;
		}
		.oldPrice{
			font-size: 26rpx;
			color: #999;
			text-align: right;
			// text-decoration: line-through;
			margin-top: 14rpx;
		}
		.desc{
			font-size: 26rpx;
			color: #777;
			margin-top: 20rpx;
		}
	}
	.info-unit{
		margin-top: 20rpx;
		padding: 30rpx;
		background-color: #fff;
		/deep/ text{
			font-size: 26rpx;
		}
		/deep/ .text{
			color: #7C7C7C;
			margin-right: 20rpx;
			font-size: 26rpx;
		}
	}
}
</style>
