alarm-item.vue 4.38 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.deviceAlias || item.deviceName || $t('common.noData') }}</text>
				</view>
				<view class="item-text text-clip">
					<text class="text-muted">{{ item.details == null ? $t('common.noData') : getAttrText(item.details) }}</text>
				</view>
				<view class="item-text text-clip">
					<text class="text-muted">{{ item.details == null ? $t('common.noData') : getConditionText(item.details) }}</text>
				</view>
				<view class="item-text text-clip">
					<text class="text-muted">{{ item.details == null ? $t('common.noData') : getValuesText(item.details) }}</text>
				</view>
				<view class="item-text">
					<text class="text-muted">
						{{$t('device.alarmStatus')}} {{ setAlarmStatus(item.status,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)]">
							{{ setAlarmSeverity(item.severity,alarmSeverity)}}
						</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

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

	export default {
		props: {
			list: {
				type: Array,
				default: []
			}
		},
		data() {
			return {
				alarmSeverity,
				alarmStatus
			}
		},
		methods: {

			setAlarmStatus(value, list) {
				return this.$t(list.find(item => item.value === value).label)
			},
			setAlarmSeverity(value, list) {
				return this.$t(list.find(item => item.value === value).label)
			},
			setAlarmSeverityColor(value, list) {
				return {
					color: list.find(item => item.value === value).color
				}
			},
			bindImageUrl(e) {
				return this.alarmSeverity.find(item => item.value === e).icon
			},

			getAttrText(details){
				return this.formatDetailText(details,0)
			},
			getConditionText(detail){
				return this.formatDetailText(detail,1)
			},
			getValuesText(detail){
				return this.formatDetailText(detail,2)
			},
		 formatDetailText(details,type) {
				const deviceIdKeys = Object.keys(details)
				if(!deviceIdKeys) return
				const values = deviceIdKeys.reduce((acc, curr) => {
					const items = details[curr]?.triggerData
					if(items?.key && items?.logicValue && items.realValue){
						if(type==0){
							acc.push(`${this.$t('device.triggerAttribute')}:${items.key || this.$t('common.noData')}`)
						}else if (type ==1){
							acc.push(`${this.$t('device.triggerCondition')}:${findLogin(items)+items.logicValue ||  this.$t('common.noData')}`)
						}else if(type==2){
							acc.push(`${this.$t('device.triggerValue')}:${items?.realValue ||  this.$t('common.noData')}`)
						}
					}
					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: 340rpx;
			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: 311rpx;
				margin-top: 8rpx;
				margin-left: 20rpx;

				.item-text {
					width: 500rpx;
					text-align: left;
					margin-top: 13rpx;
					line-height: 40rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;

					.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>