<template>
	<view class="device-detail">
		<!-- 自定义导航栏 -->
		<view class="tabback">
            <view class="rtjt" @click="btnback">←</view>
            <view class="name">{{ $i18n.t('deviceDetail') }}</view>
			<view style="width: 36rpx;"></view>
		</view>

		<!-- 头像和扫码按钮（悬浮） -->
		<view class="avatar-box">
			<image class="avatar" :src="xqobj.productPicture" mode="aspectFill"></image>
			<view class="scan-btn" @click="btnrdit">
				<image src="https://api.ccttiot.com/smartmeter/img/static/uZiAQwh3lTliRkGXV3R0" mode="aspectFill"></image>
			</view>
		</view>

		<!-- 信息列表卡片 -->
		<view class="info-card">
			<view class="info-item" v-for="(item, idx) in infoList" :key="idx">
				<!-- <text class="iconfont info-icon" :class="item.iconClass">{{ item.icon }}</text> -->
				<image class="iconfont info-icon" :class="item.iconClass" :src="item.icon" mode="aspectFill"></image>
				<view class="info-content">
					<view class="info-title">{{ item.title }}</view>
					<view class="info-status-row">
						<!-- 蜂窝信号强度用格子条 -->
						<view v-if="item.type === 'signal'" class="signal-bar">
							<view v-for="n in 3" :key="n" class="signal-block" :class="{active: n <= item.subValue}"></view>
							<text class="info-status" :class="item.valueClass">{{item.value}}</text>
						</view>
						<!-- 其他状态 -->
						<text v-else class="info-status" :class="item.valueClass">{{item.value}}</text>
					</view>
				</view>
				<!-- <image v-if="item.valueClass == 'red'" style="width: 60rpx;height: 60rpx;" src="https://api.ccttiot.com/smartmeter/img/static/uw31nuDEs8OOlS36kYE3" mode=""></image> -->
				<view v-if="idx !== infoList.length-1" class="divider"></view>
			</view>
		</view>
       
		<!-- 底部摘要 -->
		<view class="device-summary">
			<view>{{xqobj.productName}}{{$i18n.t('deviceModel')}}</view>
			<view>{{ $i18n.t('hardware') }}</view>
			<view>{{ $i18n.t('firmware') }}</view>
			<view>{{$i18n.t('deviceMac')}}：{{xqobj.mac}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				infoList: [
					{ icon: 'https://api.ccttiot.com/smartmeter/img/static/uyOgEFquTkqGVoJSNzKu', title: '门磁状况 左边', value: '正常', subValue: '', iconClass: '', valueClass: '', type: 'text' },
					{ icon: 'https://api.ccttiot.com/smartmeter/img/static/uyOgEFquTkqGVoJSNzKu', title: '门磁状况 右边', value: '正常', subValue: '', iconClass: '', valueClass: '', type: 'text' },
					{ icon: 'https://api.ccttiot.com/smartmeter/img/static/uLQQwSZMMJCRoyY9niZ2', title: '磁强计', value: '正常', subValue: '', iconClass: '', valueClass: '', type: 'text' },
					{ icon: 'https://api.ccttiot.com/smartmeter/img/static/uoqYd103xEnqfHqQCV3m', title: '加速度器（3-axis）震动', value: '100%', subValue: '', iconClass: '', valueClass: '', type: 'text' },
					{ icon: 'https://api.ccttiot.com/smartmeter/img/static/unC82eDTsw5iBODBWQy0', title: '加速度器（3-axis）角度', value: '45°', subValue: '', iconClass: '', valueClass: '', type: 'text' },
					{ icon: 'https://api.ccttiot.com/smartmeter/img/static/upMEA7YPuRFC2VClTsXv', title: '温度（℃）', value: '2℃就改变', subValue: '', iconClass: '', valueClass: '', type: 'text' },
					{ icon: 'https://api.ccttiot.com/smartmeter/img/static/uGzlwvxrcAsRPCW34eKp', title: '电池电量', value: '100%', subValue: '', iconClass: '', valueClass: '', type: 'text' },
					{ icon: 'https://api.ccttiot.com/smartmeter/img/static/ujnGeXUE8lSWKXg7bcFf', title: '设备盖子', value: '打开', subValue: '', iconClass: '', valueClass: 'red', type: 'text' },
					{ icon: 'https://api.ccttiot.com/smartmeter/img/static/u9ElqXEKREKILzl3SLUG', title: '设备支架', value: '正常', subValue: '', iconClass: '', valueClass: '', type: 'text' },
					{ icon: 'https://api.ccttiot.com/smartmeter/img/static/uyO1e6LIeqzoybk2MeLt', title: 'HUB接连', value: '连接', subValue: '', iconClass: '', valueClass: '', type: 'text' },
					{ icon: 'https://api.ccttiot.com/smartmeter/img/static/u8LVyGR693oxNl6DaJLI', title: 'HUB信号强度', value: '', subValue: '3', iconClass: '', valueClass: '', type: 'signal' },
					{ icon: 'https://api.ccttiot.com/smartmeter/img/static/usrbHxshaZ3iuDlTHL4w', title: '连接模式', value: '有线', subValue: '', iconClass: '', valueClass: '', type: 'text' },
					{ icon: 'https://api.ccttiot.com/smartmeter/img/static/u8LVyGR693oxNl6DaJLI', title: 'LORA信号强度', value: '-95(dBm)', subValue: '2', iconClass: '', valueClass: '', type: 'signal' },
					{ icon: 'https://api.ccttiot.com/smartmeter/img/static/u8LVyGR693oxNl6DaJLI', title: 'BLE信号强度', value: '-95(dBm)', subValue: '1', iconClass: '', valueClass: '', type: 'signal' },
					{ icon: 'https://api.ccttiot.com/smartmeter/img/static/uMLNWkOVJRxP7rws6oHm', title: 'LORA发射功率', value: '', subValue: '2', iconClass: '', valueClass: '', type: 'signal' },
					{ icon: 'https://api.ccttiot.com/smartmeter/img/static/uMLNWkOVJRxP7rws6oHm', title: 'BLE发射功率', value: '', subValue: '3', iconClass: '', valueClass: '', type: 'signal' },
					{ icon: 'https://api.ccttiot.com/smartmeter/img/static/uc1XzHKWwT9EzARbZIeR', title: '中继器', value: '无', subValue: '', iconClass: '', valueClass: '', type: 'text' },
					{ icon: 'https://api.ccttiot.com/smartmeter/img/static/uRhz8EQZgniEsUdrWjzL', title: 'NC接口', value: '开启', subValue: '', iconClass: '', valueClass: '', type: 'text' },
				],
				id:'',
				xqobj:{}
			}
		},
		onLoad(option) {
			this.id = option.id
			this.getxq()
		},
		methods: {
			// 点击进行设备修改
			btnrdit(){
				uni.navigateTo({
					url:'/pages/device/mcygedit?id=' + this.id
				})
			},
			// 进行设备详情请求
			getxq(){
				this.$http.get(`/bst/device/detail?id=${this.id}`).then(res => {
					if(res.code == 200){
						this.xqobj = res.data
					}
				})
			},
            // 点击返回上一级
			btnback(){
				uni.navigateBack()
			}
		}
	}
</script>

<style scoped lang="less">
	.tabback {
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: 100%;
		height: 160rpx;
		padding: 0 20rpx;
		padding-top: 80rpx;
		box-sizing: border-box;
		position: fixed;
		top: 0;
		left: 0;
        z-index: 999 !important;
		background-color: #fff;
		.rtjt {
			font-size: 36rpx;
		}
	}
	.device-detail {
		padding-top: 150rpx;
		background-color: #F3F5F6;
	}
	.avatar-box {
		position: relative;
		display: flex;
		justify-content: center;
		margin-top: 60rpx;
		padding-bottom: 74rpx;
		border-bottom: 1rpx solid #f2f2f2;
		.avatar {
			width: 278rpx;
			height: 278rpx;
			background: #e0e0e0;
			border-radius: 24rpx;
			box-shadow: 0 2rpx 8rpx #eee;
		}
		.scan-btn {
			image{
				width: 48rpx;
				height: 48rpx;
			}
			position: absolute;
			right: 26rpx;
			top: -36rpx;
			width: 48rpx;
			height: 48rpx;
			background: #fff;
			border-radius: 50%;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 32rpx;
			box-shadow: 0 2rpx 8rpx #eee;
			border: 1rpx solid #eee;
		}
	}
	.info-card .info-item:nth-child(9){
		margin-bottom: 30rpx;
	}
	.info-card .info-item:nth-child(10){
		border-top: 1px solid #f2f2f2;
	}
	.info-card {
		.info-item {
			display: flex;
			align-items: flex-start;
			padding: 0 24rpx 0 32rpx;
			position: relative;
			min-height: 80rpx;
			background: #fff;
			image{
				width: 50rpx;
				height: 50rpx;
				margin-top: 30rpx;
			}
			.info-icon {
				font-family: 'iconfont' !important;
				font-size: 32rpx;
				margin-right: 18rpx;
				color: #222;
				line-height: 80rpx;
			}
			.info-content {
				flex: 1;
				padding: 18rpx 0;
				.info-title {
					font-size: 28rpx;
					color: #727272;
					font-weight: 500;
				}
				.info-status-row {
					display: flex;
					align-items: center;
					margin-top: 6rpx;
					min-height: 32rpx;
					.info-status {
						font-size: 26rpx;
						color: #3D3D3D;
						&.red {
							color: #e74c3c;
						}
						&.green {
							color: #27ae60;
						}
					}
					.signal-bar {
						display: flex;
						align-items: center;
						.signal-block {
							width: 62rpx;
							height: 6rpx;
							margin-right: 6rpx;
							border-radius: 2rpx;
							background: #e0e0e0;
							&.active {
								background: #4cd964;
							}
						}
					}
				}
			}
			.divider {
				position: absolute;
				left: 0;
				right: 0;
				bottom: 0;
				height: 1rpx;
				background: #f2f2f2;
			}
		}
	}
	.device-summary {
		background: #f7f7f7;
		text-align: center;
		color: #888;
		font-size: 24rpx;
		line-height: 1.8;
		border-radius: 0 0 20rpx 20rpx;
		padding-top: 40rpx;
		box-sizing: border-box;
		padding-bottom: 30rpx;
	}
</style>