<template>
	<view style="background-color: #ffffff;letter-spacing: 1rpx;">
		<tn-nav-bar :isBack="false" backTitle="" :bottomShadow="true" backgroundColor="#FFFFFF">
			<view class="custom-nav tn-flex tn-flex-col-center tn-flex-row-left">
				<view style="padding-left: 15rpx;" @click="goBack()">
					<text class="tn-icon-left" style="font-size: 40rpx;"></text>
				</view>
				<view class="tn-margin-top"
					style=";text-shadow:  1rpx 0 0 #FFF, 0 1rpx 0 #FFF, -1rpx 0 0 #FFF , 0 -1rpx 0 #FFF;">
					<tn-tabs :list="[{name:'会员地图'}]" :current="topCurrent" activeColor="#000" :bold="false"
						:fontSize="36"></tn-tabs>
				</view>
			</view>
		</tn-nav-bar>
		<view :style="{paddingTop: vuex_custom_bar_height + 'px'}"></view>
		<view style="background-color: #FFF;z-index: 200;">
			<view class="tn-flex tn-flex-row-between tn-flex-col-center tn-margin">
				<view class="justify-content-item align-content-item" style="width: 100%;position: relative;">
					<view class="tn-flex tn-flex-col-center"
						style="border-radius: 100rpx;padding: 15rpx;width: 100%;background-color:#F1F2F8;">
						<text style="color: #BABDC7;"
							class="tn-icon-search justify-content-item tn-padding-right-xs tn-text-lg"></text>
						<input v-model="serach_content" class="justify-content-item" placeholder="会员姓名/手机号" name="input"
							placeholder-style="color:#BABDC7" style="width: 100%;padding-right: 200rpx;"></input>
					</view>
					<view style="position: absolute;right: 6rpx;top: 6rpx">
						<tn-button backgroundColor="#3056D3" shape="round" padding="10rpx 10rpx" width="150rpx"
							@click="serach()" height="60rpx">
							<text style="color:#ffffff;font-weight: bold;">{{serach_do?'重 置':'搜 索'}}</text>
						</tn-button>
					</view>
				</view>
			</view>
		</view>
		<view>
			<view @click="coversShow = true" style="position: fixed;top: 50%;right: 30rpx;z-index: 1;">
				<image src="/static/map.png" style="width: 80rpx;height: 80rpx;"></image>
			</view>
			<map @markertap="openMark" :style="{width: '100%',height: my_page+'px'}" :scale="5" :latitude="34.75"
				:longitude="113.66" :markers="covers">
			</map>
			<tn-popup v-model="coversShow" mode="bottom" :mask="false" height="50%" :borderRadius="10">
				<scroll-view>
					<view v-for="item in covers" style="padding:20rpx 30rpx;">
						<view @click="tn('/pages/packageA/user/my_card?id='+item.id)"
							class="tn-classify__content__sub-classify__content__item tn-flex tn-flex-center  tn-flex-col-center">
							<view style="width: 100rpx;height: 100rpx">
								<image v-if="item.company_image!=''&&item.company_image!=null"
									:src="apiImgUrl+item.company_image"
									style="width: 100rpx;height: 100rpx;border-radius:50%;">
								</image>
								<image v-if="item.company_image==''||item.company_image==null" src="/static/def.png"
									style="width: 100rpx;height: 100rpx;border-radius:50%;">
								</image>
							</view>
							<view style="margin-left: 20rpx;">
								<view style="font-size: 28rpx;font-weight: 600;">
									<text>{{item.nikename}}</text>
								</view>
								<view class="tn-text-ellipsis-2"
									style="font-size: 24rpx;margin-top: 10rpx;color: #888888;">
									<text>{{item.title==null?'':item.title}}</text>
								</view>
							</view>

						</view>
					</view>
				</scroll-view>
			</tn-popup>
		</view>
	</view>
</template>

<script>
	import {
		latitudeAndLongitude
	} from '@/util/api.js';
	import store from "@/store";
	export default {
		data() {
			return {
				apiImgUrl: this.$store.state.imgUrl,
				my_page: 0,
				covers: [],
				coversShow: false,
				serach_content: '',
			}
		},
		onLoad() {
			this.getLatitudeAndLongitude();
			const key = uni.getSystemInfoSync();
			const kk = uni.getWindowInfo();
			var c = this.sizeDeal(120);
			var s = this.sizeDeal(0);
			this.my_page = parseInt(key.windowHeight) - parseInt(store.state.vuex_custom_bar_height) - parseInt(s) -
				parseInt(c);
		},
		methods: {
			openMark(d) {
				console.log(d);
			},
			serach() {
				this.coversShow = true;
				this.covers = [];
				this.getLatitudeAndLongitude();
			},
			getLatitudeAndLongitude() {
				latitudeAndLongitude({
						nikename: this.serach_content,
						enterprise_name: this.serach_content
					})
					.then(res => {
						console.log(res);
						var list = res.data;
						const transformedSelectList = list.map(item => ({
							latitude: parseFloat(item.dimension),
							longitude: parseFloat(item.longitude),
							id: item.id,
							iconPath: '/static/make.png',
							width: 30,
							height: 30,
							title: item.enterprise_name,
							company_image: item.company_image,
							nikename: item.nikename,
						}));
						console.log(transformedSelectList);
						this.covers = transformedSelectList;

					})
					.catch(error => {
						uni.showToast({
							title: error,
							icon: 'none',
							duration: 2000
						});
					})
			},
			tn(url) {
				uni.navigateTo({
					url: url
				})
			},
			sizeDeal(size) {

				// 使用uni.upx2px进行转换
				const pxValue = uni.upx2px(size);

				return pxValue;
			},
			goBack() {
				if (getCurrentPages().length > 1) {
					uni.navigateBack()
				} else {
					uni.redirectTo({
						url: '/pages/index/index'
					})

				}
			}
		}
	}
</script>


<style lang="scss" scoped>
	/* 自定义导航栏内容 start */
	.custom-nav {
		height: 100%;

		&__back {
			margin: auto 30rpx;
			margin-right: 10rpx;
			flex-basis: 5%;
			width: 100rpx;
			position: absolute;
		}
	}


	.left-width {
		flex-basis: 28%;
	}

	/* 自定义导航栏内容 end */
	.tn-classify {

		/* 搜索栏 start */


		/* 搜索栏 end */

		/* 分类列表和内容 strat */
		&__container {}

		&__left-box {}

		&__right-box {
			background-color: #F1F2F8;
		}

		/* 分类列表和内容 end */

		/* 侧边导航 start */
		&__tabbar {
			&__item {
				&:first-child {
					border-top-right-radius: 0rpx;
				}

				&:last-child {
					border-bottom-right-radius: 0rpx;
				}

				&--active {
					background-color: #F1F2F8;
					position: relative;
					font-weight: bold;
					color: #3056D3;

					&--prev {
						border-bottom-right-radius: 26rpx;
					}

					&--next {
						border-top-right-radius: 26rpx;
					}
				}
			}
		}

		/* 侧边导航 end */

		/* 分类内容 start */
		&__content {
			margin: 18rpx;

			/* 推荐商品 start */
			&__recomm {
				margin-bottom: 40rpx;

				&__swiper {}
			}

			/* 推荐商品 end */

			/* 子栏目 start */
			&__sub-classify {
				margin-bottom: 20rpx;
				padding-bottom: 40rpx;

				&--title {
					font-weight: bold;
					margin-bottom: 18rpx;

				}

				&__content {

					&__item {
						padding: 20rpx;
						background-color: #FFFFFF;
					}
				}
			}

			/* 子栏目 end */
		}

		/* 分类内容 end */
	}

	.tn-bg-my-ccc {
		background-color: #F1F2F8;
	}
</style>