<template>
	<view>
		<view class="status_bar"></view>
		<view class="" style="position: relative;top: 44px;">
			<view style="position: fixed;z-index: 100;">
				<uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回" title="环境监测系统" right-icon="search" @clickRight="clickRight"
				 size="16"></uni-nav-bar>
			</view>
			<image :src="'http://www.hnyfwlw.com:8006/bigdata_app'+'/image/environment/1.png'" mode="" class="image"></image>
			<view class="prevents">
				<view class="prevents_item" v-for="item,index in eqlistdata" :key="index" @click="eqdetails(item)">
					<image :src="item.is_online==1?'http://www.hnyfwlw.com:8006/bigdata_app/image/prevention/6.png':'http://www.hnyfwlw.com:8006/bigdata_app/image/prevention/7.png'" mode=""
					 class="prevents_item_img"></image>
					<view class="prevents_item_top">
						<p>设备名称：{{item.equip_name==""?"无":item.equip_name}}</p>
						<p :class="item.is_online==1?'green':'red'" v-text="item.is_online==1?'在线':'离线'"></p>
					</view>
					<view class="prevents_item_bot">
						<p>设备 ID：{{item.equip_id}}</p>
						<p>最新上报时间：{{item.uptime|timeFormat()}}</p>
					</view>
				</view>
			</view>
		</view>
		<view class="top">
			<view class="backtop" @click="top" v-if="isTop">
				<image src="../../static/images/1.png" mode="" class="img0"></image>
			</view>
			<view class="more">
				<view class="box" @click="online" v-show="filtrateTF">
					<p>在线</p>
				</view>
				<view class="box" @click="offline" v-show="filtrateTF">
					<p>离线</p>
				</view>
				<view class="box" @click="complete" v-show="filtrateTF">
					<p>全部</p>
				</view>
				<view @click="filtrate">
					<image src="../../static/images/b0bcdb0e3fe8690520f743aa8303bf2.png" mode="" class="img1"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page: 1,
				size: 10,
				eqlistdata: [],
				isTop:false,
				filtrateTF:false,
				device_status:""
			}
		},
		methods: {
			async eqlist() { //设备列表
				const res = await this.$myRequest({
					url: '/api/api_gateway?method=weather.weather.qxz_page',
					data: {
						page: this.page,
						device_status:this.device_status
					}
				})
				this.eqlistdata = this.eqlistdata.concat(res.ids)
				console.log(res.ids)
			},
			clickRight() {
				uni.navigateTo({
					url: "./search"
				})
			},
			clickLeft() {
				uni.switchTab({
					url: "../index/index"
				})
			},
			eqdetails(data) {
				uni.navigateTo({
					url: "./equipment?shebei=" + JSON.stringify(data)
				})
			},
			filtrate(){
				this.filtrateTF = !this.filtrateTF
			},
			top() {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 500
				})
			},
			online(){
				this.eqlistdata=[]
				this.page = 1
				this.device_status = 1
				this.eqlist()
				this.filtrateTF = !this.filtrateTF
			},
			offline(){
				this.eqlistdata=[]
				this.page = 1
				this.device_status = 0
				this.eqlist()
				this.filtrateTF = !this.filtrateTF
			},
			complete(){
				this.eqlistdata=[]
				this.page = 1
				this.device_status = ""
				this.eqlist()
				this.filtrateTF = !this.filtrateTF
			}
		},
		onLoad() {
			this.eqlist()
		},
		onReachBottom() {
			this.page++
			this.eqlist()
		},
		onPageScroll(e) { //nvue暂不支持滚动监听，可用bindingx代替
			if (e.scrollTop > 200) { //距离大于200时显示
				this.isTop = true
			} else { //距离小于200时隐藏
				this.isTop = false
			}
		},
	}
</script>

<style lang="scss">
	/deep/.uni-icons {
		font-size: 40rpx !important;
	}

	.image {
		position: fixed;
		top: 83px;
		width: 100%;
		height: 160rpx;
		z-index: 555;
	}

	.prevents {
		width: 100%;
		position: absolute;
		top: 140px;

		.prevents_item {
			width: 95%;
			margin: 0 auto 30rpx;
			border-radius: 10rpx;
			box-shadow: 0 0 10rpx #bcb9ca;
			padding: 20rpx 40rpx 20rpx 80rpx;
			box-sizing: border-box;
			position: relative;

			.prevents_item_img {
				width: 30rpx;
				height: 50rpx;
				position: absolute;
				top: -4rpx;
				left: 30rpx;
			}

			.prevents_item_top {
				display: flex;
				justify-content: space-between;
				height: 60rpx;
				border-bottom: 2rpx solid #F4F4F4;
				line-height: 60rpx;
				font-size: 26rpx;

				.red {
					color: #ff0000;
				}

				.green {
					color: #7DBB91;
				}
			}

			.prevents_item_bot {
				margin-top: 20rpx;
				font-size: 26rpx;
				color: #BDBDBD;
			}
		}
	}
	.top {
		position: fixed;
		right: 10px;
		bottom: 40px;
		z-index: 100;
		image {
			width: 100rpx;
			height: 100rpx;
		}
		.backtop{
			display: flex;
			justify-content: flex-end;
			margin-bottom: 10rpx;
		}
		.more{
			display: flex;
		}
		.box{
			width: 80rpx;
			height: 80rpx;
			background-color: rgba(161,161,161,0.45);
			border-radius: 50%;
			text-align: center;
			line-height: 80rpx;
			box-sizing: border-box;
			margin: 14rpx 10rpx 0 0;
			color: #fff;
		}
	}
</style>
