<template>
	<view>
		<view class="tabalr">
			<u-navbar autoBack placeholder bgColor="transparent">
				<view class="navSlot" slot="left">
					<u-icon name="arrow-left" size="19"></u-icon>
					<text class="title">定位</text>
				</view>
			</u-navbar>
			<!-- <view class="tab">
				<view>全部</view>
				<view>巡查</view>
				<view>预警</view>
				<view>异常</view>
			</view> -->

		</view>
		<view class="status">
			<view class="devicesNormal">
				<!-- <view class="status_bule">
				</view> -->
				<view class="statusTitle">正常({{no1}})</view>
			</view>

			<view class="devicesNormal">
				<!-- <view class="status_bule">
				</view> -->
				<view class="statusTitle">待补纸({{no3}})</view>
			</view>
			<view class="devicesNormal">
				<!-- <view class="status_bule">
				</view> -->
				<view class="statusTitle">异常({{no4}})</view>
			</view>
			<view class="devicesNormal">
				<!-- <view class="status_bule">
				</view> -->
				<view class="statusTitle">离线({{no2}})</view>
			</view>
		</view>
		<view class="map-container">
			<map style="width: 100%; height: 600rpx" :show-location='true' ref="map" id="map" :latitude="latitude"
				:longitude="longitude" :customCallout="callout" :markers="marker" :scale="scale" @markertap="markertap"
				@callouttap='callouttap'>
			</map>
		</view>
		<view class="upopup">
			<!-- <text class="border"></text> -->
			<view class="listview">
				<view class="liitem" v-for="(item,index) in toilets" :key="index">
					<view class="title">
						<view>{{item.region}}-{{item.toiletId}}公厕</view>
						<text @click="tourl(item)">巡查</text>
					</view>
					<view class="conttext">
						<view class="account">
							<view class="clock">
								<u-icon name="account"></u-icon>
								<text>待巡查时间：{{item.setInspectiontime}}</text>
							</view>
							<view class="clock">
								<u-icon name="clock"></u-icon>
								<text>巡查人员：{{item.setInspectors}}</text>
							</view>
						</view>
						<view class="gopos">
							<image @click="gopos(item.locationlat,item.locationlong)" src="../../static/hoem/gopos.png"
								mode=""></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- <view class="border_btm" @click="open">
			<text></text>
		</view> -->
		<u-popup :show="show" @close="close" @open="open" mode="bottom" :round="10">
			<view class="upopup">
				<text class="border"></text>
				<view class="listview">
					<view class="liitem" v-for="(item,index) in toilets" :key="index">
						<view class="title">
							<view>{{item.region}}-{{item.toiletId}}公厕</view>
							<text @click="tourl(item)">巡查</text>
						</view>
						<view class="conttext">
							<view class="account">
								<view class="clock">
									<u-icon name="account"></u-icon>
									<text>待巡查时间：{{item.setInspectiontime}}</text>
								</view>
								<view class="clock">
									<u-icon name="clock"></u-icon>
									<text>巡查人员：{{item.setInspectors}}</text>
								</view>
							</view>
							<view class="gopos">
								<image @click="gopos(item.locationlat,item.locationlong)"
									src="../../static/hoem/gopos.png" mode=""></image>
							</view>
						</view>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import index from '../../uni_modules/uview-ui';

	export default {
		data() {
			return {
				no1: 0,
				no2: 0,
				no3: 0,
				no4: 0,
				show: false,
				callout: {
					anchorY: 0,
					anchorX: 0,
					display: 'BYCLICK'
				},
				latitude: 34.721948, //纬度
				longitude: 113.614955, //经度
				scale: 17, //缩放级别
				toilets: [],
				marker: [],
			}
		},
		onReady() {

		},

		onLoad() {

		},
		onShow() {
			this.getLocation();
			this.getalltop();
		},
		computed: {},
		methods: {
			gopos(locationlat, locationlong) {
				console.log(locationlat, locationlong)
				// uni.openLocation({
				// 	latitude: locationlat,
				// 	longitude: locationlong,
				// 	success: function() {
				// 		console.log('success');
				// 	}
				// }); 
				//moveToLocation将地图中心移动到当前定位点，需要配合map组件的show-location使用
				uni.createMapContext("map", this).moveToLocation({
					latitude: locationlat,
					longitude: locationlong,
				});
				this.scale = 20
			},
			tourl(item) {
				uni.navigateTo({
					url: '/pages/map/device?id=' + item.id
				})
			},
			getalltop() {
				const params = {
					url: '/sun/mqtt/alltop',
					data: {

					},
				}
				this.$request(params).then(res => {
					console.log(res.rows)
					this.toilets = res.rows;
					this.no1 = 0;
					this.no2 = 0;
					this.no3 = 0;
					this.no4 = 0;
					// res.rows.forEach((item, index) => {
					// 	console.log(item)
					// 	if (item.allEquipment.length) {
					// 		item.allEquipment.forEach((iotem, iondex) => {
					// 			if (iotem.notificationStatus = 0) {
					// 				this.no1++
					// 			} else if (iotem.notificationStatus = 1) {
					// 				this.no2++
					// 			} else if (iotem.notificationStatus = 2) {
					// 				this.no3++
					// 			} else if (iotem.notificationStatus = 3) {
					// 				this.no4++
					// 			}
					// 		})
					// 	}
					// })
					let markerList = [];
					res.rows.map((item, i) => {
						markerList.push({
							id: i,
							latitude: item.locationlat,
							longitude: item.locationlong,
							iconPath: '../../static/image/posdata.png',
							width: 40,
							height: 40,
							callout: { //自定义标记点上方的气泡窗口 点击有效  
								content: item.region, //文本
								color: '#ffffff', //文字颜色
								fontSize: 15, //文本大小
								borderRadius: 10, //边框圆角
								padding: '10',
								bgColor: '#269EFB', //背景颜色
								display: 'ALWAYS', //常显
							},
						});
					})

					this.marker = markerList;
					console.log('marker', markerList.length);
				})
			},
			open() {
				this.show = true;
				// console.log('open');
			},
			close() {
				this.show = false;
				// console.log('close');
			},
			getLocation() {
				uni.getLocation({
					type: 'gcj02',
					success: res => {
						this.latitude = res.latitude
						this.longitude = res.longitude
						console.log('当前定位', res);
					}
				});
			},
			refresh() {
				this.getLocation()
				console.log('刷新');
				//后期这里可加入调用请求接口的方法，用来实现刷新
			},
			//定位
			onControltap() {
				this.getLocation()
				uni.createMapContext("map", this).moveToLocation({ //moveToLocation将地图中心移动到当前定位点，需要配合map组件的show-location使用
					latitude: this.latitude,
					longitude: this.longitude,
				});
				console.log('定位');
			},
			//地图点击事件
			markertap(e) {

			},
			//地图点击事件
			callouttap(e) {

			}

		}
	}
</script>

<style scoped lang="scss">
	/deep/.u-popup {
		position: relative;
		z-index: 99999999;
	}

	.upopup {
		padding-top: 24rpx;

		.border {
			margin: 0 auto;
			width: 173rpx;
			height: 7rpx;
			background: #F1F1F1;
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			margin-bottom: 34rpx;
			display: block;
		}

		.listview {
			height: 800rpx;
			padding: 0 44rpx;
			overflow-y: scroll;

			.liitem {
				width: 662rpx;
				background: linear-gradient(90deg, #FDEEEF 0%, #FFFFFF 100%);
				box-shadow: 0rpx 0rpx 6rpx 1rpx #FFC6C7;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				margin-bottom: 20rpx;
				padding: 20rpx;
				padding-top: 16rpx;
				padding-bottom: 0;
				box-sizing: border-box;

				.conttext {
					display: flex;
					justify-content: space-between;
					align-items: center;

					.account {
						.clock {
							display: flex;
							margin-bottom: 20rpx;

							text {
								font-family: Microsoft YaHei, Microsoft YaHei;
								font-weight: 400;
								font-size: 24rpx;
								color: #666666;
								margin-left: 10rpx;
							}
						}
					}

					.gopos {
						image {
							width: 52rpx;
							height: 52rpx;
						}
					}
				}

				.title {
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-bottom: 20rpx;

					view {
						font-family: Microsoft YaHei, Microsoft YaHei;
						font-weight: bold;
						font-size: 28rpx;
						color: #333333;
					}

					text {
						width: 84rpx;
						height: 37rpx;
						line-height: 37rpx;
						background: linear-gradient(90deg, #FCD4D2 0%, #FB262A 100%);
						box-shadow: 0rpx 3rpx 6rpx 1rpx #FFC5C5;
						border-radius: 8rpx 8rpx 8rpx 8rpx;
						font-family: Microsoft YaHei, Microsoft YaHei;
						font-weight: 400;
						font-size: 24rpx;
						color: #FFFFFF;
						text-align: center;
					}
				}
			}

		}
	}

	.border_btm {
		width: 100%;
		height: 40rpx;
		padding-top: 16rpx;
		box-sizing: border-box;

		text {
			width: 173rpx;
			height: 8rpx;
			background: #F1F1F1;
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			display: block;
			margin: 0 auto;
		}
	}

	.status {
		background: white;
		padding: 30rpx;
		display: flex;
		justify-content: space-between;

		.devicesNormal {
			display: flex;
			padding: 10rpx;
			align-items: center;

			.statusTitle {
				padding-left: 10rpx;
				font-size: 24rpx;
				color: #999999;
			}

			.status_bule {
				background: #269EFB;
				width: 22rpx;
				height: 22rpx;
			}
		}

	}

	.tab {
		display: flex;
		justify-content: space-between;
		padding: 22rpx 44rpx 22rpx 44rpx;
	}

	.tabalr {
		background: linear-gradient(91deg, #FDEDEE 0%, #FFFFFF 100%);
		display: block;
		font-size: 28rpx;
	}

	.map-container {
		position: relative;
		overflow: hidden;
		border-radius: 50rpx 50rpx 0 0;
		position: relative;
		z-index: 9999999;

		.cover-view {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			/* width: 80rpx;
			height: 160rpx; */
			padding: 42rpx 22rpx;
			color: #4F575F;
			font-weight: 400;
			background-color: #fff;
			background-size: 120rpx 120rpx;
			background-position: center center;
			position: absolute;
			top: 150rpx;
			right: 32rpx;
			border-radius: 15rpx;


		}

		.cover-image {
			display: inline-block;
			width: 50rpx;
			height: 50rpx;

		}
	}
</style>