<template>
	<view class="page">
		<!-- 用户首页显示 -->
		<view class="useryonghu">
			<u-navbar :is-back="false" :border-bottom="false" :background="bgc" title-color='#2E4975' title-size='36'
				height='8'></u-navbar>
			<view class="title">
				充电宝
			</view>
			<view class="ditu">
				<view class="dtxs">
					<map class='map' :latitude="latitude" :longitude="longitude" @click="handleMapClick"
						:markers="covers" />
				</view>
				<view class="tubiao">
					<view class="gr" @click="btnindex(1)">
						<image src="../../static/image/a1.png" mode="" style="width: 96rpx;height:98rpx;"></image>
						<!-- 个人中心 -->
					</view>
					<view class="gr" @click="btnindex(2)">
						<image src="../../static/image/a2.png" mode="" style="width: 96rpx;height:102rpx;"></image>
						<!-- 我的订单 -->
					</view>
					<view class="gr" @click="btnindex(3)">
						<image src="../../static/image/a3.png" mode="" style="width: 96rpx;height:98rpx;"></image>
						<!-- 附近门店 -->
					</view>
					<view class="gr" @click="btnindex(4)">
						<image src="../../static/image/a4.png" mode="" style="width: 96rpx;height:94rpx;"></image>
						<!-- 联系客服 -->
					</view>
				</view>
				<view class="guangg">
					<image src="../../static/image/a5.png" mode=""></image>
				</view>
				<view class="saoma">
					<view>
						<image src="../../static/image/sm.png" mode=""></image>扫码充电
					</view>
				</view>
			</view>
		</view>
		<!-- 代理首页显示 -->
	<!-- 	<view class="userdaili" v-if="false">
			<u-navbar :is-back="false" title="首页" :border-bottom="false" :background="bgc" title-color='#000'
				title-size='36' height='36'></u-navbar>

			<view class="zhanghu">
				<view class="zhtitle">
					<text>账户余额（元）</text> <text class="tx" @click="btnnav(9)">提现明细</text>
				</view>
				<view class="zhje">
					<text>1163.916</text> <text class="btntx" @click="btnnav(10)">立即提现</text>
				</view>
				<view class="buc">
					收益提升技巧：加强关注，尽快为缺宝的设备补充充电宝
				</view>
			</view>

			<view class="dttitle">
				订单统计
			</view>
			<view class="ordertongji">
				<view class="orderday">
					<view class="sj">
						<text @click="btnriq(1)" :class="dateindex == 1 ? 'dateactive' : ''">今日</text>
						<text @click="btnriq(2)" :class="dateindex == 2 ? 'dateactive' : ''">昨日</text>
						<text @click="btnriq(3)" :class="dateindex == 3 ? 'dateactive' : ''">近七日</text>
						<text @click="btnriq(4)" :class="dateindex == 4 ? 'dateactive' : ''">近30日</text>
					</view>
				</view>
				<u-picker mode="time" v-model="show" :params="params" @confirm="confirm"></u-picker>
				<view class="date">
					<text @click="btnks(1)">{{selector}}</text> -- <text @click="btnks(2)">{{selectors}}</text>
				</view>
				<view class="shuju">
					<view class="ddje">
						<view class="shu">
							32.5
						</view>
						<view class="sb">
							订单总额
						</view>
					</view>
					<text style="width: 1px;height: 60rpx;background: #979797;margin-top: 24rpx;"></text>
					<view class="ddje">
						<view class="shu">
							9
						</view>
						<view class="sb">
							订单总数
						</view>
					</view>
					<text style="width: 1px;height: 60rpx;background: #979797;margin-top: 24rpx;"></text>
					<view class="ddje">
						<view class="shu">
							0
						</view>
						<view class="sb">
							新增店铺
						</view>
					</view>
					<text style="width: 1px;height: 60rpx;background: #979797;margin-top: 24rpx;"></text>
					<view class="ddje">
						<view class="shu">
							0
						</view>
						<view class="sb">
							新增设备
						</view>
					</view>
				</view>
			</view>

			<view class="dttitle">
				更多功能
			</view>
			<view class="gongneng">
				<view class="icons" @click="btnnav(1)">
					<image src="../../static/image/sbgl.png" mode=""></image>
				</view>
				<view class="icons" @click="btnnav(2)">
					<image src="../../static/image/dpgl.png" mode=""></image>
				</view>
				<view class="icons" @click="btnnav(3)">
					<image src="../../static/image/yygl.png" mode=""></image>
				</view>
				<view class="icons" @click="btnnav(4)">
					<image src="../../static/image/dlgl.png" mode=""></image>
				</view>
				<view class="icons" @click="btnnav(5)">
					<image src="../../static/image/ddgl.png" mode=""></image>
				</view>
				<view class="icons" @click="btnnav(6)">
					<image src="../../static/image/hydp.png" mode=""></image>
				</view>
				<view class="icons" @click="btnnav(7)">
					<image src="../../static/image/sjfx.png" mode=""></image>
				</view>
				<view class="icons" @click="btnnav(8)">
					<image src="../../static/image/a1.png" mode=""></image>
				</view>
			</view>
		</view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				params: {
					year: true,
					month: true,
					day: true,
					hour: false,
					minute: false,
					second: false
				},
				dateindex: 1,

				latitude: 27.109017527965676, // 初始纬度  
				longitude: 120.25287434763894, // 初始经度  
				covers: [], // 覆盖物数组  
			};
		},
		methods: {
			btnindex(num) {
				if (num == 2) {
					uni.navigateTo({
						url: '/pages/myorder/index'
					})
				} else if (num == 3) {
					uni.navigateTo({
						url: '/pages/nearbystores/index'
					})
				} else if (num == 1) {
					uni.navigateTo({
						url: '/pages/personal/index'
					})
				} else {
					uni.navigateTo({
						url: '/pages/abbr/index'
					})
				}
			},
			btnnav(num) {
				if (num == 1) {

				} else if (num == 2) {

				} else if (num == 3) {

				} else if (num == 4) {

				} 
			},

			getMyLocation() {
				const self = this;
				uni.getLocation({
					type: 'wgs84',
					success: (res) => {
						console.log('我的位置：', res);
						self.latitude = res.latitude;
						self.longitude = res.longitude;
						// 创建表示当前位置的覆盖物对象  
						const myLocationCover = {
							latitude: res.latitude,
							longitude: res.longitude,
							width: 20,
							height: 40,
							iconPath: '../../static/image/icon1.png' // 替换为你的图标路径  
						};
						// 将当前位置的覆盖物添加到covers数组中  
						self.covers.push(myLocationCover);
						// 如果需要刷新地图或覆盖物，可以在这里调用相应的方法  
					},
					fail: (err) => {
						console.error('获取位置失败：', err);
					}
				});
			},
			// 假设这个方法用于初始化其他覆盖物（如充电宝图标）  
			initOtherCovers() {
				this.covers = [{
						latitude: 27.1040175279,
						longitude: 120.22287435634,
						width: 40,
						height: 50,
						iconPath: '../../static/image/tb.png'
					},
					{
						latitude: 27.10801752796,
						longitude: 120.26287434763,
						width: 40,
						height: 50,
						iconPath: '../../static/image/tb.png'
					}
				];
			},

			handleMapClick(e) {
				const {
					latitude,
					longitude
				} = e.detail;
				const clickedCover = this.covers.find(cover => {
					// 假设覆盖物是以其中心点为基准的矩形  
					const left = cover.longitude - cover.width / 2;
					const right = cover.longitude + cover.width / 2;
					const top = cover.latitude + cover.height / 2;
					const bottom = cover.latitude - cover.height / 2;

					// 检查点击的经纬度是否在覆盖物的矩形范围内  
					return longitude >= left && longitude <= right && latitude >= bottom && latitude <= top;
				});

				if (clickedCover) {
					uni.showToast({
						title: `点击了店铺`,  
						icon: 'success',
						duration: 2000
					});
				} else {
					uni.showToast({
						title: '点击了地图其他位置',
						icon: 'none',
						duration: 2000
					});
				}
			},
		},
		mounted() {
			this.initOtherCovers(); // 初始化其他覆盖物  
			this.getMyLocation(); // 获取并设置自身位置的覆盖物  
		}
	};
</script>

<style lang="scss">
	/deep/ .map {
		width: 100%;
		height: 100%;
	}

	.dateactive {
		background: #E1F3ED;
	}

	page {
		// background-color: ;
		background: linear-gradient(180deg, #25CE88 0%, rgba(255, 255, 255, 0) 100%);
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.page {
		width: 750rpx;
		padding-left: 34rpx;
		padding-right: 34rpx;
		box-sizing: border-box;
		position: fixed;
		top: 0;
		left: 0;

		// 代理样式
		.userdaili {
			.gongneng {
				width: 680rpx;
				height: 304rpx;
				background: #FFFFFF;
				border-radius: 24rpx 24rpx 24rpx 24rpx;
				padding: 0 50rpx;
				box-sizing: border-box;

				.icons {
					display: inline-block;
					width: 145rpx;
					text-align: center;

					image {
						margin-top: 34rpx;
						width: 50px;
						height: 50px;
					}
				}

			}

			.ordertongji {
				width: 680rpx;
				height: 342rpx;
				background: #FFFFFF;
				border-radius: 24rpx 24rpx 24rpx 24rpx;

				.shuju {
					display: flex;
					justify-content: space-between;
					padding: 0 40rpx;
					box-sizing: border-box;
					margin-top: 24rpx;

					.ddje {
						text-align: center;

						.shu {
							font-weight: 500;
							font-size: 40rpx;
							color: #3D3D3D;
						}

						.sb {
							margin-top: 20rpx;
							font-weight: 500;
							font-size: 20rpx;
							color: #3D3D3D;
						}
					}
				}

				.date {
					padding-left: 80rpx;
					padding-right: 80rpx;
					box-sizing: border-box;
					display: flex;
					justify-content: space-between;
					margin-top: 26rpx;

					text {
						padding: 6rpx 18rpx;
						box-sizing: border-box;
						background: #eee;
						border-radius: 10rpx 10rpx 10rpx 10rpx;
						font-size: 24rpx;
						color: #808080;
					}
				}

				.orderday {
					display: flex;
					justify-content: space-between;
					width: 100%;
					padding: 10rpx 12rpx;
					box-sizing: border-box;

					text {
						margin-right: 10rpx;
						border-radius: 20rpx;
						text-align: center;
						display: inline-block;
						width: 148rpx;
						height: 84rpx;
						// background: #E1F3ED;
						text-align: center;
						line-height: 84rpx;
					}
				}
			}

			.dttitle {
				margin: 36rpx 0;
				font-weight: 500;
				font-size: 36rpx;
				color: #3D3D3D;
			}

			.zhanghu {
				margin-top: 32rpx;
				width: 680rpx;
				height: 264rpx;
				background: #FFFFFF;
				border-radius: 24rpx 24rpx 24rpx 24rpx;
				padding: 36rpx 38rpx;
				box-sizing: border-box;

				.zhtitle {
					display: flex;
					justify-content: space-between;

					.sj {
						display: flex;
						justify-content: space-between;

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

					.tx {
						font-size: 24rpx;
						color: #27D089;
					}
				}

				.zhje {
					margin-top: 20rpx;
					display: flex;
					justify-content: space-between;
					border-bottom: 1px solid #ccc;
					padding-bottom: 20rpx;

					text {
						font-weight: 500;
						font-size: 48rpx;
						color: #3D3D3D;
					}

					.btntx {
						width: 156rpx;
						height: 42rpx;
						background: linear-gradient(270deg, #54DAA1 0%, #19CD82 100%);
						border-radius: 40rpx 40rpx 40rpx 40rpx;
						font-size: 24rpx;
						color: #FFFFFF;
						text-align: center;
						line-height: 42rpx;
						margin-top: 10rpx;
					}
				}

				.buc {
					margin-top: 20rpx;
					font-size: 24rpx;
					color: #979797;
				}
			}
		}




		//样式结束
		.title {
			font-weight: 500;
			font-size: 36rpx;
			color: #3D3D3D;
			line-height: 50rpx;
			text-align: left;
			font-style: normal;
			text-transform: none;
		}

		.guangg {
			image {
				width: 680rpx;
				height: 238rpx;
			}
		}

		.saoma {
			width: 750rpx;
			height: 186rpx;
			background: #FFFFFF;
			position: fixed;
			bottom: 0;
			left: 0;
			padding-top: 38rpx;
			border-radius: 54rpx 54rpx 0 0;

			view {
				text-align: center;
				width: 676rpx;
				height: 102rpx;
				background: linear-gradient(270deg, #54DAA1 0%, #19CD82 100%);
				border-radius: 54rpx 54rpx 54rpx 54rpx;
				font-weight: 500;
				font-size: 40rpx;
				color: #FFFFFF;
				margin: auto;
				line-height: 102rpx;
			}

			image {
				width: 56rpx;
				height: 56rpx;
				vertical-align: middle;
				margin-right: 10rpx;
			}
		}

		.ditu {
			width: 100%;
			height: 964rpx;
			background: #FFFFFF;
			border-radius: 38rpx 38rpx 38rpx 38rpx;
			margin-top: 34rpx;
			padding-top: 16rpx;

			.dtxs {
				width: 642rpx;
				height: 812rpx;
				// background-color: red;
				margin: auto;
			}

			.tubiao {
				display: flex;
				justify-content: space-between;
				padding: 0 50rpx;
				box-sizing: border-box;
				padding-top: 20rpx;
				padding-bottom: 24rpx;

				.gr {
					text-align: center;
					width: 100%;
					font-weight: 400;
					font-size: 24rpx;
					color: #3D3D3D;

					image {
						display: block;
						margin: auto;
						margin-bottom: 14rpx;
					}
				}
			}
		}
	}
</style>