<template>
	<view class="container">
		<!-- 头部轮播 -->
		<view class="carousel-section">
			<!-- 背景色区域 -->
			<view class="bg"><image src="../../static/img/index.png" mode=""></image></view>
			<!-- 标题栏和状态栏占位符 -->
			<!-- <view class="titleNview-placing"></view> -->
			<!-- 搜素栏 -->
			<view class="search flex">
				<image src="../../static/icon/address.png" class="address"></image>
				<view class="shop-name clamp">满园春台州店11111111</view>
				<view class="input-box flex" @click="clickSearch">
					<view class=" input-content flex">
						<view class="iconfont iconsearch"></view>
						<view class="input"><input type="text" disabled value="输入关键字搜索" /></view>
					</view>
				</view>
			</view>
			<swiper class="carousel" autoplay="true" duration="400" interval="5000" @change="swiperChange" :indicator-dots="true" indicator-active-color="#FFFFFF">
				<!-- <swiper class="carousel" autoplay="true" duration="400" interval="5000"> -->
				<swiper-item v-for="(item, index) in carouselList" :key="index" class="carousel-item">
					<image :src="item.pic" mode="aspectFill" @click="bannerNavToUrl(item)"></image>
				</swiper-item>
			</swiper>
		</view>
		<!-- 分类 -->
		<view class="cate-section">
			<navigator url="/pages/shoping/list">
				<view class="cate-item">
					<image class="Uimg" src="/static/icon/in2.png"></image>
					<text>全部分类</text>
				</view>
			</navigator>
			<navigator url="/pages/prefecture/integral">
				<view class="cate-item">
					<image src="/static/icon/in1.png"></image>
					<text>附近门店</text>
				</view>
			</navigator>
			<navigator url="/pages/prefecture/consumer">
				<view class="cate-item">
					<image src="/static/icon/in3.png"></image>
					<text>邀请有礼</text>
				</view>
			</navigator>
			<navigator url="/pages/received/index?state=0">
				<view class="cate-item">
					<image src="/static/icon/in4.png"></image>
					<text>收付款</text>
				</view>
			</navigator>
		</view>

		<!-- 积分兑换 -->
		<view class="main-box">
			<view class="main-top">
				<image src="../../static/icon/indexI.png" mode="" class="main-icon"></image>
				<view class="main-title">积分兑换</view>
				<view class="main-synopsis">超值体验</view>
			</view>
			<view class="main-content">
				<view class="content-top flex">
					<view class="content-font">
						<view class="content-title">积分兑换热门好物</view>
						<view class="content-synopsis">买到就是赚到</view>
					</view>
					<image src="../../static/icon/fanhui.png" class="go" mode=""></image>
				</view>
			</view>
			<view class="commodity">
				
			</view>
		</view>
	</view>
</template>

<script>
import seckill from './seckill';
import { loadIndexs } from '@/api/index.js';
import { interceptor } from '@/utils/loginUtils';
import { userinfo } from '@/api/user.js';
import { mapState } from 'vuex';
export default {
	components: {
		seckill
	},
	filters: {
		moneyNum: function(value) {
			return +value;
		}
	},
	data() {
		return {
			titleNViewBackground: '',
			swiperCurrent: 0,
			swiperLength: 0,
			carouselList: [], //轮播列表
			goodsList: [], //最新商品列表
			bastList: [], //精品推荐列表
			bastBanner: [], //促销商品列表
			menusList: [], //头部菜单
			userServant: [
				{
					image: ''
				}
			] //用户推广服务
		};
	},
	computed: {
		...mapState(['loginInterceptor']),
		...mapState('user', ['hasLogin', 'userInfo'])
	},
	onLoad(option) {
		let agree = uni.getStorageSync('agree') || false;
		// 判断是否已经同意协议
		if (!agree) {
			uni.redirectTo({ url: '/pages/contract/start' });
		}
		if (option.spread) {
			// 存储邀请人
			uni.setStorage({
				key: 'spread',
				data: option.spread
			});
		}
	},
	onShow() {
		// 判断是否强制登录
		if (this.loginInterceptor && !this.hasLogin) {
			// 登录拦截
			userinfo()
				.then(e => {})
				.catch(e => {
					console.log(e);
				});
		}
		this.loadData();
	},
	// #ifndef MP
	// 监听导航栏输入框点击事件
	onNavigationBarSearchInputClicked(e) {
		//跳转到搜索页面
		this.clickSearch();
	},
	//点击导航栏 buttons 时触发
	onNavigationBarButtonTap(e) {
		const index = e.index;
		if (index === 0) {
			this.$api.msg('点击了扫描');
		} else if (index === 1) {
			// #ifdef APP-PLUS
			const pages = getCurrentPages();
			const page = pages[pages.length - 1];
			const currentWebview = page.$getAppWebview();
			currentWebview.hideTitleNViewButtonRedDot({
				index
			});
			// #endif
			uni.navigateTo({
				url: '/pages/notice/notice'
			});
		}
	},
	// #endif
	methods: {
		// 點擊搜索框
		clickSearch() {
			uni.navigateTo({
				url: '/pages/product/search'
			});
		},
		// 监听图片加载完成
		onImageError(key, index) {
			this[key][index].image = '/static/error/errorImage.jpg';
		},
		// 请求载入数据
		async loadData() {
			loadIndexs({}).then(({ data }) => {
				let goods = data.info;
				this.carouselList = data.banner;
				this.swiperLength = this.carouselList.length;
				this.menusList = data.menus;
				this.goodsList = goods.firstList; //最新商品
				this.bastList = goods.bastList; //精品推荐
				this.bastBanner = goods.bastBanner; //促销单品
				this.userServant = goods.platoonList; //服务商品
			});
		},
		//轮播图切换修改背景色
		swiperChange(e) {
			const index = e.detail.current;
			this.swiperCurrent = index;
			// this.titleNViewBackground = this.carouselList[index].background;
		},
		//详情页
		navToDetailPage(item) {
			uni.navigateTo({
				url: '/pages/product/product?id=' + item.id
			});
		},
		// 轮播图跳转
		bannerNavToUrl(item) {
			// #ifdef H5
			if (item.wap_url.indexOf('http') > 0) {
				window.location.href = item.wap_url;
			}
			// #endif
			//测试数据没有写id，用title代替
			uni.navigateTo({
				url: item.wap_url
			});
		}
	}
};
</script>

<style lang="scss">
page {
	background: #f5f5f5;
}
.m-t {
	margin-top: 16rpx;
}
/* 头部 轮播图 */
.carousel-section {
	position: relative;
	padding-top: 10px;
	overflow: hidden;
	.bg {
		position: absolute;
		top: 0;
		left: 0;
		width: 750rpx;
		height: 346rpx;
		image {
			width: 100%;
			height: 100%;
		}
	}
	.titleNview-placing {
		height: var(--status-bar-height);
		padding-top: 44px;
		box-sizing: content-box;
	}
	.search {
		justify-content: flex-start;
		padding: 10rpx 24rpx 20rpx;
		align-items: center;
		.address {
			width: 32rpx;
			height: 38rpx;
		}
		.shop-name {
			position: relative;
			z-index: 10;
			width: 206rpx;
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #ffffff;
			padding-left: 10rpx;
		}
		.input-box {
			position: relative;
			z-index: 999;
			width: 427rpx;
			height: 60rpx;
			background: rgba(39, 170, 116, 0.4);
			box-shadow: 0px 9rpx 21rpx 0px rgba(4, 114, 69, 0.22);
			border-radius: 30px;
			margin-left: 25rpx;
			.input-content {
				position: relative;
				z-index: 11;
				border-radius: 99rpx;
				flex-grow: 1;
				padding: 5rpx 30rpx;
				background: #a2e0c7;
				.iconsearch {
					font-size: 50rpx;
					color: #ffffff;
				}
				.input {
					margin-left: 19rpx;
					flex-grow: 1;
					color: #ffffff;
					input {
						font-size: 26rpx;

						color: #ffffff;
					}
				}
			}
			.input-button {
				padding-left: 20rpx;
				font-size: $font-base;
				height: 100%;
			}
		}
	}
}
.carousel {
	width: 100%;
	height: 300rpx;
	background-color: #fff;
	.carousel-item {
		width: 100%;
		height: 100%;
		padding: 0 28rpx;
		overflow: hidden;
	}
	image {
		width: 100%;
		height: 100%;
		border-radius: $border-radius-sm;
	}
}
.swiper-dots {
	display: flex;
	position: absolute;
	left: 60rpx;
	bottom: 15rpx;
	width: 72rpx;
	height: 36rpx;
	background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAABkCAYAAADDhn8LAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTMyIDc5LjE1OTI4NCwgMjAxNi8wNC8xOS0xMzoxMzo0MCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cG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OCAE4sYMyJ5cwCHs4rCwI4sYBxJ5YzC84rCwKcXxArAuthQYDzC2JF0H49LAhwYUGsCFqvx5EF2T07dMaJBetx4cRyaqFtHJ8EIhK0i8OJBQxcECuCVutxJhCRoE0cZwMRyRcFefa/ffZBVPogePihhyCnbBhcfMFFEFM+DD4m+ghSlgmDkwlOgpAl4+BkkJMgZdk4+EgaSCcpVX7bmY9kgXQQU+1TgE0c+QJZUUz1b2T4SBbIKmJW+3iMj2SBVBWz+leVfCQLpIqYbp8b85EskIxyfIOfK5Sf+wiCRJEsllQ+oqEkQfBxmD8BBgA5hVjXyrBNUQAAAABJRU5ErkJggg==);
	background-size: 100% 100%;
	.num {
		width: 36rpx;
		height: 36rpx;
		border-radius: 50px;
		font-size: 24rpx;
		color: #fff;
		text-align: center;
		line-height: 36rpx;
	}

	.sign {
		position: absolute;
		top: 0;
		left: 50%;
		line-height: 36rpx;
		font-size: 12rpx;
		color: #fff;
		transform: translateX(-50%);
	}
}
/* 分类 */
.cate-section {
	display: flex;
	justify-content: space-around;
	align-items: center;
	flex-wrap: wrap;
	padding: 30rpx 22rpx;
	background: #fff;
	.cate-item {
		display: flex;
		flex-direction: column;
		align-items: center;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
		.none-font-color {
			color: $page-color-base;
		}
		.Uimg {
			border-radius: 999px;
		}
	}
	/* 原图标颜色太深,不想改图了,所以加了透明度 */
	image {
		width: 88rpx;
		height: 88rpx;
		margin-bottom: 14rpx;
		border-radius: 50%;
		opacity: 0.7;
	}
}
.ad-1 {
	width: 100%;
	height: 210upx;
	padding: 10upx 0;
	background: #fff;
	image {
		width: 100%;
		height: 100%;
	}
}
/*公用边框样式*/
%icon {
	margin-right: 10rpx;
	display: inline-block;
	padding: 2rpx 10rpx;
	border: 1rpx solid $color-yellow;
	color: $color-yellow;
	line-height: 1;
	font-size: $font-base;
	border-radius: 10rpx;
}
// 积分兑换,消费券
.main-box {
	background-color: #ffffff;
	margin-top: 20rpx;
	padding: 22rpx 30rpx;
	.main-top {
		display: flex;
		justify-content: flex-start;
		align-items: center;
		.main-icon {
			width: 36rpx;
			height: 36rpx;
		}
		.main-title {
			margin-left: 8rpx;
			font-size: 32rpx;
			font-family: Source Han Sans CN;
			font-weight: 500;
			color: #333333;
		}
		.main-synopsis {
			margin-left: 16rpx;
			font-size: 20rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #95a0b1;
		}
	}
	.main-content {
		width: 690rpx;
		background: #f4f4f4;
		border-radius: 12rpx;
		margin: 20rpx auto 0;
		.content-top {
			width: 690rpx;
			background: linear-gradient(43deg, #73deb2, #52c696);
			border-radius: 12rpx 12rpx 0px 0px;
			padding: 24rpx 22rpx 68rpx 27rpx;
			.content-font {
				.content-title {
					font-size: 32rpx;
					font-family: Source Han Sans CN;
					font-weight: 500;
					color: #ffffff;
				}
				.content-synopsis {
					margin-top: 10rpx;
					font-size: 24rpx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #ffffff;
				}
			}
			.go {
				width: 30rpx;
				height: 35rpx;
				transform: rotate(180deg);
				-ms-transform: rotate(180deg); /* Internet Explorer */
				-moz-transform: rotate(180deg); /* Firefox */
				-webkit-transform: rotate(180deg); /* Safari 和 Chrome */
				-o-transform: rotate(180deg); /* Opera */
			}
		}
	}
}
</style>
