<template>
	<view class="center">
		<view class="top"><image :src="list.data.background_image" mode=""></image></view>
		<view class="name-box">
			<view class="price-box">
				<text class="price">
					{{
						list.data.cost_money_type === list.data.cost_2_money_type
							? list.data.cost * 1 + list.data.cost_money_type
							: list.data.cost * 1 + list.data.cost_money_type + '/' + list.data.cost_2 * 1 + list.data.cost_2_money_type
					}}
				</text>
				<!-- <text class="yuan">￥229</text> -->
			</view>
			<view class="name clamp">{{ list.data.name }}</view>
			<view class="info">
				<view class="info-item">门票：{{ list.data.ticket * 1 }}{{ list.data.ticket_money_type }}</view>
				<view class="info-item">销量：56件</view>
				<view class="info-item">浙江省台州市</view>
			</view>
		</view>
		<view class="tip-box">
			<view class="tip-titele">拼团玩法</view>
			<view class="tip-main">开团/参团-满员开团-拼中发货</view>
		</view>
		<view class="tip-box">
			<view class="tip-titele">拼团须知</view>
			<view class="tip-main">
				本轮预约开始时间:{{ list.start }}
				<br />
				本轮预约结束时间:{{ list.end }}
				<br />
				本轮开奖时间：{{ list.next_pink.name }}
				<br />
				下轮预约开始时间:{{ list.next_pink.name }}
			</view>
		</view>
		<view class="detail">
			<view class="detail-title">商品详情</view>
			<view class="systom"></view>
		</view>
		<view class="btn" @click="buy()">立即拼团</view>
	</view>
</template>
<script>
import { lalaDetial } from '@/api/product.js';
import { getTime } from '@/utils/rocessor.js';
import uniNumberBox from '@/components/uni-number-box.vue';
export default {
	components: {
		uniNumberBox
	},
	data() {
		return {
			id: '',
			list: {}
		};
	},
	onLoad(option) {
		this.id = option.id;
		this.loadData();
	},

	computed: {
		money() {
			return this.num * this.price * this.step;
		}
	},
	onShow() {},
	methods: {
		async loadData() {
			let obj = this;
			lalaDetial({}, obj.id).then(({ data }) => {
				obj.list = data;
				obj.list.end = getTime(data.next_pink.value - data.close_join * 60);
				//当前时间
				for (let i = 0; i < data.open_times.length; i++) {
					//拼团开始时间
					if (data.open_times[i].value == data.next_pink.value) {
						if (i != 0) {
							let j = i - 1;
							obj.list.start = getTime(data.open_times[j].value);
						} else {
							let date = data.open_times[0].name.split(' ');
							let start = date[0] + ' ' + data.lala_pink_open + ':00';
							start = new Date(start);
							start = start.getTime();
							obj.list.start = getTime(start);
						}
					}
				}
				console.log(obj.list);
			});
		},
		buy() {
			//当前时间
			let dateTime = new Date().valueOf();
			let start = new Date(this.list.start).valueOf();
			let end = new Date(this.list.end).valueOf();
			console.log(dateTime, start, end);
			if(dateTime < start){
				this.$api.msg('当前场次还未开始');
				return;
			}
			if(dateTime > end){
				this.$api.msg('当前场次已经结束，请等待下一场');
				return;
			}
			uni.navigateTo({
				url: '/pages/product/pingOrder?id=' + this.id
			});
		},
		changeCurrent(index) {
			this.current = index;
		}
	}
};
</script>

<style lang="scss" scoped>
page,
.center {
	background: #f8f6f6;
	height: 100%;
}
.top {
	width: 750rpx;
	height: 710rpx;
	image {
		width: 100%;
		height: 100%;
	}
}
.name-box {
	padding: 30rpx 26rpx;
	line-height: 1;
	background-color: #ffffff;
	.price-box {
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #e83f30;
		.price {
			font-size: 48rpx;
		}
		.yuan {
			padding-left: 10rpx;
			font-size: 30rpx;
			font-weight: 500;
			text-decoration: line-through;
			color: #999999;
		}
	}
	.name {
		font-size: 34rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #1d2023;
		margin-top: 30rpx;
	}
	.info {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-top: 30rpx;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #999999;
	}
}
.tip-box {
	margin-top: 20rpx;
	padding: 34rpx 60rpx 50rpx 30rpx;
	display: flex;
	align-items: flex-start;
	background-color: #ffffff;
	.tip-titele {
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #3b3b3b;
	}
	.tip-main {
		margin-left: 30rpx;
		width: 500rpx;
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #8a8a8a;
	}
}
.detail {
	.detail-title {
		width: 750rpx;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		font-size: 28rpx;
		font-family: PingFangSC;
		font-weight: bold;
		color: #1d2023;
	}
}
.btn {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	width: 750rpx;
	height: 98rpx;
	background: linear-gradient(0deg, #2e58ff, #32c6ff);
	text-align: center;
	line-height: 98rpx;
	font-size: 36rpx;
	font-family: PingFang SC;
	font-weight: bold;
	color: #ffffff;
}
</style>
