<template>
	<!-- 测报灯预警信息 -->
	<view>
		<block v-for="(item,index) in warningList" :key="index">
			<view class="ui-card warn-item">
				<view class="title">{{item.ekey}}</view>
				<view class="subtitle">设备ID：{{item.device_id}}</view>
				<view class="paragraph">
					<text  v-for="(val,key,i) in item.warning_content" :key="i">
						{{key+':'+val}},
					</text>
				</view>
				<text class="time">{{item.upltime | timeFrom}}</text>
			</view>
		</block>
		<ui-empty v-if="warningList.length==0" text="暂无预警信息"></ui-empty>
	</view>
</template>

<script>
	import {
		getPestWarningList
	} from '@/api/warning.js'
	export default {
		data() {
			return {
			
				// 预警列表
				warningList: [],
				params: {
					page: 1, //页数 默认为1
					page_size: 10, //数据条数据 默认为10
				},
				total: 0,
			}
		},
		onLoad(options) {
			this.getWarningList();
		},
		// 触底请求
		onReachBottom(e) {
			if (this.warningList.length >= this.total) {
				return;
			}
			this.params.page += 1;
			this.getWarningList();
		},
		methods: {
			// 获取设备列表
			async getWarningList() {
				this.$api.loading('加载中...');
				const {
					data,
					nusm
				} = await getPestWarningList(this.params);
				this.$api.hide();
				this.warningList = [...this.warningList, ...data];
				this.total = nusm ?? 0;
			},
		}
	}
</script>

<style lang="scss">
	.warn-item {
		padding: 26rpx 24rpx;

		.title {
			font-size: $font-size-title;
			color: $color-title;
			line-height: $line-height-title;
		}

		.subtitle {
			margin-top: 10rpx;
			font-size: $font-size-subtitle;
			color: $color-subtitle;
			line-height: $line-height-subtitle;
		}

		.paragraph {
			margin: 10rpx 0 18rpx;
			font-size: $font-size-paragraph;
			color: $color-paragraph;
			line-height: $line-height-paragraph;
		}

		.time {
			padding: 6rpx 15rpx;
			font-size: 28rpx;
			color: #317AFD;
			line-height: 1;
			background: rgba(49, 122, 253, .3);
			border-radius: 4rpx;
		}
	}
</style>
