<template>
	<!-- 可视监控 -->
	<view class="camera-panel">
		<view class="camera-list">
			<!-- 监控列表 -->
			<block v-for="(item,index) in cameraList" :key="index">
				<view class="camera-item" @click="openCameraDetails(item.device_id)">
					<image class="pic" mode="aspectFill" :src="item.jk_live_img">
					</image>
					<view class="row-between p-10">
						<text class="text">{{item.device_id}}</text>
						<text class="tips" :calss="item.status?'':'close'"></text>
					</view>
				</view>
			</block>
			<!-- 监控列表end -->
		</view>
		<ui-empty v-if="cameraList.length==0"></ui-empty>
	</view>
</template>

<script>
	import {
		getCameraList
	} from '@/api/camera.js'
	export default {
		data() {
			return {
				params: {
					page: 1,
					page_size: 10,
					// device_id:
				},
				// 监控列表
				cameraList: [],
				total: 0, // 设备总数
			};
		},
		async onLoad() {
			await this.$onLaunched;
			this.getCameraList();
		},
		onReachBottom(e) {
			if (this.cameraList.length >= this.total) {
				return;
			}
			this.params.page += 1;
			this.getCameraList();
		},
		methods: {
			// 获取监控列表
			async getCameraList() {
				this.$api.loading('加载中...');
				const {
					data,
					counts
				} = await getCameraList(this.params);
				this.$api.hide();
				this.cameraList = [...this.cameraList, ...data];
				this.total = counts;
			},
			/**
			 * 打开监控详情
			 * @param {string} id 设备id
			 */
			openCameraDetails(id) {
				uni.navigateTo({
					url: `details?id=${id}`
				})
			}
		}
	}
</script>

<style lang="scss">
	// 可视监控面板
	.camera-panel {

		padding: 24rpx;
		margin-top: 24rpx;
		background-color: #fff;
	}

	.camera-list {
		display: flex;
		flex-wrap: wrap;
	}

	// 可视列表项
	.camera-item {
		width: 336rpx;

		margin-right: 28rpx;
		margin-bottom: 24rpx;

		border-radius: 12rpx;
		border: 1rpx solid #F1F1F1;

		&:nth-child(2n) {
			margin-right: 0;
		}

		.pic {
			display: block;
			width: 336rpx;
			height: 255rpx;

			border-radius: 4rpx;
		}

		.text {
			font-size: 20rpx;
			color: #666666;
		}

		.tips {
			width: 24rpx;
			height: 24rpx;
			background: #07F546;
			border-radius: 100%;

			&.close {
				background: #e93f27;
			}
		}
	}
</style>
