<template>
	<view class="Circle_friends">
		<view class="circle_friends_wrapper">


			<view @click="selectLocation" v-if="isFshow">
				<view class="site-box flex_a_c_j_sb" :style="{'background-color':backColor}">

					<view :class="['place_wrapper','flex_a_c',isFshow?'sitebox':'']">
						<view :class="['iconfont','icon-weizhi',isFshow?'sitebox':'']" style="margin-left: 20rpx;">
						</view>
						<view class="town_name">{{street}}</view>
					</view>
					<navigator url="/pages/chat/customer_list/index?type=0" hover-class="none">
						<view :class="['iconfont','icon-xiaoxi',isFshow?'sitebox':'']" style="color:#fff;"></view>
					</navigator>
				</view>
				<!-- <view class="site-box ','flex_a_c_j_sb'" v-if="ishshow">
				<view class="bg-img">
					<img :src="bgColor" alt="">
				</view>
			</view> -->
			</view>



			<zbpSwiper :isSelectPlace="true" :town='street' :streetname='street' :location_Arr="locationArr"
				@change='dchange'>
			</zbpSwiper>


			<view class="list">
				<navigator hover-class="none"
					:url="`/pages/nongKe/supply_chain/supplier?type_id=10&street_id=${street_id}`">
					<view class="list-m">
						<image src="@/static/images/f6.png" mode="aspectFit"></image>
						<view class="list-title">
							<view class="list-titlea">
								<image src="@/static/images/p9.png" mode="aspectFit"></image>
								<view class="titlea-con">
									<view class="titlea">september</view>
									<view class="titleb">
										9月
									</view>
								</view>
							</view>
							<view class="list-titleb">
								<view class="titlea">
									{{town}}
								</view>
								<view class="titleb">
									综合供销云市场
								</view>
							</view>

						</view>
						<view class="list-title-info" style="color:#3A7331 ;">
							<view class="">
								点击查看
							</view>

							<view class="title-infoimg">
								<image src="@/static/images/pj.png" mode="aspectFit"></image>
							</view>
						</view>
					</view>


				</navigator>

				<view class="list-m" @click="go_shop">
					<image src="@/static/images/f1.png" mode="aspectFit"></image>
					<view class="list-title">
						<view class="list-titlea">
							<image src="@/static/images/p8.png" mode="aspectFit"></image>
						</view>
						<view class="list-titleb">
							<view class="titlea">
								里海云仓
							</view>
							<view class="titleb">
								行业分类市场
							</view>
						</view>
					</view>
					<view class="list-title-info" style="color:#FF6B00 ;">
						<view class="">
							点击查看
						</view>
						<view class="title-infoimg">
							<image src="@/static/images/pj1.png" mode="aspectFit"></image>
						</view>
					</view>
				</view>
			</view>

			<view class="list-con">
				<view class="list-con-left">
					<!-- <view class="list-con-title">
						<view class="con-titlea">
							名优特产
						</view>
						<view class="con-titleb">
							精选当地特色特产
						</view>
					</view> -->
					<image src="@/static/images/f5.png" mode="aspectFit"></image>
				</view>
				<view class="list-con-right">
					<view class="con-right" style="margin-bottom: 20rpx;">
						<!-- <view class="list-con-title">
							<view class="con-titlea">
								当地美食
							</view>
							<view class="con-titleb">
								美食线上一条街
							</view>
						</view> -->
						<image src="@/static/images/f7.png" mode="aspectFit"></image>
					</view>
					<view class="con-right">
						<!-- <view class="list-con-title">
							<view class="con-titlea">
								特色文旅
							</view>
							<view class="con-titleb">
								热门景区，当地文化
							</view>
						</view> -->
						<image src="@/static/images/f2.png" mode="aspectFit"></image>
					</view>

				</view>
			</view>
			<view class="list-bon">
				<image src="@/static/images/f4.png" mode="aspectFit"></image>
			</view>
			<view class="goodslist">
				<WaterfallsFlow :wfList='cateGoods' />

			</view>
			<view class="empty_wrapper" v-if="emptyShow">
				<u-empty :show="emptyShow" mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png"></u-empty>
			</view>
		</view>

		<u-picker :defaultIndex="[0,0]" :show="showPicker" ref="uPicker" :columns="columnData" @confirm="confirm"
			@cancel="showPicker = false" @change="changeHandler" keyName="name"></u-picker>
		<u-loadmore :status="status" v-if="cateGoods.length>=where.limit" />

		<view class="location" v-if='isshow'>
			<view class="locationa">
				位置权限使用说明
			</view>
			<view class="locationb">
				用于向你推荐最近门店
			</view>
		</view>
	</view>
</template>

<script>
	import mTabbar from '@/components/m-tabbar/m-tabbar.vue'
	import zbpSwiper from '@/components/zbpSwiper'
	import easyLoadimage from '@/components/easy-loadimage/easy-loadimage.vue';
	import WaterfallsFlow from '@/components/WaterfallsFlow/WaterfallsFlowo.vue'
	import Cache from '@/utils/cache';
	import {
		getSlideAPI
	} from '@/api/lihai.js'
	import {
		graphicLstApi,
		getTopicList,
		graphicStartApi
	} from '@/api/community.js'
	import {
		getIndexData,
		getDiy,

	} from '@/api/api.js'

	import {
		spuInfo
	} from '@/api/product.js';
	import {
		getGeocoder,
		merClassifly,
		getProductHot
	} from '@/api/store.js';
	import {
		getArea,
		getStreet
	} from '@/api/article.js';
	import {
		Toast
	} from '@/libs/uniApi'
	export default {
		components: {
			mTabbar,
			zbpSwiper,
			easyLoadimage,
			WaterfallsFlow
		},
		data() {
			return {
				activeStyle: {

					color: '#333333',
					fontWeight: 'bold',
					transform: 'scale(1.04)'
				},
				isshow: false,
				locationArr: ({}),
				status: 'loadmore',
				bgColor: '',
				showPicker: false,
				columnData: [],
				show: false,
				tabsData: {
					list: [],
					tabsActive: 0
				},
				tabsData1: {
					list: [],
					tabsActive: 0
				},
				where: {
					category_id: 0,
					page: 1,
					limit: 6
				},
				where1: {

					page: 1,
					limit: 6
				},
				currentItemId: 69, // 默认获取 社区的数据 0 表示推荐 || 69 社区
				keyword: '',
				location: '',
				emptyShow: false,
				town: '',
				cateGoods: [],
				recoList: [],
				articleList: [],
				street_id: '',
				street: '',
				bgColor: '',
				isFshow: false,
				backColor: 'rgba(248, 66, 33, 0)'
			}
		},

		onPullDownRefresh() {
			this.cateGoods = []
			this.list()
			this.Area()
			uni.stopPullDownRefresh()
		},

		onLoad() {
this.list()

			this.Area()


			// this.openTongZhi()
			uni.$on('connectstatusChange', (connectstatus) => {
				var connectstr = ''
				if (connectstatus == true) {
					connectstr = '已连接'
					this.getRegistrationID()
				} else {
					connectstr = '未连接'
				}
				this.connectstatus = connectStr
			})

		},

		onReachBottom() {
			if (this.status == 'nomore') return;
			this.status = 'loading';
			t
			this.where.page = ++this.where.page;
			this.list()
		},
		mounted() {

			// #ifdef  H5
			// 监听页面滚动事件
			window.addEventListener("scroll", this.scrolling);
			// #endif

			this.$bus.$on('value-updated', (newValue) => {
				// 更新父组件的值
				this.street = newValue.split(',')[0]
				this.town = newValue.split(',')[0]
				this.street_id = newValue.split(',')[1]
			});



			if (this.street.length <= 0) {
				this.selfLocation()
			}

		},
		// #ifdef APP-PLUS
		onPageScroll(e) {

			const scrollTop = e.scrollTop;
			if (scrollTop <= 20) {
				this.backColor = 'rgba(248, 66, 33, 0)'
				this.isFshow = false
			} else if (20 < scrollTop && scrollTop <= 100) {
				this.backColor = 'rgba(248, 66, 33, .5)'
				this.isFshow = true
			} else if (scrollTop > 100) {
				this.backColor = 'rgba(248, 66, 33, 1)'
				this.isFshow = true


			}
		},
		// #endif

		methods: {
			list() {
				 getProductHot(1,10).then(res => {
					// console.log(res)
					this.cateGoods = res.data.list
				})
				// spuInfo('510502106', this.where1).then(res => {
				// 	// console.log(res)
				// 	this.cateGoods = res.data.list
				// })
			},
			scrolling() {
				// 滚动条距文档顶部的距离
				let scrollTop =
					window.pageYOffset ||
					document.documentElement.scrollTop ||
					document.body.scrollTop;
				// 滚动条滚动的距离
				let scrollStep = scrollTop - this.oldScrollTop;
				// console.log("header 滚动距离 ", scrollTop);
				// 更新——滚动前，滚动条距文档顶部的距离
				this.oldScrollTop = scrollTop;

				//变量windowHeight是可视区的高度
				let windowHeight =
					document.documentElement.clientHeight || document.body.clientHeight;
				//变量scrollHeight是滚动条的总高度
				let scrollHeight =
					document.documentElement.scrollHeight || document.body.scrollHeight;

				//滚动条到底部的条件
				if (scrollTop + windowHeight == scrollHeight) {
					//你想做的事情
					// console.log("header  你已经到底部了");
				}


				if (scrollTop <= 20) {
					this.backColor = 'rgba(248, 66, 33, 0)'
					this.isFshow = false
				} else if (20 < scrollTop && scrollTop <= 100) {
					this.backColor = 'rgba(248, 66, 33, .5)'
					this.isFshow = true
				} else if (scrollTop > 100) {
					this.backColor = 'rgba(248, 66, 33, 1)'
					this.isFshow = true


				}


			},






			getCloudShopMerId(id) {
				get_cloud_shop(id).then(res => {
					res.data.length > 0 ? this.isYunCang = 1 : this.isYunCang = 0
				})
			},
			selectLocation() {

				this.showPicker = true
			},
			confirm(e) {

				this.street = e.value[1].name
				this.street_id = e.value[1].code
				this.town = e.value[1].name
				uni.setStorageSync('ADRESS_LOCATION',
					e.value[1].name + ',' + e.value[1].name + ',' +

					e.value[1].code
				)
				this.showPicker = false
			},
			changeHandler(e) {
				const {
					columnIndex,
					value,
					values,
					index,
					picker = this.$refs.uPicker
				} = e;
				if (columnIndex === 0) {
					getStreet({
						area_code: value[0]['code']
					}).then(res => {
						this.$refs.uPicker.setColumnValues(1, res.data);
					});
				}
			},
			Area() {
				getArea({
					city_code: 510500
				}).then(res => {
					this.$refs.uPicker.setColumnValues(0, res.data);
					this.Street(res.data[0]['code']);
				});
			},
			Street(code) {
				getStreet({
					area_code: code
				}).then(res => {
					this.$refs.uPicker.setColumnValues(1, res.data);
				});
			},
			gogogo(item) {
				if (item.video_link.length > 0) {

					uni.navigateTo({
						// #ifdef MP || H5
						url: `/pages/short_video/nvueSwiper/index?id=${item.community_id}`
						// #endif
						// #ifdef APP
						url: `/pages/short_video/appSwiper/index?id=${item.community_id}`
						// #endif
					})

				} else {
					uni.navigateTo({

						url: `/pages/plantGrass/plant_detail/index?id=${item.community_id}`
					})
				}
			},
			giveStart(item) {
				let status = item.relevance_id ? 0 : 1
				graphicStartApi(item.community_id, {
					status: status
				}).then(res => {
					if (item.relevance_id) {
						item.count_start--;
						item.count_start = item.count_start == 0 ? 0 : item.count_start
						item.relevance_id = false
					} else {
						item.count_start++;
						item.relevance_id = true
					}
				})
			},
			go_shop() {
				if (this.isYunCang == 0) {
					return Toast('当前区域没有云仓库')
				}
				uni.navigateTo({
					url: `/pages/nongKe/cloud_entrepot/index?street=${this.street_id}&town=${this.town}`
				})

			},
			dchange(e) {
				this.street = e.value[1].name
				this.street_id = e.value[1].code
				this.town = e.value[1].name
			},
			selfLocation() {
				if (uni.getStorageSync('loction') == true) {
					this.isshow = false
				} else {
					this.isshow = true
					uni.setStorageSync('loction', true);
				}
				uni.getLocation({
					type: 'wgs84',
					timeout: '10',
					success: (res) => {

						this.isshow = false
						let latitude, longitude;
						latitude = res.latitude.toString();
						longitude = res.longitude.toString();
						getGeocoder({
							lat: latitude,
							long: longitude
						}).then(res => {
							this.town = res.data.address_reference.town.title
							this.street_id = res.data.address_reference.town.id
							this.street = res.data.address_component.street
							uni.$emit('add', this.street + ',' + this.street_id)
							// uni.setStorageSync('ADRESS_LOCATION',
							// 	this.town + ',' + this.street_id)
							// this.list()
						}).catch(err => {
							uni.showToast({
								title: err,
								icon: 'none'
							})
						})
					},
					fail: (err) => {
						this.isshow = false
						// uni.showToast({
						// 	title: "获取定位超时",
						// 	icon: 'none',
						// 	duration: 2000
						// });
					}
				});
			},



		}
	}
</script>

<style lang="scss" scoped>
	/deep/.color-lump {
		display: none;
	}

	page {
		background: #F4F7FE;

		// background: linear-gradient(180deg, #FFFFFF 0%, #F6F6F6 100%);
	}

	.location {
		background-color: #F6F6F6;
		width: 680rpx;
		height: 150rpx;
		position: absolute;
		top: 0;
		z-index: 9999;
		border-radius: 20rpx;
		left: 50%;
		margin-left: -340rpx;
		margin-top: 80rpx;
		padding-left: 20rpx;

		.locationa {
			font-size: 28rpx;
			color: #000;
			font-weight: 500;
			margin-top: 30rpx;
			margin-bottom: 15rpx;
		}

		.locationb {
			font-size: 20rpx;
			color: #5a5a5a;
		}
	}

	.Circle_friends {
		position: relative;
		padding: 0 0 87.72rpx 0;

	}



	.sitebox {
		animation-name: fadeIn;
		animation-duration: 3s;
		animation-fill-mode: forwards;
	}

	@keyframes fadeIn {
		from {
			opacity: 0;
		}

		to {
			opacity: 1;
		}
	}


	.site-box {
		width: 100%;
		/* #ifdef MP || APP-PLUS */
		height: 160rpx;
		/* #endif */
		/* #ifdef H5 */
		height: 120rpx;
		/* #endif */
		margin-bottom: 26.32rpx;
		position: absolute;
		top: 0rpx;
		position: fixed;
		z-index: 999;
		/* #ifdef MP || APP-PLUS */
		padding-top: 75rpx;
		/* #endif */
		/* #ifdef H5 */
		padding-top: 25rpx;
		/* #endif */
		// background-color: #e5e5e5;


		padding-right: 20rpx;

		// 位置
		.place_wrapper {
			color: #fff;
			margin-right: 24.56rpx;
			font-size: 30rpx;

			opacity: 0;

			.town_name {
				margin-left: 21rpx;
			}
		}

		.iconfont {
			opacity: 0;
			font-size: 30rpx;
			font-size: 35.09rpx;
		}
	}



	.circle_friends_wrapper {
		position: relative;

		z-index: 2;
	}

	/deep/.u-tabs__wrapper__nav__line {
		width: 46rpx;


	}

	/deep/.u-tabs__wrapper__nav__item {
		padding: 0 0px;
		padding-right: 10rpx;
	}

	.search_wrapper {
		width: 694.74rpx;
		margin: 0 auto;
	}

	.tabs_wrapper {
		width: 720rpx;
		margin: 0 auto;
		margin-bottom: 21.05rpx;
		// margin-left: -20rpx;

	}

	.empty_wrapper {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.article_box {
		height: 100%;
		width: 694.74rpx;
		margin: 0 auto;
		background-color: #fff;
		border-radius: 16rpx;
		padding: 0 24.56rpx;
		box-sizing: border-box;

		.title-box {
			height: 87.72rpx;

			text {
				font-size: 28.07rpx;
			}
		}

		.article-item {
			display: flex;
			// height: 175.44rpx;
			justify-content: space-between;
			border-bottom: 1px solid #f0f0f0;
			padding: 21.05rpx 0;

			.text {
				flex: 1;
				height: 122.81rpx;
				margin-right: 17.54rpx;
				font-size: 24rpx;
				color: #999;
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				.name {
					font-size: 26.32rpx;
					color: #282828;
				}
			}

			.pictrue {
				width: 175.44rpx;
				height: 122.81rpx;

				image {
					width: 100%;
					height: 100%;
					border-radius: 8px;
				}
			}
		}
	}

	.tabs_wrapper {
		width: 723rpx;
		margin: 0rpx auto;
		margin-bottom: 21.05rpx;

		.title {
			font-size: 31.58rpx;
			font-weight: bold;

			&::before {
				content: '';
				display: inline-block;
				width: 3px;
				height: 31.58rpx;
				background-color: #F84221;
				margin-right: 7.02rpx;
			}
		}
	}

	.list {
		display: flex;
		padding: 12rpx;
		justify-content: space-between;

		.list-m {
			width: 356rpx;
			height: 235rpx;
			position: relative;


			.list-title {
				display: flex;
				position: absolute;
				top: 20rpx;

				.list-titlea {

					margin-left: 14rpx;
					width: 96rpx;
					height: 117rpx;
					margin-right: 11rpx;
					position: relative;

					.titlea-con {
						position: absolute;
						top: 20rpx;
						color: #F4F7FE;

						.titlea {
							margin-top: 12rpx;
							margin-left: 12rpx;
							font-size: 16rpx;
							font-family: PingFang SC-Semibold, PingFang SC;
						}

						.titleb {
							margin-top: 6rpx;
							font-size: 37rpx;
							font-family: PingFang SC-Semibold, PingFang SC;
							font-weight: 600;
							color: #FFFFFF;
							margin-left: 20rpx;
						}
					}


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

				.list-titleb {

					.titlea {

						font-size: 37rpx;
						font-family: PingFang SC-Semibold, PingFang SC;
						font-weight: 600;
						color: #FFFFFF;
						margin-top: 10rpx;

					}

					.titleb {

						font-size: 33rpx;
						font-family: PingFang SC-Medium, PingFang SC;
						font-weight: 500;
						color: #FFFFFF;

					}
				}
			}

			.list-title-info {
				width: 98rpx;
				height: 30rpx;
				background: #FFFFFF;
				padding: 2rpx 2rpx;
				display: flex;
				font-size: 10rpx;
				font-size: 18rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #FF6B00;
				border-radius: 19rpx 19rpx 19rpx 19rpx;
				position: absolute;
				bottom: 14rpx;
				left: 50%;
				margin-left: -49rpx;
				padding-left: 15rpx;

				.title-infoimg {
					width: 18rpx;
					height: 18rpx;
					margin: auto 0;

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

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

	.list-con {
		display: flex;
		justify-content: space-between;
		margin-top: -10rpx;
		padding: 12rpx;

		.list-con-left {
			width: 357rpx;
			height: 482rpx;
			position: relative;


			.list-con-title {
				position: absolute;
				top: 0;
				z-index: 10;
				padding-left: 14rpx;

				.con-titlea {
					font-size: 37rpx;
					font-family: PingFang SC-Semibold, PingFang SC;
					font-weight: 600;
					color: #FFFFFF;
					margin-top: 10rpx;

				}

				.con-titleb {
					margin-top: 5rpx;
					font-size: 33rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
				}
			}

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

		.list-con-right {
			width: 356rpx;

			.con-right {
				width: 356rpx;
				height: 235rpx;
				position: relative;


				.list-con-title {
					position: absolute;
					top: 0;
					z-index: 10;
					padding-left: 14rpx;

					.con-titlea {
						font-size: 37rpx;
						font-family: PingFang SC-Semibold, PingFang SC;
						font-weight: 600;
						color: #FFFFFF;
						margin-top: 10rpx;

					}

					.con-titleb {
						margin-top: 5rpx;
						font-size: 33rpx;
						font-family: PingFang SC-Medium, PingFang SC;
						font-weight: 500;
						color: #FFFFFF;
					}
				}

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

	.list-bon {
		width: 724rpx;
		height: 128rpx;
		margin: 0 auto;
		margin-bottom: 12rpx;

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

	.goodslist {
		margin: 0 auto;
		width: 725rpx;
	}
</style>