<!-- 商品各个样式组件 -->
<template>
	<view class="container">
		<!-- _goods_type_1  商品样式1 -->
		<block v-if="goodsType==='goods_type1'">
			<view class="groupon_goods5 groupon_goods5-pading" :style="{marginBottom:goodsData.style.marginBottom*2+'rpx',padding:goodsData.style.margin*2+'rpx',backgroundColor:goodsData.style.bgColor}">
				<view class="b-f" :style="{paddingLeft:goodsData.style.padding*2+'rpx',paddingTop:goodsData.style.padding*2+'rpx',paddingBottom:goodsData.style.padding*2+'rpx',paddingRight:'0'}">
					<scroll-view scroll-x="true">
						<view class="groupon_goods5-list dis-flex">
							<view class="groupon_goods5-list-item m-right20" v-for="(goods,index) in goodsData.data" :key="index" @click="navigateTo(goods.url)">
								<view class="groupon_goods5-image" :style="{'background-image':'url('+goods['logo']+')'}">
									<image v-if="goods.stk == 0" style="width: 250upx;height: 250upx;background-color: rgba(0,0,0,0.5);" :src="imgfixUrls  + 'rush_goods_sell_out.png'" mode="aspectFit"></image>
								</view>
								<view class="groupon_goods5-title twolist-hidden f-28 col-3 m-top20">{{goods['goods_name']}}</view>
								<view class="groupon_goods5-price dis-flex flex-y-center flex-x-between">
									<view class="now-price f-28">￥{{goods['price']}}</view>
									<view class="old-price f-24" style="text-decoration:line-through;">￥{{goods['oldprice']}}</view>
								</view>
							</view>
						</view>
					</scroll-view>
				</view>
			</view>
		</block>
	</view>
</template>
<script>
	import App from "@/common/js/app.js"
	export default {
		data() {
			return {

			}
		},
		props: {
			goodsData: {
				type: Object,
				default: function() {
					return {}
				}
			},
			goodsType: {
				type: String,
				default: function() {
					return ''
				}
			}
		},
		components: {

		},
		computed: {

		},
		onShow() {

		},
		mounted() {
			this.setEndTime()
		},
		methods: {
			//  倒计时
			setEndTime() {
				if (this.goodsType === 'goods_type4') {
					setInterval(() => {
						let _this = this,
							nowTime = new Date().getTime();
						for (let i in _this.goodsData.data) {
							// 开始时间
							let startTime = Number(_this.goodsData.data[i].starttime) * 1000,
								// 截止时间
								endTime = Number(_this.goodsData.data[i].endtime) * 1000,
								// 距离结束时间
								leftTime = parseInt((endTime - nowTime) / 1000),
								// 距离开始时间
								rightTime = parseInt((startTime - nowTime) / 1000),
								// 每个商品活动时间
								timeobj = {},
								callback = function(dataTime, timeType) {
									let hh = parseInt(dataTime / 60 / 60 / 24 * 24),
										mm = parseInt(dataTime / 60 % 60),
										ss = parseInt(dataTime % 60),
										timeobj = {
											hh: hh < 10 ? '0' + `${hh}` : hh,
											mm: mm < 10 ? '0' + `${mm}` : mm,
											ss: ss < 10 ? '0' + `${ss}` : ss
										};
									_this.$set(_this.goodsData.data[i], 'timeobj', timeobj)
									_this.goodsData.data[i].stateTime = timeType === 'left' ? 1 : 2;
								};
							if (leftTime > 0 && rightTime <= 0) {
								if (nowTime > startTime && nowTime < endTime) {
									callback(leftTime, 'left')
								}
							} else if (rightTime > 0 && leftTime > 0) {
								if (startTime > nowTime && nowTime < endTime) {
									callback(rightTime, 'right')
								}
							} else {
								_this.goodsData.data[i].isTimeOver = true;
								return false
							}
						}
					}, 1000);
				}
			},
			navigateTo(url) {
				let isHttpUrl = url.indexOf('https') !== -1;
				if (isHttpUrl) {
					location.href = url;
				} else {
					App.navigationTo({
						url
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import url('../../../common/css/diyPages.css')
</style>
