<template>
	<view class="center">
		<!-- 顶部logo and 搜索 start-->
		<view class="top-search flex">
			<view class="top-logo">
				<image src="../../static/icon/sh-log.png" mode=""></image>
			</view>
			<view class="search-box flex" @click="clickSearch()">
				<image class="search" src="../../static/icon/search-h.png" mode=""></image>
				<view class="search-font">输入关键词搜索</view>
			</view>
		</view>
		<!-- 顶部logo and 搜索 end-->
		<view class="jg"></view>
		<!-- 轮播图 start -->
		<swiper class="top-swiper" autoplay="true" duration="400" interval="5000" @change="swiperChange">
			<swiper-item v-for="(item, index) in carouselList" :key="index" class="carousel-item"
				@click="bannerNavToUrl(item)">
				<image src="../../static/img/bargainBg.jpg" />
			</swiper-item>
		</swiper>
		<!-- 轮播图 end -->
		<view class="swiper-btm flex">
			<view class="btm-item flex">
				<image src="../../static/icon/index-gou.png" mode=""></image>
				<view class="">自用购物返利</view>
			</view>
			<view class="btm-item flex">
				<image src="../../static/icon/index-gou.png" mode=""></image>
				<view class="">分享好友赚钱</view>
			</view>
			<view class="btm-item flex">
				<image src="../../static/icon/index-gou.png" mode=""></image>
				<view class="">超值正品优惠</view>
			</view>
		</view>
		<!-- 商品列表 -->
		
	</view>
</template>

<script>
	import {
		tabbar1
	} from '@/utils/tabbar.js';
	import {
		loadIndexs
	} from '@/api/index.js';
	import uniCountdowns from '@/components/uni-countdown/uni-countdowns.vue';
	export default {
		components: {
			uniCountdowns
		},
		data() {
			return {
				current: 0,
				tabbar: tabbar1,
				titleNViewBackground: '',
				swiperCurrent: 0,
				swiperLength: 0,
				dataList: '',
				carouselList: [], //轮播图列表
				text: ['恭喜黑白灰用户拼团成功￥353元！', '恭喜黑白灰用户拼团成功￥353元！'],
				stopTime: {
					stopTimeH: 0,
					stopTimeM: 24,
					stopTimeS: 59
				},
				bzb: 30
			};
		},
		onLoad() {
			this.loadData();
		},
		methods: {
			loadData() {
				loadIndexs({})
					.then(({
						data
					}) => {
						let goods = data.info;
						this.dataList = goods.bastList; //精品推荐
						this.carouselList = data.banner;
					})
					.catch(e => {});
			},
			goDetails(e) {
				console.log(e, '123456');
				uni.navigateTo({
					url: '/pages/index/messageInfo'
				});
			},
			nav(url) {
				uni.navigateTo({
					url,
					fail() {
						uni.switchTab({
							url
						});
					}
				});
			},
			//轮播图切换修改背景色
			swiperChange(e) {
				const index = e.detail.current;
				this.swiperCurrent = index;
				this.titleNViewBackground = this.carouselList[index].background;
			},
			// 點擊搜索框
			clickSearch() {
				uni.navigateTo({
					url: '/pages/product/search'
				});
			},

			//详情页
			navToDetailPage(item) {
				let id = item.id;
				uni.navigateTo({
					url: '/pages/product/product?id=' + id
				});
			}
		}
	};
</script>

<style lang="scss">
	page,
	.center {
		min-height: 100%;
		height: auto;
		background: #ededed;
	}
	// 顶部搜索
	.top-search {
		height: 80rpx;
		padding: 0 20rpx;
		background-color: #fff;
		.top-logo {
			width: 50rpx;
			height: 50rpx;
			margin-right: 10rpx;

			image {
				width: 50rpx;
				height: 50rpx;
			}

		}

		.search-box {
			justify-content: center;
			width: 698rpx;
			height: 60rpx;
			background: #EEEEEE;
			// box-shadow: 0px 10rpx 20rpx 0px rgba(4, 114, 69, 0.22);
			border-radius: 30rpx;

			.search {
				width: 34rpx;
				height: 34rpx;
			}

			.search-font {
				margin-left: 14rpx;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #CBCBCB;
			}
		}
	}
	// 顶部轮播图
	.top-swiper {
		width: 750rpx;
		height: 360rpx;
		// margin: 20rpx 0 0;
		image {
			width: 750rpx;
			height: 360rpx;
		}
	}
	.swiper-btm {
		height: 60rpx;
		width: 750rpx;
		background-color: #fff;
		margin-bottom: 20rpx;
		font-size: 21rpx;
		font-weight: 500;
		color: #333333;
		.btm-item {
			flex-grow: 1;
			justify-content: center;
			image {
				width: 25rpx;
				height: 25rpx;
				margin-right: 14rpx;
			}
		}
	}
	.jg {
		height: 20rpx;
		background-color: #fff;
	}
</style>
