<template>
	<view class="page">
		<!-- <view style="position: fixed;left:0px;z-index: 100;" :style="{'top': statusBaeHeight + 58 + 'px'}">
			<view class="search-box" style="background: #F2F2F2;">
				<input type="text" disabled placeholder="搜索酒款/酒厂" @click="toSearch">
			</view>
		</view> -->
		<view v-if="showJoinImg && bannerJoin" class="join-box" @click="toJoin">
			<image :src="bannerJoin.bannerUrl" class="img"></image>
		</view>
		<!-- 轮播 -->
		<swiper v-else class="join-box" circular :autoplay="true" :indicator-dots="true">
			<swiper-item v-for="(item,index) in homeBanner" :key="index">
				<image :src="item.bannerUrl" class="img"></image>
			</swiper-item>

		</swiper>

		<!-- 快捷导航 -->
		<view class="bg-white"
			style="border-radius: 30rpx 30rpx 12rpx 12rpx;padding-top:8rpx;position: relative;margin-top:-20rpx">
			<view class="search-box">
				<text class="cuIcon-search" style="font-size: 40rpx;color: #A2A2A2;margin-right: 24rpx;"></text>
				<input type="text" disabled placeholder="搜索酒款/酒厂" @click="toSearch">
			</view>
			<view class="flex justify-between bg-white" style="padding: 20rpx 36rpx;">
				<view class="nav-item" @click="toGo(1)">
					<view class="flex justify-center align-center img-box">
						<image src="/static/nav-1.png" style="width: 48rpx;height: 48rpx;"></image>
					</view>
					<text class="text-bold">新酒上市</text>
				</view>
				<view class="nav-item" @click="toGo(2)">
					<view class="flex justify-center align-center img-box">
						<image src="/static/nav-2.png" style="width: 48rpx;height: 48rpx;"></image>
					</view>
					<text class="text-bold">生成酒单</text>
				</view>
				<view class="nav-item" @click="toGo(3)">
					<view class="flex justify-center align-center img-box">
						<image src="/static/nav-3.png" style="width: 48rpx;height: 48rpx;"></image>
					</view>
					<text class="text-bold">酒币换购</text>
				</view>
				<view class="nav-item" @click="toGo(4)">
					<view class="flex justify-center align-center img-box">
						<image src="/static/nav-4.png" style="width: 48rpx;height: 48rpx;"></image>
					</view>
					<text class="text-bold">关注厂牌</text>
				</view>
			</view>
		</view>


		<commonTitle title="热门活动招募"></commonTitle>
		<!-- 专辑列表 -->
		<view v-for="(item,i) in featurePageList" :key="i" class="bg-white">
			<view class="flex justify-between align-center title-box" @click="toFeaturePage(item)">
				<view class="flex-1 flex flex-col">
					<text class="title">{{ item.pageName }}</text>
					<text class="sub">{{ item.subTitle}}</text>
				</view>
				<image src="@/static/arrow-right.png" style="width: 48rpx;height: 48rpx;"></image>
			</view>
			<rowBeer :beers="item.beers" />
			<!-- <scroll-view scroll-x="true" class="scroll-container">
				<view v-for="(it, index) in item.beers" :key="index" style="display: inline-block;" class="row-box" @click="toReview(it)">
					<view class="beer-box">
						<image :src="it.cover" class="cover"></image>
						<view class="title word-all">{{ it.beerName || ''}}</view>
						<view class="desc word-all">{{ it.beerStyles || '' }}</view>
						<view class="desc word-all">{{ it.brandName ||'' }}</view>
						<view class="flex align-center num">
							<image src="@/static/vector.png" style="width: 20rpx;height: 20rpx;margin-right: 10rpx;">
							</image>
							{{ it.beerOverallRating || 0 }}（{{ it.beerReviewsCount || 0}}）
						</view>
					</view>
				</view>
				
			</scroll-view> -->
		</view>
		<view v-if="showJoinImg" class="weixin-box">
			<text>入驻助理在线服务，1对1咨询使用指南~</text>
			<view class="bg-zd btn" @click="toAddAiad">立即添加</view>
		</view>
		<loginPopup ref="loginRef" @loginSuccess="loginSuccess"></loginPopup>
		<!-- 开屏广告 -->
		<uni-popup ref="ADRef" type="center" :is-mask-click="false" maskBackgroundColor="rgba(0,0,0,0.7)">
			<view class="flex flex-col align-center justify-center" style="width: 630rpx;height: 61vh;">
				<swiper class="swiper" style="width: 630rpx;height: 58vh;" circular :autoplay="true"
					:indicator-dots="true">
					<swiper-item v-for="(item,index) in ADList" :key="index">
						<image :src="item.bannerUrl" style="width: 630rpx;height: 50vh;border-radius: 30rpx;"
							@click="handleAD(item)">
						</image>
					</swiper-item>
				</swiper>
				<text class="cuIcon-roundclose text-white" style="font-size: 68rpx !important;" @click="closeAd"></text>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		getBannerList
	} from '@/api/bar.js'
	import {
		listFeaturePage
	} from '@/api/platform.js'
	import commonTitle from '@/components/commonTitle.vue'
	import loginPopup from '@/components/loginPopup.vue';
	import rowBeer from '@/components/rowBeer.vue'
	export default {
		components: {
			commonTitle,
			loginPopup,
			rowBeer
		},
		data() {
			return {
				statusBaeHeight: 0,
				curTag: 0,
				ADList: [], // 广告弹窗
				bannerJoin: null, // 入驻banner
				showJoinImg: false, // 是否显示入驻图片
				userInfo: null,
				featurePageList: [], // 专辑页列表
				homeBanner: [], //首页banner
			};
		},
		onLoad() {
			// setTimeout(() => {
			// 	uni.setNavigationBarColor({
			// 		frontColor: '#ffffff',
			// 		backgroundColor: '#FFFFFF',
			// 		animation: {
			// 			duration: 400,
			// 			timingFunc: 'easeIn'
			// 		}
			// 	})
			// }, 500)
			this.statusBaeHeight = uni.getWindowInfo.statusBarHeight
			this.getBannerListFun() // 广告轮播图
			uni.showShareMenu({
				menus: ['shareAppMessage', 'shareTimeline']
			})
		},
		onShow() {
			this.userInfo = uni.getStorageSync('userInfo')
			if (this.userInfo == null || this.userInfo.userType == '09') { // 没登录或者没入驻
				this.showJoinImg = true
			}else {
					this.showJoinImg = false
				}
			this.getFeaturePageListFun() // 专辑页列表
		},
		// onPullDownRefresh(){
		// 	this.getFeaturePageListFun() // 专辑页列表
		// },

		methods: {
			loginSuccess() {
				this.userInfo = uni.getStorageSync('userInfo')
				
				if (this.userInfo == null || this.userInfo.userType == '09') { // 没登录或者没入驻
				console.log('登录')
					this.showJoinImg = true
				}else {
					this.showJoinImg = false
				}
			},
			toAddAiad() {
				uni.navigateTo({
					url: '/pagesMy/addAiad'
				})
			},
			// 搜索
			toSearch() {
				// uni.navigateTo({
				// 	url: '/pages/index/searchBeer'
				// })
				uni.navigateTo({
					url: '/pagesActivity/homeSearch'
				})
			},
			changeTag(index) {
				this.curTag = index
			},
			// 查询广告弹窗 banner列表
			getBannerListFun() {
				this.ADList = []
				this.homeBanner = []
				this.bannerJoin = null
				getBannerList().then(res => {
					res.data.forEach(it => {
						if (it.bannerType == 'homeAD') { // 开屏广告
							this.ADList.push(it)
						} else if (it.bannerType == 'homeJoin') { // 入驻
							this.bannerJoin = it
						} else if (it.bannerType == 'homeBanner') { // 首页banner
							this.homeBanner.push(it)
						} 
						
					})
					
					let showHomeAD = uni.getStorageSync('showHomeAD')
					if (!showHomeAD) {
						
						this.$refs.ADRef.open()
						
					}

				})
			},
			// 关闭广告
			closeAd() {
				uni.setStorageSync('showHomeAD', true)
				uni.setTabBarStyle({
					backgroundColor: '#ffffff'
				})
				this.$refs.ADRef.close()

			},
			handleAD(item) {
				this.closeAd()
				if (item.bannerLink) {
					uni.navigateTo({
						url: item.bannerLink,
					})
				}
			},
			// 立即入驻
			toJoin() {
				if (!this.bannerJoin) return
				uni.navigateTo({
					url: this.bannerJoin.bannerLink,
				})
			},
			// 跳转专辑页
			toFeaturePage(item) {
				uni.navigateTo({
					url: `/pages/index/featureInfo?id=${item.id}`
				})
			},
			// 查询专辑页列表
			getFeaturePageListFun() {
				listFeaturePage().then(res => {
					this.featurePageList = res.data
				})
			},
			// 跳转酒评页
			toReview(it) {
				uni.navigateTo({
					url: "/pages/index/review?beerId=" + it.id
				})
			},
			toGo(key) {
				switch (key) {
					case 1: // 新酒上市
						uni.navigateTo({
							url: "/pages/index/newBeer"
						})
						break;
					case 2: // 生成酒单
						if (!uni.getStorageSync('token')) {
							this.$refs.loginRef.open()
							return
						}
						uni.navigateTo({
							url: "/pagesActivity/winelist"
						})
						break;
					case 3: //酒币换购

						if (!uni.getStorageSync('token')) {
							this.$refs.loginRef.open()
							return
						}
						uni.navigateTo({
							url: "/pagesCoin/beerCoin"
						})
						break;
					case 4: // 关注酒厂
						if (!uni.getStorageSync('token')) {
							this.$refs.loginRef.open()
							return
						}
						uni.navigateTo({
							url: '/pagesMy/myAttention'
						})
						break;
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	/deep/.uni-popup {
		z-index: 1025;
	}

	.page {
		// background: #FDFDFD;
		height: 100vh;
		overflow-y: auto;
		// padding-bottom: calc(110rpx + constant(safe-area-inset-bottom));
		// padding-bottom: calc(110rpx + env(safe-area-inset-bottom));
	}

	.search-box {
		border-radius: 80rpx;
		width: 700rpx;
		height: 80rpx;
		background-color: rgba(243, 243, 243, 0.8);
		display: flex;
		align-items: center;
		padding: 32rpx 30rpx;
		margin: 26rpx auto;
		box-sizing: border-box;

		input {
			width: 100%;
			height: 100%;
			background-color: transparent;
			font-size: 28rpx;
		}
	}

	.join-box {
		// margin: 20rpx 0;
		// border-radius: 30rpx;
		box-sizing: border-box;
		// border: 1.5px solid #F2F2F2;
		// padding: 34rpx 26rpx;
		// height: 450rpx;
		// height: 1130rpx;
		height: 536rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-around;

		.btn {
			width: 582rpx;
			height: 68rpx;
			border-radius: 24rpx;
			text-align: center;
			line-height: 68rpx;
			margin: 0 auto;
		}

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

		}
	}

	.swiper {
		margin-bottom: 20rpx;
		height: 400rpx;
	}

	// 快捷导航
	.nav-item {
		text-align: center;
		color: #0B0E26;

		.img-box {
			width: 146rpx;
			height: 146rpx;
			background: #F2F2F2;
			border-radius: 50%;
			margin-bottom: 18rpx;
		}
	}

	.quickNav-box {
		border-radius: 20rpx;
		background: #FFFFFF;
		width: 100%;
		padding: 32rpx 24rpx;
		height: 490rpx;
		box-sizing: border-box;

		.left {
			height: 416rpx;
			width: 352rpx;
			// width: 47%;
			border-radius: 20rpx;
			margin-right: 22rpx;
		}

		.right {
			height: 196rpx;
			// width: 326rpx;
			width: 100%;
			margin-bottom: 22rpx;
			border-radius: 20rpx;
		}
	}

	.goods-box {
		border-radius: 30rpx;
		background: rgba(255, 255, 255, 0.2);
		box-sizing: border-box;
		border: 1px solid #F2F2F2;
		box-shadow: 0px 5.47px 43.78px 0px rgba(0, 0, 0, 0.05);
		display: flex;
		padding: 16rpx 32rpx;
		margin: 20rpx 32rpx 0;

		.cover {
			width: 208rpx;
			height: 300rpx;
			border-radius: 30rpx;
			margin-right: 14rpx;
		}
	}

	.tag {
		background-color: transparent;
		border-radius: 12rpx;
		padding: 12rpx 20rpx;
		border: 1px solid #9D9D9D;
		;
		margin-right: 24rpx;
		margin-bottom: 50rpx;
	}

	.active-tag {
		background-color: #FEE034;
		font-weight: bold;
		border: 1px solid #FEE034;

	}

	.title-box {
		padding: 24rpx 32rpx;
		margin-bottom: 28rpx;
		box-sizing: border-box;

		.title {
			font-size: 32rpx;
			font-weight: bold;
			color: #1E2019;
			line-height: 130%;
		}

		.sub {
			font-size: 20rpx;
			color: #9D9D9D;
			margin-top: 18rpx;
		}
	}

	// .scroll-container {
	// 	display: flex;
	// 	flex-direction: row;
	// 	white-space: nowrap;
	// 	min-height: 505rpx;
	// 	// padding-bottom: 10rpx;
	// 	margin-bottom: 32rpx;
	// 	.row-box {
	// 		&:nth-child(1) {
	// 			margin-left: 32rpx;
	// 		}
	// 	}
	// 	.beer-box {
	// 		width: 208rpx;
	// 		background: #FFFFFF;
	// 		margin-right: 16rpx;
	// 		margin-bottom: 36rpx;
	// 		box-sizing: border-box;
	// 		display: flex;
	// 		flex-direction: column;
	// 		justify-content: flex-start;
			

	// 		.cover {
	// 			width: 208rpx;
	// 			height: 300rpx;
	// 			border-radius: 12rpx;
	// 			margin-bottom: 18rpx;
	// 		}

	// 		.title {
	// 			font-size: 28rpx;
	// 			color: #1E2019;
	// 			margin-bottom: 12rpx;
	// 			color: #19191B;
	// 		}

	// 		.desc {
	// 			font-size: 24rpx;
	// 			color: #A5A7B9;
	// 			margin-bottom: 12rpx;
	// 			color: #979797;
	// 		}

	// 		.num {

	// 			font-size: 20rpx;
	// 			color: #5F5F63;
	// 		}
	// 	}
	// }

	.weixin-box {
		position: fixed;
		// bottom: 130rpx;
		// bottom: calc(100rpx + env(safe-area-inset-bottom) / 2);
		bottom: 38rpx;
		background: rgba(0, 0, 0, 0.6);
		border-radius: 12rpx;
		height: 80rpx;
		width: 90%;
		box-sizing: border-box;
		margin: 0 32rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 34rpx;
		font-size: 20rpx;
		color: #FFFFFF;

		.btn {
			border-radius: 12rpx;
			background: #39E5B1;
			width: 124rpx;
			height: 38rpx;
			line-height: 38rpx;
			text-align: center;
			font-size: 20rpx;
			color: #000000;
			font-weight: 500;
		}

	}
</style>