<template>
	<view>
		<!-- <headerSerch :dataConfig="headItem"></headerSerch> -->
		<!-- <view class="nav-bar_2">
			<text class="text_3">中意购</text>
		</view> -->

		<view class="top custom_box" style="background: linear-gradient(180deg, rgb(254,245,246), rgb(245,245,245)); color: black;" >
			<!-- #ifdef MP || APP-PLUS -->
			<view class="sys-head">
				<view class="sys-bar" :style="{ height: sysHeight }"></view>
				<!-- #ifdef MP -->
				<view class="sys-title">中意购</view>
				<!-- #endif -->
			</view>
			<!-- #endif -->
		</view>

		<view class="index_body" :style="{ top: sysHeightTop}">
			<view class="block_2  flex-row justify-between" @click="changeAddress()">
				<view class="image-text_9 flex-row justify-between">
					<image class="icon_1" referrerpolicy="no-referrer" src="../../../static/images/addressIcon.png" />
					<text class="text-group_1 ">{{ markers[0].label.content }}</text>
				</view>
				<view class="image-text_10 flex-row justify-between">
					<text class="text-group_2">切换地点</text>
					<image class="icon_2" referrerpolicy="no-referrer" src="../../../static/images/quehuan.png" />
				</view>
			</view>

			<!-- 轮播 -->
			<view class="swiper-group">
				<u-swiper height="210" :list="swiperList" @change="e => current = e.current" :autoplay="false" keyName="imageUrl"  @click="clickImageUrl">
					<view slot="indicator" class="indicator">
						<view class="indicator__dot" v-for="(item, index) in swiperList" :key="index"
							:class="[index === current && 'indicator__dot--active']">
						</view>
					</view>
				</u-swiper>
			</view>

			<view class="header-group">
				<view class="tabs index_tabs">
					<u-tabs class="defalt-utabs" :is-scroll="false" :list="navigationList" @click="clickNav" lineColor="#B22338" :current="tabIndex"
						:inactiveStyle="{ color: '#999999' }" :activeStyle="{ color: '#B22338', fontWeight: 'bold' }"
						keyName="title"></u-tabs>
				</view>
			</view>

			<view :style="{ height: swiperHeight }">
				<swiper  :style="{ height: swiperHeight }" :current="tabIndex" @change="swiperChange">
					<swiper-item v-for="(tab, i) in navigationList" :key="i">
						<mescroll-item ref="MescrollItem" :i="i" :index="tabIndex" :currentId="currentId" :tabs="navigationList" :height="swiperHeight" :positionInfo="positionInfo">
						</mescroll-item>
					</swiper-item>
				</swiper>
			</view>

		</view>
		<u-popup :round="15" :show="showTips" class="TipsPop" mode="center" @close="showTips = false" @open="() => { }">
			<view class="tips">
			</view>
			<view class="txt">
				<view class="tips1">
					温馨提示
				</view>

				<view class="tips2">
					您所在的城市没有开放团购目前仅支持的城市如下：
				</view>

				<view class="tips3">
					上海市
				</view>

				<view class="tips4">
					您可以通过右上角"
					<text class="red">切换地点</text>
					"定位到支持
				</view>
				<button class="tips5" @click="showTips = false">
					知道了
				</button>
			</view>
		</u-popup>


	</view>
</template>

<script>
let sysHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
let sysHeightTop = (uni.getSystemInfoSync().statusBarHeight + 43) + 'px';
import MescrollItem from "./module/mescrollUni-item.vue";
import headerSerch from './components/headerSerch';
import latestGroupBuying from './components/latestGroupBuying';
import { getAddress } from '../../../api/wxMap'
import {
	toLogin
} from '@/libs/login.js';
import {
	mapGetters
} from "vuex";
import { getAdsList, getNoticeList, getCategoryOne, getGoodsPage, getIndexData, getGoodsInfo } from '../../../api/home.js'
import { latestGroupon, historyGroupon, detailGroupon, goodsDetail } from '../../../api/groupon.js'

import UButton from "../../../uni_modules/uview-ui/components/u-button/u-button";
export default {
	components: {
		MescrollItem,
		UButton,
		headerSerch,
		latestGroupBuying
	},
	data () {
		return {
			swiperHeight:'600px',
			tabIndex:0,
			sysHeight: sysHeight,
			sysHeightTop: sysHeightTop,
			showTips: false,
			showMap: false,
			markers: [{
				id: 1,
				latitude: '',//纬度，必填
				longitude: '',//经度，必填
				title: '',//标注点名
				width: 32,//标注图标宽度，Number类型
				height: 32,//标注图标高度，Number类型
				iconPath: '../../../static/images/addressIcon.png',//显示的图标，必填
				label: {
					content: '',
					textAlign: "center"
				}
			}],

			currentId: 0,
			noticeShow: false,
			noticeContent: '',
			tempArr: [],
			where: {
				zoneType: 8,
				current: 1,
				size: 20,
			},
			isSortType: 0,

			current: 0,
			noticeList: [],
			notice: [
				'寒雨连江夜入吴',
				'平明送客楚山孤',
				'洛阳亲友如相问',
				'一片冰心在玉壶'
			],
			swiperList: [],
			navigationList: [{
				title: '最新团购',
				id: '0'
			}, {
				title: '历史团购',
				id: '1'
			}],
			positionInfo: {
				address: '',
				longitude: '', //经度
				latitude: '', //纬度
			},

			user_latitude: '',
			user_longitude: ''
		}
	},
	computed: mapGetters(['isLogin']),
	created () {
		this.getAdsList();
		this.getLatestGroupon();
		this.getCurrentLocation()
		let sysInfo=uni.getSystemInfoSync();
		console.log("设备信息")
		console.log(sysInfo)
		this.swiperHeight= sysInfo.windowHeight -(sysInfo.screenWidth/750) * (200) +'px';
		console.log(this.swiperHeight)
	},
	onMounted (options) {
	},
	onLoad (options) {
	},
	updated () {
	},
	onShow(){
    this.getAdsList();
		if (this.markers[0].label.content){
			this.getCurrentLocation()
		}
	},
	watch: {
		// isLogin: {
		// 	deep: true, //深度监听设置为 true
		// 	handler: function (newV, oldV) {
		// 		this.getAdsList()
		// 		this.getLatestGroupon()
		// 	}
		// }
	},
	methods: {

		clickImageUrl(e){
			let item =this.swiperList[e]

			if (item.skipType === 2){//跳转到文章链接
				uni.navigateTo({
					url: '/pages/groupbuying/article/article?id='+item.dataId
				});
			}
			if (item.skipType === 3){ //跳转到团购详情链接
				uni.navigateTo({
					url: item.targetUrl
				});
			}
		},

		swiperChange(e) {
			this.tabIndex = e.detail.current
		},

		changeAddress () {
			uni.chooseLocation({
				latitude: this.markers[0].latitude || '', /* 纬度 */
				longitude: this.markers[0].longitude || '', /* 经度 */
				success: (res) => {
					if (res.name){
						this.markers[0].latitude = res.latitude;
						this.markers[0].longitude =res.longitude;
						this.markers[0].label.content = res.name;
						uni.setStorageSync('user_longitude', res.longitude);
						uni.setStorageSync('user_latitude', res.latitude);
					}
				},
				fail: function (err) {
					console.log(err)
				}
			})
		},
		// 通过自带的方法获取到当前的经纬度，调用方法获取到地址获取到地址的中文信息
		getCurrentLocation () {
			let that = this //在uniapp中药定义一下this才能使用
			uni.getLocation({
				type: 'wgs84',
				success: function (res) {
					uni.setStorageSync('user_longitude', res.longitude);
					uni.setStorageSync('user_latitude', res.latitude);
					console.log("dizhixinxi -> ", res)
					that.markers[0].longitude = res.longitude;
					that.markers[0].latitude = res.latitude;
					getAddress(res.longitude, res.latitude).then(res => {
						//初始化地址信息
						console.log("++++++++++初始化地址信息++++++++++++", res)
						// if (res.result.address_component.city.indexOf('上海') === -1){
						// 	that.showTips= true;
						// }
						that.positionInfo.address = res.result.address_reference.landmark_l2.title
						that.markers[0].label.content = res.result.address_reference.landmark_l2.title
					})
				}
			});

		},


		// 获取当前地址
		loAcquire (longitude, latitude) {
			let that = this;
			// uni.showLoading({
			// 	title: '加载中',
			// 	mask: true
			// });
			let str = `output=jsonp&key='此处输入你申请的密钥'=${latitude},${longitude}` //记得在这里要输入密钥哦！
			console.log(this.$jsonp);
			this.$jsonp('https://apis.map.qq.com/ws/geocoder/v1/?', {}).then(res => {
				console.log(res);
				uni.hideLoading();
				if (res.status == 0) {
					that.positionInfo.address = '当前位置是:' + res.result.address_component.street_number; //当前定位
				}
			})
		},
		pullResh () {
			// if (this.current == 0) {
			// 	uni.showLoading({ title: '刷新中' });
				this.getAdsList()
			// 	this.getLatestGroupon()
			// } else {
			// 	this.$refs.latestGroupBuying.getGoodsPage()
			// }
		},
		getLatestGroupon () {
			// let that = this;
			// latestGroupon({
			// 	current: 1,
			// 	size: 1,
			// 	longitude: that.positionInfo.longitude,
			// 	latitude: that.positionInfo.latitude
			// }).then(res => {
			// 	console.log(res)
			// })
		},
		getGoodsInfo () {
			getGoodsInfo({
				current: 1,
				size: 50,
				isRecom: 1
			}).then(res => {
				this.tempArr = res.data
				uni.stopPullDownRefresh()
				uni.hideLoading();
			})
		},
		getBroGoodsInfo () {
			getGoodsInfo({
				current: 1,
				size: 50,
				zoneType: 6
			}).then(res => {
				this.tempArrBao = res.data
			})
		},
		getCategoryOne () {
			getCategoryOne().then(res => {
				this.navigationList = []
				let tuiJian = {
					title: '推荐',
					id: '0'
				}
				this.navigationList = res.data
				this.navigationList.unshift(tuiJian)
			})
		},


		noticeClose () {
			this.noticeShow = false
		},
		goNoticeDetail (value) {
			this.noticeContent = this.noticeList[value].content
			this.noticeShow = true
		},
		getNoticeList () {
			getNoticeList().then(res => {
				this.notice = []
				this.noticeList = res.data
				res.data.forEach(element => {
					this.notice.push(element.title)
				});
			})
		},
		getAdsList () {
			let that = this;
			getAdsList({
				type: 2
			}).then(res => {
				if (res.data.length > 0) {
					that.swiperList = []
					that.swiperList = res.data
					// res.data.forEach(element => {
					// 	that.swiperList.push(element.imageUrl)
					// });
				}
			});
		},

		clickNav (e) {
			this.tabIndex=e.index
			this.current = e.index
			// if (e.index > 0) {
			this.currentId = e.id
			// }
			// console.log("currentId ->", this.currentId)
		}
	}
}
</script>

<style lang="scss" scoped>
page {
	background-color: #ee4040;
}

.header-group {
	background-color: #F9F9F9;

	.search-group {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 30rpx 30rpx 10rpx 30rpx;


		.logo {
			width: 138rpx;
			height: 46rpx;
		}

		.message {
			line-height: 1;

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

		.search {
			flex: 1;
			padding: 0 30rpx;

			.searchBox {
				padding: 0 30rpx;
				display: flex;
				align-items: center;
				background-color: #FFF;
				border-radius: 100rpx;
				height: 60rpx;

				image {
					width: 28rpx;
					height: 28rpx;
					padding-right: 20rpx;
				}

				text {
					font-size: 24rpx;
					color: #999;
				}

			}
		}
	}

	.tabs {
		padding: 0 20rpx;
	}
}

.tab-content {
	.swiper-group {
		padding: 20rpx 30rpx 10rpx 30rpx;
		background-image: linear-gradient(to bottom, #EB4C63, #F9F9F9);
	}

	.grid-box {
		padding: 10rpx 30rpx 20rpx 30rpx;

		.grid-group {
			padding: 20rpx 0;
			border-radius: 20rpx;
			background-color: #FFF;
			display: flex;
			align-items: center;
			flex-wrap: wrap;

			.grid-item {
				width: 33.333%;
				display: flex;
				flex-direction: column;
				align-items: center;
				margin: 10rpx 0;

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

				text {
					font-size: 24rpx;
					color: #666;
					margin-top: 10rpx;
				}
			}

		}
	}

	.notice {
		padding: 0 30rpx;
	}

	.sale-group {
		padding: 20rpx 30rpx;

		.sale-content {
			border-radius: 20rpx;
			background-image: linear-gradient(45deg, #EB4C63, #FFA470);
			padding: 20rpx 0;

			.title {
				display: flex;
				align-items: center;
				justify-content: space-between;
				color: #FFF;
				font-weight: bold;
				padding: 0 30rpx;

				.more {
					display: flex;
					align-items: center;
					font-size: 24rpx;
					font-weight: normal;

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

			.goods-scroll {
				white-space: nowrap;
				padding: 20rpx 15rpx 0 15rpx;

				.goods-item {
					display: inline-block;
					width: 240rpx;
					padding: 15rpx;
					margin: 0 10rpx;
					background-color: #FFF;
					border-radius: 10rpx;

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

					.goods-name {
						font-size: 26rpx;
						color: #333;
						width: 240rpx;
						margin: 6rpx 0;
						word-break: break-all;
						white-space: pre-wrap;
						text-overflow: ellipsis;
						display: -webkit-box;
						line-height: 1.2;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
						overflow: hidden;
					}

					.tags {
						display: inline-block;
						font-size: 20rpx;
						padding: 6rpx;
						background-color: #FCE9EC;
						color: #EB4C63;
						margin: 6rpx 0;
					}

					.price {
						font-size: 32rpx;
						font-weight: bold;
						color: #EB4C63;
					}
				}


			}
		}
	}

	.goods-list {
		.title {
			text-align: center;
			color: #333;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 32rpx;
			font-weight: bold;

			.line {
				display: inline-block;
				width: 200rpx;
				height: 2rpx;
				margin: 0 30rpx;
				background-color: #FFA470;
			}
		}

		.list-group {
			display: flex;
			align-items: center;
			flex-wrap: wrap;
			padding: 15rpx;
			box-sizing: border-box;

			.list-item-content {
				width: 50%;
				padding: 15rpx;
				box-sizing: border-box;

				.list-item {
					padding: 15rpx;
					background-color: #FFF;
					border-radius: 10rpx;

					image {
						width: 100%;
					}

					.goods-name {
						font-size: 28rpx;
						color: #333;
						margin: 6rpx 0;
						word-break: break-all;
						white-space: pre-wrap;
						text-overflow: ellipsis;
						display: -webkit-box;
						line-height: 1.4;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
						overflow: hidden;
					}

					.tags {
						display: inline-block;
						font-size: 20rpx;
						padding: 6rpx;
						background-color: #FCE9EC;
						color: #EB4C63;
						margin: 6rpx 0;
					}

					.price {
						font-size: 32rpx;
						font-weight: bold;
						color: #EB4C63;
					}
				}
			}
		}
	}

}



.nav-bar_2 {
	width: 374px;
	margin-top: 6px;
	padding: 10px 9px 7px 16px;
}

.text_3 {
	overflow-wrap: break-word;
	color: rgba(51, 51, 51, 1);
	font-size: 18px;
	letter-spacing: 2px;
	font-family: STYuanti-SC-Regular;
	font-weight: NaN;
	text-align: left;
	white-space: nowrap;
	line-height: 24px;
	margin-top: 3px;
}

.applet-top-bar_1 {
	width: 90px;
	height: 30px;
}


.block_2 {
	display: flex;
	justify-content: space-around;
	box-shadow: 0px 2px 4px 0px rgba(178, 35, 56, 0.05);
	background-image: url(../../../static/images/addressBgi.png);
	background-size: cover;
	align-self: center;
	margin: 20rpx;
	margin-top: 4px;
	padding: 15px 8px 15px 8px;
}

.flex-row {
	display: flex;
}

.image-text_9 {
	width: 228px;
}

.icon_1 {
	width: 16px;
	height: 16px;
	margin: 2px 0 2px 0;
}

.text-group_1 {
	overflow-wrap: break-word;
	color: rgba(51, 51, 51, 1);
	font-size: 12px;
	text-align: left;
	white-space: nowrap;
	line-height: 20px;
	max-width: 190px;
	display: block;
	white-space: pre-line;
	margin-left: 20rpx;
}

.image-text_10 {
	width: 56px;
}

.text-group_2 {
	overflow-wrap: break-word;
	color: rgba(153, 153, 153, 1);
	font-size: 10px;
	font-weight: NaN;
	line-height: 20px;
}

.icon_2 {
	width: 12px;
	height: 12px;
	margin: 4px 0 4px 0;
}

.bord {
	border: 1px solid red;
}

.map_box {
	width: 100%;
	height: 70px;
}

.map {
	width: 100%;
	height: 100%;
}

.indicator {
	@include flex(row);
	justify-content: center;

	&__dot {
		height: 6px;
		width: 6px;
		border-radius: 100px;
		background-color: rgba(255, 255, 255, 0.35);
		margin: 0 5px;
		transition: background-color 0.3s;

		&--active {
			background-color: #ffffff;
		}
	}
}

.indicator-num {
	padding: 2px 0;
	background-color: rgba(0, 0, 0, 0.35);
	border-radius: 100px;
	width: 35px;
	@include flex;
	justify-content: center;

	&__text {
		color: #FFFFFF;
		font-size: 12px;
	}
}

.popup {
	width: 750rpx;
	height: 750rpx;
	background-color: #F9F9F9;
}

.map1_box {
	width: 750rpx;
	height: 670rpx;
}

.btn_box {
	width: 750rpx;
	height: 80rpx;
}


.TipsPop {
	width: 60vh;
	position: relative;
}


.tips {
	width: 550rpx;
	border-radius: 30px;
	left: 50%;
	transform: translateX(-50%);
	height: 45vh;
	background-size: 100% auto;
	background-image: url('http://www.gzzzyd.com/groupon/home_slices/编组 47@2x.png');
	background-repeat: no-repeat;
	text-align: center;
	border-radius: 20rpx;
	padding: 30rpx;
	position: absolute;
	top: -100rpx;

}

.txt {
	top: 30px;
	width: 550rpx;
	border-radius: 30px;
	left: 50%;
	transform: translateX(-50%);
	height: 50vh;
	text-align: center;
	position: relative;
	z-index: 999;
	padding: 30rpx;

	.tips1 {
		height: 80rpx;
		font-size: 56rpx;
		font-weight: 400;
		color: #333333;
		line-height: 80rpx;
		letter-spacing: 5px;
		margin-bottom: 30rpx;
	}

	.tips2 {
		height: 88rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #333333;
		line-height: 44rpx;
		margin-bottom: 30rpx;
	}

	.tips3 {
		height: 66rpx;
		font-size: 48rpx;
		font-weight: 600;
		color: #333333;
		line-height: 66rpx;
		margin-bottom: 30rpx;
	}

	.tips4 {
		height: 34rpx;
		font-size: 24rpx;
		font-weight: 400;
		color: #333333;
		line-height: 34rpx;
		margin-bottom: 30rpx;

		.red {
			color: #B42A3E;
		}
	}

	.tips5 {
		position: absolute;
		bottom: 50px;
		width: 80%;
		left: 50%;
		transform: translateX(-50%);
		height: 76rpx;
		background: #B42A3E;
		border-radius: 48rpx;
		line-height: 76rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #FFFFFF;
		margin-top: 30rpx;
	}
}

.index_body {
	position: relative;
}


.sys-head {
	position: relative;
	width: 100%;
	// background: linear-gradient(90deg, $bg-star1 0%, $bg-end1 100%);

	.bg {
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		background: var(--view-theme);
		background-size: 100% auto;
		background-position: left bottom;
	}

	.sys-title {
		font-family: STYuanti-SC-Regular, STYuanti-SC;
		z-index: 10;
		position: relative;
		height: 43px;
		text-align: left;
		line-height: 43px;
		font-size: 36rpx;
		color: rgba(17, 17, 17, 1);
		/*font-weight: bolder;*/
		font-weight: 400;
		padding-left: 36rpx;
		color: #333333;
	}
}

</style>
