<template>
	<scroll-view class="home" scroll-y @scrolltolower='onBottom'>
		<!-- <van-tabs >
		  <van-tab title="标签 1">内容 1</van-tab>
		  <van-tab title="标签 2">内容 2</van-tab>
		  <van-tab title="标签 3">内容 3</van-tab>
		  <van-tab title="标签 4">内容 4</van-tab>
		</van-tabs> -->
		<view class="top-list">
			<image class="background-img" style="width: 100vw;" src="https://t1-1305573081.cos.ap-shanghai.myqcloud.com/wxapp/static/imgs/%E9%A1%B6%E9%83%A8%E8%83%8C%E6%99%AF3.png"
			 mode="widthFix"></image>
			<topbar class="topbar-slot">
				<view>
					<text style="color: #FFFFFF;">极速生活圈</text>
				</view>
			</topbar>

			<loadSke :loading='topLoading' :list='bannerList'>
				<swiper class="swiper-box" :current="current" autoplay circular indicator-dots>
					<swiper-item v-for="(item,index) in bannerList" :key='index'>
						<image @click="clickJumpType(item)" class="image" :src="item.fileUrl" mode="scaleToFill" :draggable="false" />
					</swiper-item>
				</swiper>

				<view class="eat-box">
					<view class="eat" v-for="(item,index) in couponList" :key='index' @click="clickJumpType(item)">
						<image :src="item.fileUrl" mode="scaleToFill" class="img"></image>
						<view class="text-box">
							<text class="text-1">{{item.pictureName}}</text>
							<text class="text-2">{{item.dataDescribe.split(' ')[0]}}</text>
							<text class="text-3">{{item.dataDescribe.split(' ')[1]}}</text>
						</view>
					</view>
				</view>

				<view class="menu-box">
					<view class="menu" v-for="(item,index) in menuList" :key='index' @click="clickJumpType(item)">
						<image :src="item.fileUrl" mode="scaleToFill" class="img"></image>
						<text class="text-1">{{item.pictureName}}</text>
						<text class="text-2">{{item.dataDescribe || '暂无描述'}}</text>
					</view>
				</view>
			</loadSke>
		</view>

		<view class="bottom-ad" v-for="(item,index) in bottomAD" :key='index' @click="clickJumpType(item)">
			<image style="width: 100%;" :src="item.fileUrl" mode="widthFix"></image>
			<text>今日仅剩{{dynamicQuantity(index)}}个</text>
			<button>免费领取</button>
		</view>

		<view class="item-box">
			<view class="item-titBox">
				<text class="item-tit">限时特价</text>
				<!-- <text class="item-tit-right" @tap='go()'>更多视频 ></text> -->
			</view>
			<loadSke :loading='pddLoading' :list='pddList'>
				<view class="flex-box">
					<view class="film-box" v-for="(item,index) in pddList" :key='index' @click="goMiniApp(JSON.stringify({appId:item.we_app_info.app_id,path:item.we_app_info.page_path}))">
						<image :src="item.goods_image_url" mode="widthFix" class="img" draggable></image>
						<view class="bottom-box">
							<view class="tit">
								<text class="text-1">{{item.goods_name}}</text>
							</view>
							<view class="des-box">
								<view class="des">{{item.unified_tags}}</view>
							</view>
							<view class="buy-box">
								<text class="price">{{'¥'+(item.min_group_price)/100}}</text>
								<button type="default" class="buy">活动价 {{'¥'+(item.min_group_price-item.coupon_discount)/100}}</button>
							</view>
						</view>
					</view>
					<view v-if="pddDataLoading" class="bottom-loading">
						正在加载中...
					</view>
				</view>
			</loadSke>
		</view>
	</scroll-view>
</template>

<script>
	import {
		getHomePageDataList,
		getPDD,
		getPddWxData
	} from '@/api/home.js'
	export default {
		data: () => ({
			bannerList: [],
			couponList: [],
			menuList: [],
			bottomAD: [],
			topLoading: true,
			pddList: [],
			pddLoading: true,
			limit: 6,
			page: 0,
			pddDataLoading: false
		}),
		mounted() {
			this.init()
		},
		methods: {
			onBottom() {
				if (this.pddDataLoading) return
				this.pddDataLoading = true
				this.page++
				getPddWxData({
					limit: this.limit,
					offset: this.page * this.limit
				}).then(res => {
					this.pddList = this.pddList.concat(res)
					this.$nextTick(() => {
						this.pddLoading = false
						this.pddDataLoading = false
					})
				})
			},
			dynamicQuantity(index) {
				index++
				let x = new Date().getHours() / 3
				let num = ((x - 8) ** 2) + index * (8 - x) * 1 + index * 3 + 1
				return parseInt(num)
			},
			init() {
				getHomePageDataList().then(res => {
					this.bannerList = res.data.carouselChart
					this.couponList = res.data.coupon.slice(0, 4)
					this.menuList = res.data.menu
					this.bottomAD = res.data.bottomAD
					this.$nextTick(() => {
						this.topLoading = false
					})
				})
				getPddWxData({
					limit: this.limit,
					offset: this.page * this.limit
				}).then(res => {
					this.pddList = res
					this.$nextTick(() => {
						this.pddLoading = false
					})
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.home{
		height: 100%;
	}
	
	.top-list {
		padding: 30rpx;
		padding-top: 0;
		box-sizing: border-box;
		width: 100%;
		background-color: #FFFFFF;
		position: relative;

		.topbar-slot {
			z-index: 1;
			align-self: center;
			display: flex;
			justify-content: center;
		}

		.background-img {
			position: absolute;
			top: 0;
			left: 0;
		}

		.swiper-box {
			width: 690rpx;
			height: 342rpx;
			overflow: hidden;

			.image {
				width: 100%;
				height: 100%;
				border-radius: 10px;
			}
		}

		.eat-box {
			margin-top: 30rpx;
			display: flex;
			justify-content: space-between;

			.eat {
				width: 158rpx;
				height: 240rpx;
				position: relative;

				.img {
					width: 100%;
					height: 100%;
				}

				.text-box {
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					position: absolute;
					bottom: 10rpx;
					left: 50%;
					width: 100%;
					transform: translateX(-50%);

					.text-1 {
						font-size: 24rpx;
						color: #0F0404;
						text-align: center;
					}

					.text-2 {
						margin-top: 5rpx;
						font-size: 20rpx;
						color: #FE3232;
						text-align: center;
					}

					.text-3 {
						font-size: 20rpx;
						color: #666666;
						text-align: center;
					}
				}

			}
		}

		.menu-box {
			display: flex;
			justify-content: flex-start;
			flex-wrap: wrap;
			margin: 0 -10rpx;

			.menu {
				width: 20%;
				padding: 0 10rpx;
				box-sizing: border-box;
				// height: 121rpx;
				margin-top: 40rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				align-items: center;

				.img {
					flex-shrink: 0;
					width: 83rpx;
					height: 83rpx;
					border-radius: 50%;
				}

				.text-1 {
					margin-top: 10rpx;
					font-size: 24rpx;
					color: #0F0404;
					text-align: center;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}

				.text-2 {
					font-size: 20rpx;
					color: #666666;
					text-align: center;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}
			}
		}


	}

	.bottom-ad {
		margin-top: -15rpx;
		position: relative;

		&:nth-child(2) {
			margin-top: 20rpx;
		}

		text {
			position: absolute;
			top: 104rpx;
			left: 220rpx;
			padding: 10rpx 15rpx;
			background: #FFE1D9;
			font-size: 22rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #A40303;
		}

		button {
			position: absolute;
			top: 67rpx;
			right: 40rpx;
			display: inline-block;
			margin: 0;
			padding: 0rpx 26rpx;
			background: linear-gradient(90deg, #E31818, #ED3E24, #ED4F24);
			border-radius: 30rpx;
			font-size: 26rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #FFFFFF;
		}
	}

	.item-box {
		background-color: #fff;
		// margin-top: 40rpx;

		.item-titBox {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 20rpx;
			border-bottom: 1rpx solid #e8e8e8;

			.item-tit {
				border-left: 8rpx solid #E31818;
				font-size: 30rpx;
				padding: 11rpx;
				margin-left: 20rpx;
			}

			.item-tit-right {
				font-size: 26rpx;
				color: #666666;
				line-height: 58rpx;
				padding: 11rpx;
			}
		}

		.flex-box {
			width: 100%;
			display: flex;
			justify-content: center;
			align-items: flex-start;
			// flex-direction: column;
			flex-wrap: wrap;
			background-color: #F8F8F8;
			padding-bottom: 20rpx;

			.film-box {
				width: 334rpx;
				border-radius: 20rpx;
				overflow: hidden;
				background: #FFFFFF;
				margin: 30rpx 11rpx 0;

				.img {
					width: 100%;
				}

				.bottom-box {
					padding: 30rpx 20rpx;

					.tit {
						display: flex;
						justify-content: space-between;

						.text-1 {
							width: 100%;
							font-size: 26rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							// white-space: nowrap;
						}
					}

					.des-box {
						margin-top: 10rpx;

						.des {
							width: 100%;
							font-size: 22rpx;
							color: #666666;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}
					}

					.buy-box {
						margin-top: 20rpx;
						display: flex;
						justify-content: flex-start;
						align-items: center;

						.price {
							// color: #E31818;
							text-decoration: line-through;
							font-size: 34rpx;
						}

						.buy {
							height: 40rpx;
							background: linear-gradient(90deg, #E31818, #ED3E24, #ED4F24);
							border-radius: 20rpx;
							margin-left: 10rpx;
							font-size: 20rpx;
							color: #FFFFFF;
							display: flex;
							justify-content: center;
							align-items: center;
							white-space: nowrap;
						}
					}

				}

			}

		}

		.bottom-loading{
			margin-top: 5rpx;
			padding: 10rpx;
		}
	}

	.ad-video {
		margin-top: 40rpx;
	}
</style>
