<template>
	<view>
		<!-- <headerSerch :dataConfig="headItem"></headerSerch> -->
		<view class="nav-bar_2 flex-row justify-between">
			<text class="text_3">中意购</text>
		</view>
		<view class="block_2 flex-row justify-between">
			<view class="image-text_9 flex-row justify-between">
				<image class="icon_1" referrerpolicy="no-referrer"
					src="https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng64f8d7838848f656c98b8047aa0940b03a63be81a880f5a9920d8242f6be887d" />
				<text class="text-group_1">上海市浦东新区秀浦路29号三层303室</text>
			</view>
			<view class="image-text_10 flex-row justify-between">
				<text class="text-group_2" @click="getCurrentLocation()">切换地点</text>
				<image class="icon_2" referrerpolicy="no-referrer"
					src="https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPng91356afb3fca819201cc9be0df3b1c18cca66d523b364042bcf5fbdf766a8902" />
			</view>
		</view>
		<!-- 轮播 -->
		<view class="swiper-group">
			<u-swiper :list="swiperList" @change="e => current = e.current" :autoplay="false">
            <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">
				<u-tabs class="defalt-utabs" :is-scroll="false" :list="navigationList" @click="clickNav" lineColor="#B22338" :inactiveStyle="{ color: '#999999' }"
					:activeStyle="{ color: '#B22338', fontWeight: 'bold' }" keyName="title"></u-tabs>
			</view>
		</view>

		<view class="good-list">
			<latestGroupBuying @changeTab="changeTab" :iSshowH="true" @detail="goDetail" :currentId="currentId"
-					:isSortType="false" :positionInfo="positionInfo" ref="latestGroupBuying"></latestGroupBuying>
		</view>

		<view v-if="!isLogin">
			<u-skeleton :loading="true" rows="20" :animate="true"></u-skeleton>
		</view>
		<view v-else>
		</view>
	</view>
</template>

<script>
import headerSerch from './components/headerSerch';
import latestGroupBuying from './components/latestGroupBuying';
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 {
	goShopDetail
} from '@/libs/order.js';
export default {
	components: {
		headerSerch,
		latestGroupBuying
	},
	data () {
		return {
			currentId: 0,
			noticeShow: false,
			noticeContent: '',
			tempArr: [],
			where: {
				zoneType: 8,
				current: 1,
				size: 20,
			},
			isSortType: 0,

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

			user_latitude: '',
			user_longitude: ''
		}
	},
	computed: mapGetters(['isLogin']),
	created () {
		this.getAdsList();
		this.getLatestGroupon();
		this.getCurrentLocation()
	},
	onMounted (options) {
	},
	onLoad (options) {

	},
	onShow () {

	},
	updated () {

	},
	watch: {
		isLogin: {
			deep: true, //深度监听设置为 true
			handler: function (newV, oldV) {
				this.getAdsList()
				this.getLatestGroupon()
			}
		}
	},
	methods: {
		// 通过自带的方法获取到当前的经纬度，调用方法获取到地址获取到地址的中文信息
		getCurrentLocation () {
			let that = this //在uniapp中药定义一下this才能使用
			uni.getLocation({
				type: 'wgs84',
				success: function (res) {
					console.log("dizhixinxi -> ", res)
					that.positionInfo.longitude = res.longitude;
					that.positionInfo.latitude = res.latitude;
					// that.loAcquire(that.positionInfo.longitude, that.positionInfo.latitude)
				}
			});
		},
		// 获取当前地址
		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)
			})
		},
		menusTap (url, zoneType) {
			let that = this
			// #ifdef H5
			location.href = url
			// #endif
			// #ifdef MP || APP-PLUS
			if (zoneType == 8) {
				//共富取消中间过渡界面
				getGoodsInfo(that.where).then(res => {
					let list = res.data;
					if (that.where.zoneType == 8 && list.length == 1) {
						// 自动跳转共富1580商品详情
						that.godDetail(list[0])
					}
				})
			} else {
				uni.navigateTo({
					url: "/pages/goods/goods_list_mall/index?zoneType=" + zoneType + "&title=" + url
				});
			}
			// #endif
		},
		// 去详情页
		godDetail (item) {
			goShopDetail(item, this.uid).then(res => {
				uni.navigateTo({
					url: `/pages/goods_details/index?id=${item.id}`
						+ "&zoneType=" + item.zoneType
				})
			})
		},
		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 = []
					res.data.forEach(element => {
						that.swiperList.push(element.imageUrl)
					});
				}
			});
		},
		// 促销列表的点击事件；
		changeTab (type) {
			this.goodType = type;
			this.tempArr = [];
			this.page = 1;
			this.loadend = false;
			let onloadH = true;
			this.getGroomList(onloadH);
		},
		// 精品推荐
		getGroomList (onloadH) {
			let that = this;
			let type = that.goodType;
			if (that.loadend) return false;
			if (that.loading) return false;
			if (onloadH) {
				that.$set(that, 'iSshowH', true);
			}
			uni.request({
				url: 'api/groom/list',
				success: res => {
					that.$set(that, 'iSshowH', false);
					let maxPage = Math.ceil(this.numConfig / this.limit);
					let list = res.data.list,
						loadend = list.length < that.limit || that.page >= maxPage;
					let tempArr = that.$util.SplitArray(list, that.tempArr);
					that.$set(that, 'tempArr', tempArr.slice(0, this.numConfig));
					that.loadend = loadend;
					that.loadTitle = loadend ? that.$t(`没有更多内容啦~`) : that.$t(`加载更多`);
					that.page = that.page + 1;
					that.loading = false;
				}
			})
			// getGroomList(type, {
			// 	page: that.page,
			// 	limit: this.numConfig
			// })
			// 	.then(({
			// 		data
			// 	}) => {
			// 		that.$set(that, 'iSshowH', false);
			// 		let maxPage = Math.ceil(this.numConfig / this.limit);
			// 		let list = data.list,
			// 			loadend = list.length < that.limit || that.page >= maxPage;
			// 		let tempArr = that.$util.SplitArray(list, that.tempArr);
			// 		that.$set(that, 'tempArr', tempArr.slice(0, this.numConfig));
			// 		that.loadend = loadend;
			// 		that.loadTitle = loadend ? that.$t(`没有更多内容啦~`) : that.$t(`加载更多`);
			// 		that.page = that.page + 1;
			// 		that.loading = false;
			// 	})
			// 	.catch(res => {
			// 		that.loading = false;
			// 		that.loadTitle = that.$t(`加载更多`);
			// 	});
		},
		goDetail (item) {
			goShopDetail(item, this.$store.state.app.uid).then(res => {
				uni.navigateTo({
					url: `/pages/goods_details/index?id=${item.id}`
				});
			});
		},
		// 去商品详情
		goGoodsDetail (item) {
			goShopDetail(item, this.uid).then(res => {
				uni.navigateTo({
					url: `/pages/goods_details/index?id=${item.id}`
				});
			});
		},
		clickNav (e) {
			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(https://lanhu-dds-backend.oss-cn-beijing.aliyuncs.com/merge_image/imgs/7ac954eaf57b4d42b263ef296c3fa351_mergeImage.png);
	align-self: center;
	margin: 20rpx;
	margin-top: 4px;
	padding: 15px 8px 15px 8px;
}

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

.flex-row {
	display: flex;
}

.image-text_10 {
	width: 56px;
}

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

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










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