<template>
	<view>
		<view class="page-body">
			<view class="utabs">
				<view style="width: 95%;margin: 0 auto;">
					<u-tabs :list="list" :is-scroll="true" :current="current" @change="change" item-width="140" font-size="24" gutter="20"
					 bar-width="60" active-color="#42b983"></u-tabs>
				</view>
			</view>
			<view class="page-section page-section-gap">
				<map :style="style" scale="3" :latitude="latitude" :longitude="longitude" :markers="covers" :enable-zoom="true"
				 @markertap="markertap" :include-points="covers">
				</map>
				<view class="particulars">
					<view class="search_btn_top">
						已点击设备：
						<span style="padding: 0 20rpx;">{{list[listindex-1].name=="全部"?"未选中":list[listindex-1].name}}</span>
						<span>{{punctuation_id}}</span>
					</view>
					<view class="search_btn_bot">
						<view class="particulars_par" @click="eqinfo">
							查看详情
						</view>
						<view class="particulars_ser" @click="serTFs">
							搜索
						</view>
					</view>
				</view>
				<view class="distri_ser" v-if="serTF">
					<view class="distri_ser_input">
						<input type="number" v-model="device_id" placeholder="请输入设备ID" @confirm="doSearch" />
						<u-icon name="search" size="38rpx" @click="search"></u-icon>
					</view>
					<p class="distri_ser_title">请选择设备类型(点击选择)</p>
					<view class="distri_ser_type">
						<view :class="typeindex==index?'type_items_bor':'type_items'" v-for="item,index in 6" :key="index" @click="typeselect(index)">
							<image :src="icon[item].url" mode="" class="type_items_img"></image>
							<p class="type_items_p">{{list[item].name}}</p>
						</view>
					</view>
					<view class="search_btn">
						<view class="btn_f" @click="btnF">
							取 消
						</view>
						<view class="btn_t" @click="btnT">
							确 定
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				id: 0, // 使用 marker点击事件 需要填写id
				title: 'map',
				latitude: 39.909,
				longitude: 116.39742,
				covers: [],
				list: [{
					name: "全部"
				}, {
					name: "杀虫灯"
				}, {
					name: "测报灯"
				}, {
					name: "性诱测报"
				}, {
					name: "环境检测"
				}, {
					name: "监控设备"
				}, {
					name: "孢子仪"
				}],
				current: 0,
				icon: [{
						id: '', //全部
						url: "../../static/image/distribution/7610e3983eb33ed5b9ad72ebdfc8ed2.png"
					},
					{
						id: 2, //杀虫灯
						url: "../../static/image/distribution/1bd535eb7dbb0809940030d40c64b4c.png"
					},
					{
						id: 3, //测报灯
						url: "../../static/image/distribution/0b551e50be351dbc14f0dd6470e3443.png"
					},
					{
						id: 4, //性诱测报
						url: "../../static/image/distribution/e19abf8bb442aefd6208f9c4687b57d.png"
					},
					{
						id: 5, //环境检测
						url: "../../static/image/distribution/8325b1b6079456ce43f952ce13d2919.png"
					},
					{
						id: 6, //监控设备
						url: "../../static/image/distribution/2eb9e550709430a1bd8178568c14785.png"
					},
					{
						id: 7, //孢子仪
						url: "../../static/image/distribution/54a96e2b0ad4efeecbd4a7b5e6deda3.png"
					},
				],
				type: '', //设备类型
				typeindex: null, //设备选择
				device_id: '', //设备号
				serTF: false, //设备搜索显示隐藏
				punctuationTF: false, //判断是否以点击标点
				punctuation_id: "", //点击标点的id
				punctuation_did: '',
				punctuation_type: '',
				style: {
					width: "100%",
					height: "85%",
				},
				listindex:1,//以选择设备名称
			}
		},
		onLoad() {
			this.history()
		},
		methods: {
			async history() { //获取分布位置
				const res = await this.$myRequest({
					url: '/api/api_gateway?method=home.homes.equip_map_location',
					data: {
						equip_type: this.type,
						device_id: this.device_id
					}
				})
				console.log(res)
				this.covers = []
				for (var i = 0; i < res.length; i++) {
					var obj = {}
					obj.latitude = res[i].lat
					obj.longitude = res[i].lng
					obj.id = [res[i].device_id, res[i].d_id, res[i].device_type_id]
					obj.title = res[i].device_name || res[i].device_id
					// obj.width = 25
					for (var j = 0; j < this.icon.length; j++) {
						if (res[i].device_type_id == this.icon[j].id) {
							obj.iconPath = this.icon[j].url
						}
					}
					this.covers.push(obj)
				}
				console.log(res)
			},
			change(index) {
				this.current = index
				if (index == 0) {
					this.type = ''
				} else {
					this.type = index + 1
				}
				this.history()
			},
			markertap(e) {
				console.log(e)
				this.punctuation_id = e.detail.markerId[0]
				this.punctuation_did = e.detail.markerId[1]
				this.punctuation_type = e.detail.markerId[2]
				this.listindex = e.detail.markerId[2]
			},
			typeselect(index) { //选择设备类型
				this.typeindex = index
				this.type = this.icon[index + 1].id
				console.log(this.type)
			},
			doSearch() { //按下回车键
				this.search()
			},
			search() { //点击搜索
				// this.history()
				if (this.type == '') {
					uni.showToast({
						title: '请选择设备类型',
						duration: 2000,
						icon: "none"
					});
				} else {
					this.history()
					this.serTF = !this.serTF
				}
			},
			serTFs() {
				this.serTF = !this.serTF
				this.style.height = "65%"
			},
			btnF() { //取消
				this.serTF = !this.serTF
				this.style.height = "85%"
			},
			btnT() { //确定
				this.search()
			},
			eqinfo() { //设备信息
				if (this.punctuation_id == '') {
					uni.showToast({
						title: '请点击需查看的设备',
						duration: 2000,
						icon: "none"
					});
				} else {
					switch (this.punctuation_type) {
						case 2:
							uni.navigateTo({
								url: "../prevention/ucharts?d_id=" + this.punctuation_did + "&imei=" + this.punctuation_id
							})
							break;
						case 3:
							uni.navigateTo({
								url: "../cb/cbd/equip-set/historyfile?d_id=" + this.punctuation_did + "&device_id=" + this.punctuation_id
							})
							break;
						case 4:
							uni.navigateTo({
								url: "../cb/xy/equip-set/xyhistoryile?d_id=" + this.punctuation_did + "&device_id=" + this.punctuation_id
							})
							break;
						case 5:
							uni.navigateTo({
								url: "../environment/history?d_id=" + this.punctuation_did + "&device_id=" + this.punctuation_id
							})
							break;
						case 6:
							// uni.navigateTo({
							// 	url: "../prevention/ucharts?d_id=" + this.punctuation_did + "&device_id=" + this.punctuation_id
							// })
							break;
						case 7:
							uni.navigateTo({
								url: "../cb/bzy/equip-set/bzyhistoryile?d_id=" + this.punctuation_did + "&device_id=" + this.punctuation_id
							})
							break;
					}

				}
			}
		}
	}
</script>

<style lang="scss">
	.utabs {
		width: 100%;
		position: fixed;
		top: 0px;
		z-index: 100;
		background-color: #FFFFFF;
	}

	.page-section {
		margin-top: 44px;
		height: 94vh;
	}
	.particulars {
		width: 100%;
		height: 160rpx;
		position: absolute;
		bottom: 0;
		.search_btn_top {
			width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			font-size: 32rpx;
			padding-left: 30rpx;
			box-sizing: border-box;
		}
		.search_btn_bot {
			width: 100%;
			display: flex;
		}
		.particulars_par {
			background-color: #F1F1F1;
			text-align: center;
			width: 50%;
			height: 80rpx;
			line-height: 80rpx;
			font-size: 28rpx;
		}

		.particulars_ser {
			background-color: #57C87B;
			text-align: center;
			width: 50%;
			height: 80rpx;
			line-height: 80rpx;
			font-size: 28rpx;
			color: #FFFFFF;
		}
	}

	.distri_ser {
		position: absolute;
		bottom: 17rpx;
		right: 0px;
		width: 100%;
		height: 400rpx;
		background-color: #FFFFFF;

		.distri_ser_input {
			width: 90%;
			margin: 20rpx auto;
			display: flex;
			background-color: #F1F1F1;
			height: 60rpx;
			border-radius: 30rpx;
			padding: 10rpx 20rpx;
			box-sizing: border-box;

			input {
				width: 90%;
				font-size: 28rpx;
				margin-right: 20rpx;
			}
		}

		.distri_ser_title {
			width: 90%;
			margin: 0 auto;
			padding-left: 20rpx;
			border-left: 4rpx solid #57C87B;
			font-size: 28rpx;
		}

		.distri_ser_type {
			width: 90%;
			margin: 20rpx auto;
			display: flex;
			justify-content: space-around;

			.type_items {
				height: 120rpx;
				width: 120rpx;
				padding: 20rpx 0;
			}

			.type_items_bor {
				height: 120rpx;
				width: 120rpx;
				border: 2rpx solid #57C87B;
				padding: 20rpx 0;
			}

			.type_items_img {
				width: 70rpx;
				height: 70rpx;
				margin-left: 20rpx;
			}

			.type_items_p {
				font-size: 24rpx;
				text-align: center;
			}
		}
	}

	.search_btn {
		width: 100%;
		display: flex;

		.btn_f,
		.btn_t {
			width: 50%;
			text-align: center;
			height: 80rpx;
			line-height: 80rpx;
			font-size: 28rpx;
		}

		.btn_f {
			background-color: #F1F1F1;
		}

		.btn_t {
			background-color: #57C87B;
			color: #FFFFFF;
		}
	}
</style>

