<template>
	<view class="center">
		<view class="top">
			<!-- <image class="top-bg" src="../../static/img/top-bg.png" mode=""></image> -->
			<view class="top-main flex">
				<view class="search-box flex" @click="clickSearch()">
					<image class="search" src="../../static/img/search.png" mode=""></image>
					<view class="search-font">输入关键词搜索</view>
				</view>
			</view>
		</view>
		<swiper class="carousel" 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="item.pic" />
			</swiper-item>
		</swiper>
		<view class="tongz flex">
			<view>
				<view class="tongz-bg">
					<image src="../../static/img/tongz-bg.png" mode=""></image>
				</view>
				<view class="tongz-left flex">
					<image class="image-left" src="../../static/img/ling.png" mode=""></image>
					<u-notice-bar style="width: 100%;" mode="vertical" type="none" :volume-icon="false"
						:more-icon="true" :list="text" @click="goDetails" @getMore="nav('/pages/index/message?type=1')">
					</u-notice-bar>
				</view>
			</view>
		</view>
		<view class="navbar flex">
			<view class="navbar-item" @click="nav('/pages/product/classify?type=4')">
				<image class="nitem-image" src="../../static/img/index-inco1.png" mode=""></image>
				<view class="nitem-font">随意嗨购</view>
			</view>

			<view class="navbar-item" @click="nav('/pages/product/classify?type=5')">
				<image class="nitem-image" src="../../static/img/index-inco3.png" mode=""></image>
				<view class="nitem-font">置换</view>
			</view>
			<view class="navbar-item" @click="nav('/pages/product/seckill')">
				<image class="nitem-image" src="../../static/img/index-inco5.png" mode=""></image>
				<view class="nitem-font">秒杀</view>
			</view>
			<view class="navbar-item" @click="nav('/pages/store/store')">
				<image class="nitem-image" src="../../static/img/index-inco7.png" mode=""></image>
				<view class="nitem-font">合作专区</view>
			</view>
			<view class="navbar-item" @click="nav('/pages/category/category')">
				<image class="nitem-image" src="../../static/img/index-inco8.png" mode=""></image>
				<view class="nitem-font">大品牌区</view>
			</view>
			<!-- <view class="navbar-item" @click="nav('/pages/index/message?type=2')">
				<image class="nitem-image" src="../../static/img/index-inco6.png" mode=""></image>
				<view class="nitem-font">拍卖品</view>
			</view> -->
			<view class="navbar-item" @click="nav('/pages/product/classify?type=1')">
				<image class="nitem-image" src="../../static/img/index-inco2.png" mode=""></image>
				<view class="nitem-font">医斯佳专区</view>
			</view>
			<view class="navbar-item" @click="nav('/pages/product/classify?type=3')">
				<image class="nitem-image" src="../../static/img/index-inco4.png" mode=""></image>
				<view class="nitem-font">CBB专区</view>
			</view>
		</view>
		<view class="shingle" v-if="list">
			<view class="shingle-top flex">
				<view class="shingle-title">CBB潮贝抢货通道</view>
				<view class="shingle-btn" @click="nav('/pages/hall/hall')">
					更多CBB代理团队
					<text>></text>
				</view>
			</view>
			<view class="shingle-main" @click="navTo(list)">
				<view class="shingle-bg">
					<image :src="list.image" mode=""></image>
				</view>
				<view class="shinglem-title flex">
					<image class="tbg" src="../../static/img/tbg-left.png" mode=""></image>
					<view class="shinglemt-center">
						<image class="address" src="../../static/img/address.png" mode=""></image>
						<view class="shingle-font">{{ list.name || 'null' }}</view>
					</view>
					<image class="tbg" src="../../static/img/tbg-right.png" mode=""></image>
				</view>
				<view class="shingle-mmain flex">
					<view class="smmain-item">
						<view class="smitem-top">开放中</view>
						<view class="smitem-bottom">状态</view>
					</view>
					<view class="shu"></view>
					<view class="smmain-item">
						<view class="smitem-top clamp">{{ list.nickname }}</view>
						<view class="smitem-bottom">CBB潮倍贝</view>
					</view>
					<view class="shu"></view>
					<view class="smmain-item">
						<view class="people flex">
							<view class="peopleitem" v-for="item in 1">
								<image src="../../static/img/busy.png" mode=""></image>
							</view>
							<view class="peopleitem" v-for="item in 4">
								<image src="../../static/img/leisure.png" mode=""></image>
							</view>
						</view>
						<view class="smitem-bottom">流畅</view>
					</view>
				</view>
				<image class="right-bottom" src="../../static/img/right-bottom.png" mode=""></image>
			</view>
		</view>
		<!-- 秒杀楼层 -->
		<seckill></seckill>
		<view class="ge" v-if="stop.length != 0"></view>
		<view class="serve" v-if="stop.length != 0">
			<view class="seckill-title flex">
				<view class="seckill-left flex">
					<image class="seckill-inco" src="../../static/img/serve.png" mode=""></image>
					<view class="seckill-font">服务专区推荐</view>
				</view>
				<view class="seckill-right" @click="nav('/pages/store/store')">
					<view class="seckill-rfont">更多</view>
					<image class="seckill-back" src="../../static/img/back.png" mode=""></image>
				</view>
			</view>
			<view class="serve-main flex">
				<view class="serve-item" @click="nav('/pages/store/storeInfo?id=' + item.id)"
					v-for="(item, index) in stop" :key="index">
					<image class="serve-price" :src="item.image" mode=""></image>
					<view class="clamp serve-title">{{ item.name }}</view>
					<view class="serve-address flex" v-if="item.jl">
						<image class="saddress-inco" src="../../static/img/address.png" mode=""></image>
						<view class="saddress-font">距离{{ item.jl }}KM</view>
					</view>
				</view>
			</view>
		</view>
		<u-tabbar activeColor="#f42b4e" v-model="current" :list="tabbar"></u-tabbar>
	</view>
</template>

<script>
	import {
		tabbar1
	} from '@/utils/tabbar.js';
	import seckill from '../../components/seckill/seckill.vue';
	import {
		article
	} from '@/api/user.js';
	import {
		loadIndexs,
		store_list
	} from '@/api/index.js';
	import uniCountdowns from '@/components/uni-countdown/uni-countdowns.vue';
	import {
		openMap
	} from '@/utils/rocessor.js';
	import {
		auction_gu
	} from '@/api/hall.js';
	export default {
		components: {
			seckill,
			uniCountdowns
		},
		data() {
			return {
				current: 0,
				tabbar: tabbar1,
				titleNViewBackground: '',
				swiperCurrent: 0,
				swiperLength: 0,
				longitude: '', //经度
				latitude: '', //纬度
				dataList: '',
				carouselList: [], //轮播图列表
				text: [],
				article: [],
				list: {},
				stop: []
			};
		},
		onPullDownRefresh() {
			console.log('111');
			this.loadData();
			this.getaddress();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onShow() {
			this.loadData();
			this.getaddress();
		},
		methods: {
			loadData() {
				article({}, 1).then(({
					data
				}) => {
					data.forEach(e => {
						this.text.push(e.synopsis);
					});
					this.article = data;
				});
				auction_gu({
						pages: 1,
						limit: 1
					})
					.then(({
						data
					}) => {
						this.list = data[0];
					})
					.catch(e => {
						console.log(e);
					});
				loadIndexs({})
					.then(({
						data
					}) => {
						let goods = data.info;
						this.dataList = goods.bastList; //精品推荐
						this.carouselList = data.banner;
					})
					.catch(e => {});
			},
			//根据经纬度计算距离
			getFlatternDistance(lat1, lng1, lat2, lng2) {
				let radLat1 = (lat1 * Math.PI) / 180.0;
				let radLat2 = (lat2 * Math.PI) / 180.0;
				let a = radLat1 - radLat2;
				let b = (lng1 * Math.PI) / 180.0 - (lng2 * Math.PI) / 180.0;
				let s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math
					.pow(Math.sin(b / 2), 2)));
				s = s * 6378.137;
				s = Math.round(s * 10000) / 10000;
				return s;
			},
			getaddress() {
				let obj = this;
				uni.getLocation({
					type: 'gcj02',
					success: res => {
						console.log('dizhi+++++++++++');
						obj.longitude = res.longitude; //经度
						obj.latitude = res.latitude; //纬度
						store_list({
							page: 1,
							limit: 3,
							latitude: res.latitude,
							longitude: res.longitude
						}).then(e => {
							if (e.data.length != 0) {
								e.data.list.forEach(e => {
									e.jl = obj.getFlatternDistance(obj.latitude, obj
										.longitude, e.latitude, e.longitude);
								});
							}
							obj.stop = e.data.list;
							console.log(e);
						});
					},
					fail: err => {
						console.log(err, '123456789');
						openMap().then(e => {
							obj.getaddress();
						});
					}
				});
			},
			goDetails(e) {
				uni.navigateTo({
					url: '/pages/index/messageInfo?id=' + this.article[e].id
				});
			},
			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'
				});
			},
			navTo(item) {
				uni.navigateTo({
					url: '/pages/hall/halllist?id=' + item.id + '&name=' + item.name + '&peoplename=' + item
						.nickname
				});
			},
			//详情页
			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: #ffffff;
	}

	.top {
		position: relative;
		width: 100%;
		height: 360rpx;

		.top-bg {
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			width: 100%;
			height: 100%;
		}

		.top-main {
			position: relative;
			z-index: 2;
			padding: 30rpx;

			.search-box {
				justify-content: center;
				width: 698rpx;
				height: 60rpx;
				background: #f1f1f1;
				
				// 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: #a4a4a4;
				}
			}
		}
	}

	.carousel {
		width: 700rpx;
		height: 276rpx;
		margin: -240rpx auto 0;
		

		image {
			width: 700rpx;
			height: 276rpx;
			background-color: red;
			border-radius: 20rpx;
		}
	}

	.tongz {
		width: 690rpx;
		height: 70rpx;
		margin: 32rpx auto 0;
		padding: 18rpx 30rpx 18rpx 24rpx;
		align-items: center;
		position: relative;

		.tongz-bg {
			position: absolute;
			top: 0;
			right: 0;
			left: 0;
			width: 690rpx;
			height: 70rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.tongz-left {
			width: 640rpx;

			.image-left {
				width: 28rpx;
				height: 34rpx;
			}

			.tongz-font {
				margin-left: 22rpx;
				font-size: 28rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #0f253a;
			}
		}

		.tongz-right {
			position: relative;
			z-index: 11;
			width: 12rpx;
			height: 26rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}
	}

	.navbar {
		justify-content: flex-start;
		flex-wrap: wrap;

		.navbar-item {
			margin-top: 42rpx;
			width: 25%;
			display: flex;
			flex-direction: column;
			align-items: center;

			.nitem-image {
				width: 90rpx;
				height: 90rpx;
			}

			.nitem-font {
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #0c1732;
			}
		}
	}

	.product {
		width: 662rpx;
		height: 180rpx;
		margin: 44rpx auto;

		.product-image {
			width: 662rpx;
			height: 180rpx;
		}
	}

	.shingle {
		width: 750rpx;
		background: #f8f8f8;
		border-radius: 10rpx;
		margin: 60rpx auto 0rpx;
		padding: 44rpx 50rpx 40rpx;

		.shingle-top {
			padding-left: 2rpx;

			.shingle-title {
				font-size: 36rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #dc262b;
			}

			.shingle-btn {
				width: 250rpx;
				height: 50rpx;
				border: 2rpx solid #dc262b;
				border-radius: 10rpx;
				padding: 0 16rpx;
				text-align: left;
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #dc262b;
				line-height: 50rpx;

				text {
					display: inline-block;
					padding-left: 6rpx;
				}
			}
		}

		.shingle-main {
			margin: 20rpx auto;
			width: 650rpx;
			height: 206rpx;
			position: relative;

			.shingle-bg {
				position: absolute;
				top: 0;
				left: 0;
				right: 0;
				width: 650rpx;
				height: 206rpx;

				image {
					width: 650rpx;
					height: 206rpx;
				}
			}

			.shinglem-title {
				position: relative;
				z-index: 2;
				justify-content: center;
				height: 70rpx;

				.tbg {
					height: 70rpx;
					width: 40rpx;
				}

				.shinglemt-center {
					display: flex;
					align-items: center;
					background: rgba(220, 38, 43, 0.66);
				}

				.address {
					width: 28rpx;
					height: 30rpx;
				}

				.shingle-font {
					font-size: 36rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #ffffff;
					line-height: 70rpx;
					margin-left: 14rpx;
				}
			}

			.shingle-mmain {
				position: relative;
				z-index: 2;
				margin-top: 30rpx;

				.smmain-item {
					width: 33%;
					display: flex;
					flex-direction: column;
					align-items: center;

					.smitem-top {
						text-align: center;
						width: 90%;
						font-size: 30rpx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #ffffff;
					}

					.smitem-bottom {
						margin-top: 10rpx;
						font-size: 30rpx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #ffffff;
					}

					.people {
						justify-content: center;

						.peopleitem {
							width: 24rpx;
							height: 34rpx;

							image {
								width: 100%;
								height: 100%;
							}
						}
					}
				}

				.shu {
					width: 2rpx;
					height: 70rpx;
					background: #ffffff;
				}
			}

			.right-bottom {
				position: absolute;
				z-index: 2;
				right: 0;
				bottom: 0;
				width: 94rpx;
				height: 92rpx;
			}
		}
	}

	.seckill-left {
		justify-content: flex-start;

		.seckill-inco {
			width: 36rpx;
			height: 36rpx;
			flex-shrink: 0;
		}

		.seckill-font {
			margin-left: 8rpx;
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #333333;
		}

		.djs {
			margin-left: 12rpx;
			font-size: 20rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #dc262b;
		}
	}

	.seckill-right {
		display: flex;
		justify-content: flex-start;
		align-items: center;

		.seckill-rfont {
			font-size: 24rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #999999;
			margin-right: 8rpx;
		}

		.seckill-back {
			width: 10rpx;
			height: 20rpx;
		}
	}

	.ge {
		height: 20rpx;
		width: 750rpx;
		background: #f8f8f8;
	}

	.serve {
		padding: 32rpx 30rpx;
		background: #ffffff;

		.serve-main {
			margin-top: 24rpx;
			flex-wrap: wrap;
			justify-content: flex-start;

			.serve-item:first-child {
				margin-left: 0rpx;
			}

			.serve-item {
				width: 220rpx;
				background: #f6f6f6;
				border-radius: 10rpx;
				margin-left: 14rpx;
				padding-bottom: 22rpx;

				.serve-price {
					width: 220rpx;
					height: 220rpx;
					border-radius: 10rpx 10rpx 0px 0px;
					background: #03a9f4;
				}

				.serve-title {
					margin-top: 16rpx;
					padding: 0 14rpx;
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #0a122b;
				}

				.serve-address {
					justify-content: flex-start;
					margin-top: 10rpx;
					padding: 0 14rpx;

					.saddress-inco {
						width: 18rpx;
						height: 24rpx;
					}

					.saddress-font {
						margin-left: 4rpx;
						font-size: 20rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #666666;
					}
				}
			}
		}
	}
</style>
