<template>
	<view>
		<view class="notice">
			<text class='iconfont icon-gonggao'></text>
			<swiper :indicator-dots="indicatorDots" autoplay="true" interval="2500" duration="500" vertical="true" circular="true">
				<block v-for="(item,index) in notice" :key='index'>
					<swiper-item>
						<navigator class='news' hover-class='none' :url="'/pages/news/index?id='+item.id">{{item.title}}</navigator>
					</swiper-item>
				</block>
			</swiper>
		</view>
		
		<view class="content">
			<view class="banner">
				<swiper indicator-dots="true" autoplay="true" circular="true" interval="2500" indicator-color="rgba(255,255,255,0.6)" indicator-active-color="#fff">
					<block v-for="(item,index) in banner" :key="index">
						<swiper-item>
							<navigator :url='item.url' class='slide-navigator acea-row row-between-wrapper' hover-class='none'>
								<image :src="item.img" class="slide-image"></image>
							</navigator>
						</swiper-item>
					</block>
				</swiper>
			</view>
			
			<view class="icon">
				<view><text class='iconfont icon-jiangchengben'></text>降成本</view>
				<view><text class='iconfont icon-qukucun'></text>去库存</view>
				<view><text class='iconfont icon-genggaoxiao'></text>更高效</view>
				<view><text class='iconfont icon-xuanze1'></text>多选择</view>
			</view>
			
			<view class="nav">
				<view><image src="../../static/images/nav1.png"></image><view>开启分站</view></view>
				<view><image src="../../static/images/nav2.png"></image><view>邀请好友</view></view>
				<view><image src="../../static/images/nav3.png"></image><view>品质保证</view></view>
				<view><image src="../../static/images/nav4.png"></image><view>降低成本</view></view>
			</view>
			
			<view class="product">
				<view class="title">
					<text>排行榜</text>
					<navigator class="more" url="/pages/product/index" open-type='switchTab' hover-class='none'>更多 <text class="iconfont icon-jiantou"></text></navigator>
				</view>
				<view class="list">
					<scroll-view scroll-x="true" style="white-space: nowrap; display: flex" show-scrollbar="false">
						<navigator class="item" v-for="(item,index) in sort_product" :key="index" :url="'/pages/product/detail?id='+item.id" hover-class='none'>
							<image :src="item.img" mode=""></image>
							<view class="name">{{item.title}}</view>
							<view class="price">￥{{item.price}}</view>
						</navigator>
					</scroll-view>
				</view>
			</view>
			
			<view class="product">
				<view class="title">
					<text>新品上新</text>
					<navigator class="more" url="/pages/product/index" open-type='switchTab' hover-class='none'>更多 <text class="iconfont icon-jiantou"></text></navigator>
				</view>
				<view class="list">
					<scroll-view scroll-x="true" style="white-space: nowrap; display: flex" show-scrollbar="false">
						<navigator class="item" v-for="(item,index) in new_product" :key="index" :url="'/pages/product/detail?id='+item.id" hover-class='none'>
							<image :src="item.img" mode=""></image>
							<view class="name">{{item.title}}</view>
							<view class="price">￥{{item.price}}</view>
						</navigator>
					</scroll-view>
				</view>
			</view>
		</view>
		
		<view class="hotSale"><text>热销单品</text>品质保证 一件代发</view>
		<view class="productList">
			<navigator class="item" v-for="(item,index) in hot_product" :key="index" :url="'/pages/product/detail?id='+item.id" hover-class='none'>
				<image :src="item.img" class="image"></image>
				<view class="info">
					<view class="title">{{item.title}}</view>
					<view class="text"><text class="price">￥{{item.price}}</text><text>{{item.wget}}kg/件</text></view>
					<view class="express">快递：
						<image src="../../static/images/express1.png" class="icon"></image>
						<image src="../../static/images/express2.png" class="icon"></image>
						<image src="../../static/images/express3.png" class="icon"></image>
					</view>
				</view>
			</navigator>
		</view>
	</view>
</template>

<script>
	import {
		getNotice,
		getIndexData
	} from '@/api/api.js';
	export default {	
		data() {
			return{
				spid: '',
				indicatorDots: false,
				notice: [],
				banner: [],
				sort_product: [],
				new_product: [],
				hot_product: []
			}
		},
		onLoad(options) {
			if (options.spid) {
				this.spid = options.spid;
			}
			this.getNotice();
			this.getIndexConfig();
		},	
		methods: {
			// 公告
			getNotice: function() {
				getNotice().then(res => {
					this.notice = res.data;
				})
			},
			// 首页数据
			getIndexConfig: function() {
				getIndexData().then(res => {
					this.banner = res.data.banner;
					this.sort_product = res.data.sort_product;
					this.new_product = res.data.new_product;
					this.hot_product = res.data.hot_product;
				})
			}
		}
	}
</script>

<style lang="scss">
	.notice{
		background: #fff;
		height: 90rpx;
		display: flex;
		padding: 20rpx 0;
		text{
			line-height: 50rpx;
			border-right: 2rpx solid #ddd;
			padding: 0 20rpx;
		}
		swiper{			
			width: 650rpx;
			height: 50rpx;
			line-height: 50rpx;
			overflow: hidden;
			margin-left: 10rpx;
			.news{
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;				
			}
		}
	}
	.content{
		padding: 0 20rpx;
	}
	.banner{
		margin-top: 20rpx;
		.slide-image{
			width:710rpx;
			height:300rpx;
			border-radius: 14rpx;
		}
	}
	.icon{
		color:#ff5c00;
		display: flex;
		justify-content:space-between;
		margin-top: 20rpx;
		text{
			margin-right: 10rpx;
		}
	}
	.nav{
		display: flex;
		justify-content:space-around;
		padding-top:30rpx;
		color:#333;
		image{
			width:110rpx;
			height:110rpx;
		}
	}	
	.product {
		padding: 23rpx 20rpx;
		margin-top:20rpx;
		border-radius: 15rpx;
		background-color: #fff;
		overflow: hidden;
		box-shadow: 0px 0px 16px 3px rgba(0, 0, 0, 0.04);	
		.title {
			display: flex;
			align-items: center;
			justify-content: space-between;	
			text {
				font-size: 32rpx;
				font-weight: bold;
			}	
			.more {
				font-size: 26rpx;
				color: #999;	
				.iconfont {
					margin-left: 6rpx;
					font-size: 25rpx;
				}
			}
		}
		.list{
			width: 100%;
			margin-top: 27rpx;
			.item{
				display: inline-block;
				width: 150rpx;
				margin-right: 20rpx;
				font-size: 24rpx;
				image{
					width:150rpx;
					height:150rpx;
				}
				.name{
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
				.price{
					text-align: center;
					color:#ff5c00;
					margin-top: 8rpx;
				}
			}
		}
	}
	.hotSale{
		margin: 20rpx 0;
		padding: 30rpx 20rpx;
		color:#666;
		background: #fff;
		text{
			color:#000;
			font-size: 32rpx;
			font-weight: bold;
			border-right: 2rpx solid #ddd;
			padding-right: 15rpx;
			margin-right: 15rpx;
		}
	}
	.productList {
		display: flex;
		justify-content:space-evenly;
		flex-wrap:wrap;
		.item{
			background: #fff;
			width:350rpx;
			margin-bottom: 20rpx;
			border-radius: 16rpx;
			.image{
				width:350rpx;
				height:350rpx;
				border-radius: 16rpx 16rpx 0 0;
			}
			.info{
				padding: 15rpx;
				.title{
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
				.text{
					display: flex;
					align-items: center;
					justify-content:space-between;
					color:#666;
					font-size: 24rpx;
					margin: 10rpx 0;
					.price{
						color:#ff5c00;
						font-size: 32rpx;
					}
				}
				.express{
					display: flex;
					align-items: center;
					.icon{
						width:40rpx;
						height:40rpx;
						margin-right: 10rpx;
						margin-top: -2rpx;
					}
				}
			}			
		}
	}
</style>