device-item.vue 2.72 KB
<template>
	<view class="device-list">
		<view @click="$emit('openDeviceDetail',item)"
			class="list-item" v-for="item in list" :key="item.id">
			<view class="u-flex item">
				<view class="item-text text-clip">
					<view>
						<text class="text-span-bold">{{ item.alias ? item.alias : item.name }}</text>
					</view>
				</view>
				<view class="item-text text-clip">
					<view class="text-container">
						{{$t('device.deviceNumber')}}:
						<text class="text-span">{{ item.sn }}</text>
					</view>
				</view>
				<view class="item-text text-clip">
					<view class="text-container">
						{{$t('common.belongingOrganization')}}:
						<text class="text-span">{{ item.organizationDTO.name }}</text>
					</view>
				</view>
			</view>
			<view class="item right-item">
				<view class="u-flex" style="margin-top: -6rpx">
					<image class="right-image" :src="formatRightImage(item.deviceState)" />
					<view>
						<text class="right-text" :style="{ color:formatColor(item.deviceState) }">
							{{ formatText(item.deviceState) }}
						</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			list: {
				type: Array,
				default: []
			}
		},
		methods: {
			formatRightImage(deviceState) {
				return deviceState === 'ONLINE' ?
					'/static/online.png' :
					deviceState === 'INACTIVE' ?
					'/static/unonline.png' :
					'/static/baojing.png'
			},
			formatText(deviceState) {
				return deviceState === 'ONLINE' ? this.$t('homePage.deviceLabel.onLine') : deviceState === 'INACTIVE' ? this.$t('homePage.deviceLabel.beActivated') : this.$t('homePage.deviceLabel.offLine')
			},
			formatColor(deviceState) {
				return deviceState === 'ONLINE' ? '#377DFF' : deviceState === 'INACTIVE' ? '#666666' : '#DE4437'
			}
		}
	}
</script>

<style lang="scss" scoped>
	.device-list {
		display: flex;
		flex-direction: column;
		padding-left: 20rpx;

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

			.item {
				margin: 30rpx;
				flex-direction: column;
				justify-content: space-between;

				.item-text {
					width: 480rpx;

					.text-container {
						display: flex;

						.text-span {
							color: #666;
							font-size: 14px;
							display: flex;
							margin-left: 20rpx;
						}
					}



					.text-span-bold {
						color: #333;
						font-size: 15px;
						font-weight: bold;
					}
				}
			}

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

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