<template>
	<view class="container">
		<view class="padding-wrap">
			<view class="message-box">
				<view class="message-image">
					<image class="image" src="@/static/msg-icon.png" mode="widthFix"></image>
				</view>
				<view class="message-info">
					<view class="message-title">
						{{detailInfo.content}}
					</view>
					<view class="message-des">
						{{detailInfo.reportTime}} <uni-icons type="location-filled" size="18" color="#F5343E" @click="mapView"/>
					</view>
					<uni-forms label-width="200upx" style="margin-top: 43upx;">
						<uni-forms-item label="设备名称："><text class="form-text">{{detailInfo.deviceId}}</text></uni-forms-item>
						<uni-forms-item label="设备编号："><text class="form-text">{{detailInfo.deviceName}}</text></uni-forms-item>
						<uni-forms-item label="设备类型："><text class="form-text">{{detailInfo.productName}}</text></uni-forms-item>
						<uni-forms-item label="安装位置："><text class="form-text">{{detailInfo.buildId}}号楼{{detailInfo.floorNo}}层</text></uni-forms-item>
						<uni-forms-item label="经度："><text class="form-text">{{detailInfo.longidute}}</text></uni-forms-item>
						<uni-forms-item label="纬度："><text class="form-text">{{detailInfo.latidute}}</text></uni-forms-item>
					</uni-forms>
				</view>
			</view>
		</view>
		<!-- 视频联动 -->
		<view class="video-box">
			<view class="video-box-title">视频联动</view>
			<view v-for="item in videoList" :key="item.id" class="video-item" @click="goVideo">
				<view class="name">{{item.name}}</view>
				<view class="act"><uni-icons type="videocam-filled" size="18"/></view>
			</view>
			<view v-if="videoList.length == 0">没有查询到关联摄像头...</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				detailInfo: {},
				videoList: []
			}
		},
		onLoad(options) {
			this.detailInfo = options.data ? JSON.parse(options.data) : {};
			this.queryVideo(this.detailInfo.deviceId);
		},
		methods: {
			//报警位置地图定位
			mapView() {
				uni.navigateTo({
					url: '/pages/map/map?floorNo=' + this.detailInfo.floorNo + '&lat=' + this.detailInfo.latidute + '&lng=' + this.detailInfo.longidute
				})
			},
			//查询报警点摄像头
			queryVideo(deviceId) {
				let token = uni.getStorageSync('bizToken');
				if(token == undefined || !token) {
					uni.request({
						url: 'http://182.139.182.190:60032/prod-api/api/Login',
						method: 'POST',
						data: { appKey: 'Arf7bd4f26', appSecret: 'kb207044c8' },
						success: (res) => {
							if(res.data.code == 0) {
								uni.setStorageSync('bizToken', res.data.data.token);
								this.queryVideo(deviceId);
							}
						}
					})
				} else {
					uni.request({
						url: 'http://182.139.182.190:60032/prod-api/api/bizDevice/list?params[pmac]=' + deviceId,
						method: 'GET',
						header: {
							Authorization: token
						},
						success: (res) => {
							console.log(res)
							if(res.data.code == 401){
								uni.removeStorageSync('bizToken');
								this.queryVideo(deviceId);
							}else{
								this.videoList = res.data.rows;
							}
						}
					})
				}
			},
			goVideo() {
				uni.navigateTo({
					url: '/pages/videoPlayer/index'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page,
	.container {
		min-height: 100vh;
		background-color: #FFFFFF;

		/deep/.uni-forms-item {
			display: flex;
			align-items: center;
			margin-bottom: 15upx;
		}

		/deep/.uni-forms-item__label {
			color: #90959D;
			font-size: 28upx;
			font-family: PingFang SC-Regular, PingFang SC;
			font-weight: 400;
		}

		.form-text {
			color: #031945;
			line-height: 40upx;
			font-size: 28upx;
			font-family: PingFang SC-Regular, PingFang SC;
			font-weight: 400;
		}
	}

	.padding-wrap {
		padding: 30upx;
	}

	.message-box {
		display: flex;
		flex-direction: row;
		margin-bottom: 44upx;

		.message-image {
			display: block;
			margin-right: 20upx;

			.image {
				width: 88upx;
				height: 88upx;
			}
		}

		.message-info {
			flex: 1;
			color: #031945;
			font-size: 28upx;
			line-height: 40upx;
			font-family: PingFang SC-Bold, PingFang SC;
			font-weight: bold;

			.message-title {
				white-space: nowrap;
				text-overflow: ellipsis;
			}

			.message-des {
				color: #90959D;
				white-space: nowrap;
				text-overflow: ellipsis;
			}
		}
	}

	// 视频联动
	.video-box {
		border-top: 14upx solid #F4F8FB;
		padding: 30upx;

		.video-box-title {
			color: #031945;
			font-size: 28upx;
			line-height: 40upx;
			font-family: PingFang SC-Bold, PingFang SC;
			font-weight: bold;
			margin-bottom: 30upx;
		}

		.video-item {
			display: flex;
			align-items: center;
			font-size: 22upx;
			line-height: 40upx;
			.name {
				display: inline-block;
				width: 80%;
				word-break: break-all;
				text-overflow: ellipsis;
				overflow: hidden;
			}
			.act {
				float: right;
				margin-left: 20upx;
			}
		}
	}
</style>