<template>
	<view class="content">
		<!-- 轮播图 -->
		<top-swiper :imgList="imgList"></top-swiper>
		<!-- 价格 -->
		<view class="good-price flex">
			<view class="new-price">
				¥{{goodItem.price}}
			</view>
			<view class="old-price" v-if="goodItem.whole && (goodItem.whole.ot_price*1 > goodItem.price*1)">
				¥{{goodItem.whole.ot_price}}
			</view>
		</view>
		<!-- 标题 -->
		<view class="good-tit" v-if="goodItem.whole">
			{{goodItem.whole.title}}
		</view>
		<content-text :description="description"></content-text>
		<view class="btn-ts" style="height: 130rpx; background-color: #fff;"></view>
		<view class="btm-btn" @click="loading? '':reservePackage()">
			立即预约
		</view>
	</view>
</template>

<script>
	// 头部轮播图
	import topSwiper from './common/topSwiper.vue';
	// 图文详情
	import contentText from './common/contentText.vue';

	import {
		getWholeDetai,
		reservePackage,
		getWholeInfo
	} from '@/api/whole.js'
	export default {
		components: {
			topSwiper,
			contentText
		},
		data() {
			return {
				imgList: [],
				goodItem: {},
				good_id: '',
				time_id: '',
				status: 1,
				is_new: '',
				description: '',
				loading: true,
			}
		},
		onLoad(opt) {
			if (opt.id) {
				this.good_id = opt.id
			}
			if (opt.time) {
				this.time_id = opt.time
				// console.log()
			}
			this.getWholeDetai()
		},
		methods: {
			getWholeDetai() {
				let obj = this

				getWholeInfo({}, obj.good_id).then(({
					data
				}) => {
					console.log(data)
					obj.goodItem = data
					obj.imgList = data.whole.images
					obj.description = data.whole.description.replace(/\<img/gi, '<img class="rich-img"')
					obj.loading = false
				})

			},
			// 预约包
			reservePackage() {
				let obj = this
				if (obj.goodItem.isSeckillEnd.status == 0) {
					obj.$api.msg('今日该场次已结束')
					return
				}
				if (obj.goodItem.isSeckillEnd.status == 2) {
					obj.$api.msg('今日该场次未开始，请稍后')
					return
				}
				let updata = {
					whole_id: obj.goodItem.whole.id,
					time_id: obj.time_id,
					price: obj.goodItem.price,
					to_uid: obj.goodItem.to_uid,
					first_price: obj.goodItem.first_price,
					last_id: obj.goodItem.id
				}
				console.log(updata, 'updata')
				obj.loading = true
				reservePackage(updata).then(res => {
					uni.showToast({
						title: '预约成功',
						duration: 2000
					});
					setTimeout(function() {
						uni.navigateTo({
							url: '/pages/user/myWholesale'
						});
					}, 800);
				}).catch(err => {
					obj.loading = false
					console.log(err)
					this.getWholeDetai()
				})
			}

		},

	}
</script>

<style lang="scss" scoped>
	.good-price {
		padding-left: 20rpx;
		padding-top: 20rpx;
		justify-content: flex-start;
		background-color: #fff;

		// align-items: f;
		.new-price {
			font-size: 50rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #FF4C4C;
		}

		.old-price {
			padding-left: 8rpx;
			font-size: 33rpx;
			font-family: PingFang SC;
			font-weight: bold;
			text-decoration: line-through;
			color: #999999;

		}

	}

	.good-tit {
		padding: 20rpx;
		background-color: #fff;
	}

	.btm-btn {
		position: fixed;
		bottom: 35rpx;
		left: 0;
		right: 0;
		margin: auto;
		width: 699rpx;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		background: linear-gradient(90deg, #FE6F61 0%, #FF4343 100%);
		border-radius: 45rpx;
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		// background-color: #fff;
	}

	/* 商品详情中限制图片大小 */
	/deep/ .rich-img {
		width: 100% !important;
		height: auto;
	}
</style>
