<!--
 * @Author: ch
 * @Date: 2022-03-23 10:07:48
 * @LastEditors: ch
 * @LastEditTime: 2022-04-21 16:45:14
 * @Description: file content
-->
<template>
	<view class="seckill" @click="$Router.push('/seckill')">
		<view class="seckill-title">
			<view class="seckill-title--left">
				<text class="seckill-title--text">限时秒杀</text>
				<view class="seckill-title--time">
					<text class="seckill-title--time-name">{{activityTimeVO.timeName}}</text>
					<image class="seckill-title--time-icon" src="@/static/index/time.png"></image>
					<text class="seckill-title--time-time">{{timerStr}}</text>
				</view>
			</view>
			<view class="seckill-title--more">
				<text>查看更多</text>
				<image class="seckill-title--more-icon" src="@/static/index/arrow.png"></image>
			</view>
		</view>
		<view class="seckill--group">
			<view v-for="item in data.activityProductListVO" :key="item.activityProductId">
				<view  class="seckill--item-img-box">
					<image class="seckill--item-img" :src="item.productMainPicture"></image>
				</view>
				<UiMoney class="seckill--item-pirce" :money="item.activityPrice" prefix></UiMoney>
				<text class="seckill--item-original-pirce">￥{{item.originalPrice}}</text>
			</view>
		</view>
	</view>
</template>
<script>
import UiMoney from '../../../components/UiMoney.vue';
export default {
	components: { UiMoney },
	props : {
		data : {
			type : Object,
			default: () => ({
				activityTimeVO : {
					timeName : 'xx'
				}
			})
		}
	},
	data(){
		return {
			timerStr : '00:00:00',
			secondNum : 0
		}
	},
	computed:{
		activityTimeVO (){
			return this.data.activityTimeVO || {}
		}
	},
	watch:{
		/**
		 * 监听数据变化后，做倒计时
		 */
		data(nVal){
			const {isStartActivity, activityTimeVO:{startTime, endTime }, currentTime} = nVal;
			if(endTime){
				let curTime = (new Date(`2022/01/01 ${currentTime}`)).getTime(),
					expireTime = 0;
				if(isStartActivity){
					// 已开始秒杀 显示距结束倒计时
					expireTime = (new Date(`2022/01/01 ${endTime}`)).getTime();
				}else{
					// 即将开抢 显示距开始倒计时
					expireTime = (new Date(`2022/01/01 ${startTime}`)).getTime();
				}
				const second = Math.floor((expireTime - curTime) / 1000);
				this.secondNum = second > 0 ? second : 0;
				this.timer();
			}
		}
	},
	methods:{
		timer(){
			
			if(this.secondNum == 0){
				this.timerStr = this.data.isStartActivity ? '已结束' : '已开始';
				return;
			}
			this.secondNum--;
			let hours = parseInt(this.secondNum / 3600)
			let minute = parseInt((this.secondNum - hours * 3600) / 60);
			let second = parseInt(this.secondNum % 60);
				hours = hours > 9 ? hours : `0${hours}`;
				minute = minute > 9 ? minute : `0${minute}`;
				second = second > 9 ? second : `0${second}`;
			this.timerStr = `${hours}:${minute}:${second}`;
			setTimeout(()=>this.timer(),1000)
		}
	}

}
</script>
<style lang="scss" scoped>
.seckill{
	height: 424rpx;
	width: 690rpx;
	margin: 0 auto;
	padding: 30rpx;
	background: #fff;
	border-radius: 20rpx;
	&-title{
		height: 36rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		&--text{
			font-size: 36rpx;
			font-weight: bold;
		}
		&--left{
			display: flex;
			align-items: center;
		}
		&--time{
			display: flex;
			height: 38rpx;
			line-height: 36rpx;
			border-radius: 18rpx;
			margin-left: 36rpx;
			background: #FFEDE9;
			overflow: hidden;
			align-items: center;
		}
		&--time-name{
			height: 100%;
			padding: 0 32rpx 0 15rpx;
			background: url('@/static/index/time_bg.png') right top no-repeat #FF512B;
			background-size: 32rpx;
			font-size: 22rpx;
			color: #fff;
			position: relative;
			
			
		}
		&--time-time{
			margin-right: 5rpx;
			padding-right: 10rpx;
			font-size: 22rpx;
			color: #FF512B;
			position: relative;
		}
		&--time-icon{
			width: 22rpx;
			height: 22rpx;
			margin-right: 8rpx;
		}
		&--more{
			display: flex;
			align-items: center;
			text{
				font-size: $font-size-sm;
				color: $color-grey4;
			}
			
		}
		&--more-icon{
			width: 10rpx;
			height: 20rpx;
			margin-left: 10rpx;
		}
	}
	&--group{
		display: flex;
		justify-content: space-between;
		margin-top: 30rpx;
	}
	&--item{
		&-img-box{

			width: 200rpx;
			height: 200rpx;
			border-radius: 8rpx;
			background: #F8F8F8;
		}
		&-img{
			width: 100%;
			height: 100%;
		}
		&-pirce{
			text-align: center;
			margin-top: 24rpx;
		}
		&-original-pirce{
			display: block;
			font-size: 22rpx;
			color: #999;
			text-decoration: line-through;
			text-align: center;
			margin-top: 6rpx;
			
		}
	}


	
}
/deep/ {
	.seckill--item-pirce{
		text{
			color: $color-yellow4;
			font-size: $font-size-lg;
			font-weight: bold;
		}
		.ui-money--prefix{
			font-size: $font-size-base;
		}
	}
}

</style>