alarm-item.vue 3.27 KB
<template>
	<view class="alarm-list">
		<view @click="$emit('openAlertDetail',item)" class="list-item" v-for="(item, index) in list" :key="index">
			<view class="u-flex item">
				<view class="item-text text-clip">
					<text class="text-bold">{{ item.deviceName == null ? '暂无数据' : item.deviceName }}</text>
				</view>
				<view class="item-text text-clip">
					<text class="text-muted">{{ item.details == null ? '暂无数据' : formatDetailText(item.details) }}</text>
				</view>
				<view class="item-text">
					<text class="text-muted">
						告警状态:{{item.status | setAlarmStatus(alarmStatus)}}
					</text>
				</view>
				<view class="item-text">
					<text class="text-secondary">{{ item.createdTime }}</text>
				</view>
			</view>
			<view class="item">
				<view class="u-flex item-right">
					<image class="right-image" :src="bindImageUrl(item.severity)"></image>
					<view class="right-text">
						<text class="text-no-color" :style="[setAlarmSeverityColor(item.severity,alarmSeverity)]">
							{{item.severity | setAlarmSeverity(alarmSeverity)}}
						</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		alarmSeverity,
		alarmStatus
	} from '../config/data.js';

	export default {
		props: {
			list: {
				type: Array,
				default: []
			}
		},
		data() {
			return {
				alarmSeverity,
				alarmStatus
			}
		},
		filters: {
			setAlarmStatus(value, list) {
				return list.find(item => item.value === value).label
			},
			setAlarmSeverity(value, list) {
				return list.find(item => item.value === value).label
			}
		},
		methods: {
			setAlarmSeverityColor(value, list) {
				return {
					color: list.find(item => item.value === value).color
				}
			},
			bindImageUrl(e) {
				return this.alarmSeverity.find(item => item.value === e).icon
			},
			formatDetailText(e) {
				const keys = Object.keys(e)
				if(!keys) return
				const values = keys.reduce((acc, curr) => {
					acc.push(`${!e[curr].key?'暂无数据':e[curr].key}:${!e[curr].realValue?'暂无数据':e[curr].realValue}`)
					return acc
				}, [])
				return values.join(',')
			}
		}
	}
</script>

<style lang="scss" scoped>
	.alarm-list {
		display: flex;
		flex-direction: column;
		padding-left: 18rpx;
		justify-content: flex-start;

		.list-item {
			width: 713rpx;
			height: 233rpx;
			background-color: #fff;
			margin-top: 24rpx;
			display: flex;
			flex-direction: row;
			border-radius: 10px;
			justify-content: space-between;

			.item {
				justify-content: flex-start;
				flex-direction: column;
				align-items: center;
				height: 211rpx;
				margin-top: 8rpx;
				margin-left: 37rpx;

				.item-text {
					width: 400rpx;
					text-align: left;
					margin-top: 13rpx;
					line-height: 40rpx;

					.text {
						color: #666666;
						font-size: 15px;
					}

					.text-three {
						color: #333333;
						font-size: 15px;
					}

					.text-nine {
						color: #999999;
						font-size: 15px;
					}
				}

				.item-right {
					flex-direction: row;
					margin-top: -3rpx;
					margin-right: 25rpx;

					.right-image {
						width: 30rpx;
						height: 30rpx;
						margin-top: 20rpx;
						margin-right: 5rpx;
					}

					.right-text {
						color: #333333;
						font-size: 13px;
						margin-left: 5rpx;
						margin-top: 20rpx;
					}
				}
			}
		}
	}
</style>