<template>
	<view class="center">
		<view class="top">
			<view class="vheigh"></view>
			<view class="body-title">
				<view class="goback-box" @click="toBack">
					<image class="goback" src="../../static/icon/fanhui.png" mode=""></image>
				</view>
				<view class="header">进货系统</view>
			</view>
			<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/index/message?type=7')">
				<image class="nitem-image" src="http://shop.yiqushangshi.com/uploads/attach/2022/07/20220711/0b6c4e066508fcd18abf124c933df88f.png" mode=""></image>
				<view class="nitem-font">最新资讯</view>
			</view>
			<view class="navbar-item" v-for="(item, index) in navbarList[0].children"
				@click="nav('/pages/product/list?tid=' + item.id)">
				<image class="nitem-image" :src="item.pic" mode=""></image>
				<view class="nitem-font">{{ item.cate_name }}</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>
		<view class="shop" @click="nav('/pages/store/store')">
			<view class="shop-title">
				<image class="shop-title-icon" src="../../static/icon/index1.png" mode=""></image>
				<view class="shop-title-font">本地生活</view>
			</view>
			<!-- #ifndef APP-PLUS -->
			<view class="shop-main">
				<image src="http://yiqugo.oss-cn-hangzhou.aliyuncs.com/59b8e202304061437149756.png" mode=""></image>
			</view>
			<!-- #endif -->
			<!-- #ifdef APP-PLUS -->
			<view class="shop-main">
				<image src="../../static/img/index-shop.png" mode=""></image>
			</view>
			<!-- #endif -->
		</view>
		<view class="product" v-for="(item, index) in navbarList[0].children">
			<view class="seckill-title flex">
				<view class="seckill-left flex">
					<view class="seckill-font">{{ item.cate_name }}</view>
				</view>
				<view class="seckill-right" @click="nav('/pages/product/list?tid=' + item.id)">
					<view class="seckill-rfont">更多</view>
					<image class="seckill-back" src="../../static/img/back.png" mode=""></image>
				</view>
			</view>
			<view class="priduct-main">
				<view class="priduct-item" v-for="itm in item.product" :key="itm.id" @click="navToDetailPage(itm)">
					<view class="priduct-main-image">
						<image :src="itm.image" mode="scaleToFill"></image>
					</view>
					<view class="priduct-main-name clamp margin-c-20">{{ itm.store_name }}</view>
					<view class="priduct-main-price">
						<view class="price" v-if="item.integral != 0">￥{{ itm.price * 1 }} + {{ itm.integral }}趣豆</view>
						<view class="price" v-else>￥{{ itm.price }}</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 {
		getCategoryList,
		getProducts
	} from '@/api/product.js';
	import {
		loadIndexs,
		store_list
	} from '@/api/index.js';
	import uniCountdowns from '@/components/uni-countdown/uni-countdowns.vue';
	// #ifdef H5
	// import { openMap } from '@/utils/rocessor.js';
	// #endif
	import {
		auction_gu
	} from '@/api/hall.js';
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		components: {
			seckill,
			uniCountdowns
		},
		data() {
			return {
				current: 0,
				tabbar: tabbar1,
				titleNViewBackground: '',
				swiperCurrent: 0,
				swiperLength: 0,
				longitude: '', //经度
				latitude: '', //纬度
				dataList: '',
				carouselList: [], //轮播图列表
				text: [],
				article: [],
				list: {},
				stop: [],
				navbarList: [{
					child: []
				}]
			};
		},
		onPullDownRefresh() {
			console.log('111');
			this.loadData();
			this.getaddress();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onShow() {
			this.loadData();
			this.getnavbar();
			this.getaddress();
		},
		methods: {
			...mapMutations(['setLat', 'setLon', 'setChoose']),
			getnavbar() {
				let obj = this;
				getCategoryList({})
					.then(({
						data
					}) => {
						data[0].children.forEach(e => {
							getProducts({
								page: 1,
								limit: 2,
								sid: e.id
							}).then(info => {
								obj.$set(e, 'product', info.data);
							});
						});
						this.navbarList = data;
						console.log(data, '123456');
					})
					.catch(err => {
						console.log(err);
					});
			},
			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 => {});
			},
			out_of_china(lng, lat) {
				return lng < 72.004 || lng > 137.8347 || (lat < 0.8293 || lat > 55.8271 || false);
			},
			transformlat(lng, lat) {
				const x_PI = (3.14159265358979324 * 3000.0) / 180.0;
				const PI = 3.1415926535897932384626;
				const a = 6378245.0;
				const ee = 0.00669342162296594323;
				let ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(
					lng));
				ret += ((20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0) / 3.0;
				ret += ((20.0 * Math.sin(lat * PI) + 40.0 * Math.sin((lat / 3.0) * PI)) * 2.0) / 3.0;
				ret += ((160.0 * Math.sin((lat / 12.0) * PI) + 320 * Math.sin((lat * PI) / 30.0)) * 2.0) / 3.0;
				return ret;
			},
			transformlng(lng, lat) {
				const x_PI = (3.14159265358979324 * 3000.0) / 180.0;
				const PI = 3.1415926535897932384626;
				const a = 6378245.0;
				const ee = 0.00669342162296594323;
				let ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
				ret += ((20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0) / 3.0;
				ret += ((20.0 * Math.sin(lng * PI) + 40.0 * Math.sin((lng / 3.0) * PI)) * 2.0) / 3.0;
				ret += ((150.0 * Math.sin((lng / 12.0) * PI) + 300.0 * Math.sin((lng / 30.0) * PI)) * 2.0) / 3.0;
				return ret;
			},
			wgs84Togcj02(lng, lat) {
				if (this.out_of_china(lng, lat)) {
					return [lng, lat];
				}
				//定义一些常量
				//GCJ02 转换为 WGS84
				var that = this;
				const x_PI = (3.14159265358979324 * 3000.0) / 180.0;
				const PI = 3.1415926535897932384626;
				const a = 6378245.0;
				const ee = 0.00669342162296594323;
				let dlat = that.transformlat(lng - 105.0, lat - 35.0);
				let dlng = that.transformlng(lng - 105.0, lat - 35.0);
				let radlat = (lat / 180.0) * PI;
				let magic = Math.sin(radlat);
				magic = 1 - ee * magic * magic;
				let sqrtmagic = Math.sqrt(magic);
				dlat = (dlat * 180.0) / (((a * (1 - ee)) / (magic * sqrtmagic)) * PI);
				dlng = (dlng * 180.0) / ((a / sqrtmagic) * Math.cos(radlat) * PI);
				var mglat = lat + dlat;
				var mglng = lng + dlng;
				return [mglng, mglat];
			},
			toBack() {
				uni.navigateTo({
					url: '/pages/navigation/index'
				})
			},
			getaddress() {
				console.log('dizhi+++++++++++');
				let obj = this;
				uni.getLocation({
					type: 'wgs84',
					success: res => {
						let wz = obj.wgs84Togcj02(res.longitude, res.latitude);
						obj.setLat(wz[1]);
						obj.setLon(wz[0]);
						console.log(wz, '经纬度');
					},
					fail: err => {
						console.log(err, '经纬度');
						openMap().then(e => {
							this.getaddress();
						});
					}
				});
			},
			goDetails(e) {
				uni.navigateTo({
					url: '/pages/index/messageInfo?id=' + this.article[e].id
				});
			},
			nav(url) {
				console.log(url, '123456');
				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;
	}

	.body-title {
		height: 80rpx;
		text-align: center;
		font-size: 35rpx;
		position: relative;

		.header {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			font-size: 36rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #fffeff;
			height: 80rpx;
			font-size: 36rpx;
			font-weight: 700;
			z-index: 9;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.goback-box {
			position: absolute;
			left: 18rpx;
			top: 0;
			height: 80rpx;
			display: flex;
			align-items: center;
		}

		.goback {
			z-index: 100;
			width: 34rpx;
			height: 34rpx;
		}
	}

	.vheigh {
		height: var(--status-bar-height);
		background-color: $base-color;
	}

	.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: rgba(255, 240, 245, 0.4);
				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: #ffffff;
				}
			}
		}
	}

	.carousel {
		width: 700rpx;
		height: 276rpx;
		/* #ifndef APP-PLUS */
		margin: -160rpx auto 0;
		/* #endif */
		/* #ifdef APP-PLUS */
		margin: -100rpx auto 0;
		/* #endif */
		border-radius: 40rpx;

		image {
			border-radius: 40rpx;
			width: 700rpx;
			height: 276rpx;
		}
	}

	.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 {
				margin-top: 10rpx;
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #0c1732;
			}
		}
	}

	.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;
			}
		}
	}

	.shop {
		background: #ffffff;
		padding: 32rpx 30rpx 20rpx;

		.shop-title {
			display: flex;
			align-items: center;

			.shop-title-icon {
				width: 36rpx;
				height: 36rpx;
			}

			.shop-title-font {
				margin-left: 20rpx;
				font-size: 34rpx;
				color: #303133;
				font-weight: bold;
			}
		}

		.shop-main {
			margin: 20rpx auto 0;
			border-radius: 40rpx;
			width: 100%;
			height: 286rpx;

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

	.seckill-title {
		padding: 32rpx 30rpx 0;
	}

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

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

		.seckill-font {
			margin-left: 8rpx;
			font-size: 40rpx;
			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;
		}
	}

	.product {
		background: #f0f0f0;
	}

	.priduct-main {
		margin-top: 38rpx;
		width: 100%;
		display: flex;
		flex-wrap: wrap;
		padding: 0 32rpx;

		.priduct-item {
			width: 48%;
			background-color: #ffffff;
			border-radius: 12rpx;
			margin-bottom: 24rpx;

			&:nth-child(2n + 1) {
				margin-right: 24rpx;
			}

			.priduct-main-image {
				width: 100%;
				height: 330rpx;
				// background: red;
				border-radius: 3px;
				overflow: hidden;

				image {
					width: 100%;
					height: 100%;
					opacity: 1;
					border-radius: 12rpx 12rpx 0 0;
				}
			}

			.priduct-main-name {
				font-size: $font-base;
				color: $font-color-dark;
				font-weight: bold;
				line-height: 80rpx;
			}

			.priduct-main-price {
				display: flex;
				justify-content: space-between;
				padding: 0 16rpx 12rpx;

				.price {
					font-size: 36rpx;
					font-weight: bold;
					color: #fd3b39;
				}

				.cart-icon {
					image {
						width: 44rpx;
						height: 44rpx;
					}
				}
			}
		}
	}
</style>