<template>
	<div class="module-item-goods" :style="!module.base.m ? 'margin-top:0' : ''" v-if="list.length>0">
		<div class="item-goods-con" :style="style">
			<view class="">
				<moduleBg :base="module.base" />
				<moduleTwtit :miaosha='miaosha' :type="module.type" :title="module.title" v-if="module.title.s" />
			</view>
			<div class="item-goods-style1" :class="module.base.s == 1 ? 'style2' : ''">
				<div class="scroll-true flex-grow-1">
					<div class="item" style="width: 30%;" v-for="(item, index) in list" :key="index"
						@click="$util.openMsGoods(list,index)">
						<div class="pic" style="height: auto;">
							<image style="width: 100%;height: 212upx;" class="pic_img" :src="url+item.thumb" />
						</div>
						<div class="c" style="padding: 0 5px;">
							<div class="tit" v-if="module.base.t.s">
								<moduleText :text="module.base.t" :name="item.name" />
							</div>
							<div class="price" v-if="module.base.sjg ">
								<template v-if="module.base.sjg">
									<span>
										<b>￥{{ item.price }}</b>
									</span>
								</template>
							</div>
							<div v-if="module.base.sgm">
								<span style="text-decoration:line-through;color: #999" class='ft24'>
									￥{{item.original_price }}
								</span>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="noadd" v-if="list.length == 0">
				暂无秒杀商品
			</div>
		</div>
	</div>
</template>
<script>
	import moduleBg from './bg.vue';
	import moduleText from './text.vue';
	import moduleTwtit from './twtit.vue';
	export default {
		props: ['module'],
		components: {
			moduleBg,
			moduleText,
			moduleTwtit
		},
		data() {
			return {
				url: getApp().globalData.URL,
				shopList: [],
				t: {},
				list: [],
				miaosha: {},
			};
		},

		computed: {
			style() {
				if (this.module.base.fc != '') {
					return `color:${this.module.base.fc}`;
				}
			},
		},

		mounted() {
			this.getGoodsList();
		},

		methods: {
			//获取商品列表
			getGoodsList() {
				// console.log(this.module, "获取商品列表")
				this.$http.request('seckill/index', {
					store_id: this.$store.state.store_id,
					controller: "admin",
					page: 1,
					limit: 8,
				}, "", "", "").then(t => {
					// console.log(t, "列表")
					if (t.code == 200) {
						var name = '',
							times = 0;
						var shopList = [];
						var timestamp = Date.parse(new Date()) / 1000; //当前时间
						if (t.data.start_time && t.data.end_time) {
							var s_time = t.data.start_time - timestamp;
							var end_time = t.data.end_time - timestamp;
							if (s_time > 0) {
								name = '活动未开始'
								times = s_time;
							}
							if (s_time < 0 && end_time > 0) {
								name = '活动进行中'
								times = end_time;
							}
							if (end_time < 0) {
								name = '活动已结束'
								times = 0;
							}
							var miaosha = {
								start_time: t.data.start_time,
								end_time: t.data.end_time,
								name: name,
								rest_time: times,
							}
							this.module.miaosha = miaosha;
							this.miaosha = miaosha;
							for (let i of t.data.list) {
								shopList.push({
									name: i.name,
									price: i.price,
									original_price: i.original_price,
									thumb: i.image_brief,
									id: i.id
								})
							}
							this.list = shopList;
							this.module.list = shopList;
						} else {
							var miaosha = {
								start_time: 0,
								end_time: 0,
								name: '活动已结束',
								rest_time: 0,
							}
							this.module.miaosha = miaosha;
							this.miaosha = miaosha;
							this.list = shopList;
							this.module.list = shopList;
						}
						// console.log(s_time, timestamp,this.module.miaosha,"this.module.miaosha")
						// console.log(this.module,"this.module.list")
					}

				}).catch((function(e) {}))

			},
		},

	};
</script>

<style>
	@import url("./goods.css");
	.module-item-goods {
		margin-top: 10px;
	}

	.scroll-true {
		white-space: nowrap;
		overflow-x: auto;
	}

	.scroll-true .item {
		display: inline-block;
		width: 30%;
		margin-right: 10px;
	}

	.el-scrollbar__wrap {
		overflow-y: hidden;
	}

	.pic_img {
		width: 106px;
		height: 106px;
	}

	.item-goods-style1 {
		position: relative;
		padding: 20rpx 0;
	}

	.noadd {
		position: relative;
		color: #999;
	}
</style>
