<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">
				¥{{goodItem.ot_price}}
			</view>
		</view>
		<!-- 标题 -->
		<view class="good-tit">
			{{goodItem.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: false,
			}
		},
		onLoad(opt) {
			if (opt.id) {
				this.good_id = opt.id
			}
			if (opt.time) {
				this.time_id = opt.time
			}
			if (opt.status) {
				this.status = opt.status
			}

			if (opt.is_new) {
				this.is_new = opt.is_new
			}

			this.getWholeDetai()
		},
		methods: {
			getWholeDetai() {
				let obj = this
				if (obj.is_new) {
					getWholeDetai({}, obj.good_id, obj.time_id, obj.status, 1).then(({
						data
					}) => {
						obj.goodItem = data.storeInfo
						obj.imgList = data.storeInfo.images
						obj.description = data.storeInfo.description.replace(/\<img/gi, '<img class="rich-img"')
					})
				} else {
					getWholeInfo({},obj.good_id).then(({data}) => {
						obj.goodItem = data.storeInfo
						obj.imgList = data.storeInfo.images
						obj.description = data.storeInfo.description.replace(/\<img/gi, '<img class="rich-img"')
					})
					// getWholeDetai({}, obj.good_id, obj.time_id, obj.status, 0).then(({
					// 	data
					// }) => {
					// 	obj.goodItem = data.storeInfo
					// 	obj.imgList = data.storeInfo.images
					// 	obj.description = data.storeInfo.description.replace(/\<img/gi, '<img class="rich-img"')
					// })
				}

			},
			// 预约包
			reservePackage() {
				let obj = this
				let updata = {
					whole_id: obj.good_id,
					time_id: obj.time_id,
					price: obj.goodItem.price,
					to_uid: obj.is_new == 'isn' ? 0 : '',
					first_price: obj.is_new == 'isn' ? 0 : '',
					last_id: obj.is_new == 'isn' ? 0 : ''
				}
				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)
				})
			}
		}
	}
</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>
