<template>
	<view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
		<cus-header title='设备异常'></cus-header>
		<div class="top" @tap="placeShow = true;">
			<div class="left">
				<image :src="imgBase+'inspection/record_location.png'"></image>
				<text>{{location}}</text>
			</div>
			<div class="right">
				<u-icon name="arrow-right" color="#FFFFFF" size="32"></u-icon>
			</div>
		</div>
		<div class="title">共有<span>{{list.length}}</span>条记录</div>
		<div class="boxs" v-if="list.length">
			<div class="box" v-for="(item,index) in list" :key="index">
				<div class="place">{{item.deviceName||''}}</div>
				<!-- <div class="pre">安装位置<span>{{item.time}}</span></div> -->
				<div class="pre">设备编号<span>{{item.deviceId||''}}</span></div>
				<div class="pre">告警原因<span class="red">{{item.alertConfigName||''}}</span></div>
				<div class="pre">告警内容<span>{{item.content||''}}</span></div>
				<div class="pre">告警时间<span>{{item.alertTime||''}}</span></div>
			</div>
		</div>
		<template v-else>
			<page-empty :height="'calc(100vh - 110px)'"></page-empty>
		</template>
		<u-picker :show="placeShow" :columns="placeColumns" keyName="orgName" @cancel="placeShow=false" @change="changeHandler" @confirm="placeConfirm" ref="uPicker"></u-picker>
	</view>
</template>

<script>
	import pageEmpty from '@/components/pageEmpty/index.vue'
	export default {
		components:{
			pageEmpty
		},
		data(){
			return {
				location:'',
				placeShow:false,
				placeColumns:[],
                placeColumnData: [],
				isOver:false,
				params:{
					buildingId:'',
					storeyId:''
				},
				list:[],
			}
		},
		async onLoad() {
			this.getFloorInfo();
			this.getList();
		},
		methods:{
			getFloorInfo(){
				this.$api.get('/control/getOrgStructureTree/').then(res=>{
					if(res.data.code===0){
						this.location = res.data.data[0].orgName;
						this.placeColumns = [
							res.data.data[0].childrenList,
							res.data.data[0].childrenList[0].childrenList
						]
						let allfloor = [];
						for (let i = 0; i < res.data.data[0].childrenList.length; i++) {
							allfloor.push(res.data.data[0].childrenList[i].childrenList)
						}
						this.placeColumnData = allfloor;
					}else this.$showToast(res.data.msg)
				})
			},
			getList(){
				this.$api.get('/home/actualAlertList',this.params).then(res=>{
					if(res.data.code===0){
						this.list = res.data.data;
					}else this.$showModal(res.data.msg)
				});
			},
            changeHandler(e) {
                const {
                    columnIndex,
                    value,
                    values, // values为当前变化列的数组内容
                    index,
					// 微信小程序无法将picker实例传出来，只能通过ref操作
                    picker = this.$refs.uPicker
                } = e
                // 当第一列值发生变化时，变化第二列(后一列)对应的选项
                if (columnIndex === 0) {
                    // picker为选择器this实例，变化第二列对应的选项
                    picker.setColumnValues(1, this.placeColumnData[index])
                }
            },
			placeConfirm(e){
				this.params.buildingId = e.value[0].orgId;
				this.params.storeyId = e.value[1].orgId;
				this.placeShow = false;
				this.init()
			},
			init(){
				this.params.page = 1;
				this.isOver = false;
				this.list = [];
				this.getList();
			}
		}
	}
</script>

<style scoped lang="less">
	.page{
		padding-bottom: 20rpx;
		background: #F4F8FB;
		box-sizing: border-box;
		.top{
			width: 100%;
			height: 102rpx;
			background: #198CFF;
			padding: 0 30rpx;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.left{
				display: flex;
				align-items: center;
				image{
					width: 36rpx;
					height: 36rpx;
				}
				text{
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 30rpx;
					color: #FFFFFF;
					line-height: 42rpx;
					margin-left: 10rpx;
				}
			}
		}
		.filtrate{
			width: 100%;
			height: 90rpx;
			background: #FFFFFF;
			display: flex;
			.pre{
				width: calc(100% / 3);
				height: 100%;
				display: flex;
				align-items: center;
				justify-content: center;
				text{
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 28rpx;
					color: #4E5969;
					line-height: 40rpx;
					margin-right: 12rpx;
				}
			}
		}
		
		.title{
			font-family: PingFang-SC, PingFang-SC;
			font-weight: bold;
			font-size: 32rpx;
			color: #1D2129;
			line-height: 32rpx;
			margin-top: 36rpx;
			padding-left: 24rpx;
			span{
				color: #198CFF;
				margin: 0 10rpx;
			}
		}
		
		.boxs{
			width: 100%;
			padding: 0 24rpx;
			box-sizing: border-box;
			margin-top: 16rpx;
			overflow: hidden;
			.box{
				margin-top: 20rpx;
				background: #FFFFFF;
				border-radius: 16rpx;
				padding: 36rpx 24rpx;
				.place{
					font-family: PingFang-SC, PingFang-SC;
					font-weight: bold;
					font-size: 32rpx;
					color: #1D2129;
					line-height: 36rpx;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
				.pre{
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #86909C;
					line-height: 24rpx;
					margin-top: 26rpx;
					span{
						font-family: PingFangSC, PingFang SC;
						font-weight: 400;
						font-size: 26rpx;
						color: #1D2129;
						line-height: 26rpx;
						margin-left: 20rpx;
						&.red{
							color: #F95050;
						}
					}
				}
			}
		}
	}
</style>