<template>
	<view class="page">
		<u-navbar title="详情" :border-bottom="false" :background="bgc" title-color='#262B37' title-size='38'
			height='40'></u-navbar>
		<view class="wangguan">
			<!-- 网关设备信息 -->
			<view class="wgshebei">
				<image :src="wgxq.picture || wgxq.modelPicture || ''" mode="aspectFill"></image>
				<view class="wgname">
					<text>{{ wgxq.deviceName || '未命名设备' }}</text>
					<view class="status-badge" :class="(wgxq.onlineStatus == 1 || wgxq.onlineStatus == 0) ? 'status-online' : 'status-offline'">
						{{ (wgxq.onlineStatus == 1 || wgxq.onlineStatus == 0) ? '在线' : '离线' }}
					</view>
				</view>
			</view>
			
			<!-- SN和MAC -->
			<view class="wgsnmac">
				<view class="ltsn">
					SN：{{ wgxq.sn || '--' }}
				</view>
				<view class="rtmac">
					MAC：{{ wgxq.mac || '--' }}
				</view>
			</view>
			
			<!-- 操作区域 -->
			<!-- <view class="wgcaozuo">
				<view class="wggx">
					<view class="lt">
						<view class="">
							版本信息
						</view>
						<view class="">
							{{ wgxq.version || '--' }} <image src="https://api.ccttiot.com/smartmeter/img/static/ugdatiDv4sy9w6SLYMgU" mode=""></image>
						</view>
					</view>
				</view>
			</view> -->
			
			<!-- 时间信息 -->
			<view class="wgtime" v-if="wgxq.updateTime || wgxq.activationTime">
				<view class="time-item" v-if="wgxq.activationTime">
					<text class="time-label">激活时间：</text>
					<text class="time-value">{{ wgxq.activationTime }}</text>
				</view>
			</view>
			
			<!-- 设备列表 -->
			<view class="wglist">
				<view class="wgtit">
					设备列表 ({{ wglist.length }})
				</view>
				<view class="wgitem" v-for="(item,index) in wglist" :key="index">
					<image :src="item.picture || item.modelPicture || ''" mode="aspectFill"></image>
					<view class="cen">
						<text>{{ item.deviceName || '未命名设备' }}</text>
						<text style="color: #808080;font-size: 24rpx;">{{ item.modelName || '--' }}</text>
					</view>
					<view class="item-status" :class="(item.onlineStatus == 1 || item.onlineStatus == 0) ? 'status-online-dot' : 'status-offline-dot'"></view>
				</view>
				<view class="empty-device" v-if="wglist.length === 0">
					<text>暂无设备</text>
				</view>
			</view>
		</view>
		<view class="saoma" @click="btnjb">
			解绑
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bgc: {
					backgroundColor: "#fff",
				},
				id:'',
				wgxq:{},
				wglist:[],
			}
		},
		onLoad(e) {
            this.id = e.id
			this.getxq()
		},
		methods: {
			// 点击进行解绑
			btnjb(){
				let that = this
				uni.showModal({
					title: '提示',
					content: '您确定要解绑当前设备吗？',
					success: function(res) {
						if (res.confirm) {
							that.$u.delete(`/app/device/unbind/${that.wgxq.deviceId}`).then(res => {
								if (res.code == 200) {
									uni.showToast({
										title: '解绑成功',
										icon: 'success',
										duration: 2000
									})
									setTimeout(() => {
										uni.reLaunch({
											url:'/pages/index/index'
										})
									}, 1000)
								} else {
									uni.showToast({
										title: res.msg,	
										icon: 'none',
										duration: 2000
									})
								}
							})
						} else if (res.cancel) {
				
						}
					}
				})
			},
            getxq(){
            	this.$u.get(`/app/getDeviceInfo/${this.id}`).then((res) => {
            		if (res.code == 200) {
            			this.wgxq = res.data
						console.log(11); 
						this.getlist()
            		}
            	})
            },
			// 查询网关下的设备
			getlist(){
				console.log(111);
				let data = {
					gatewayMacList: [this.wgxq.mac]
				}
				this.$u.post(`/app/device/gateway/list`, data).then((res) => {
					if (res.code == 200) {
						this.wglist = res.rows
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.saoma{
		width: 680rpx;
		height: 90rpx;
		background-color: #48893B;
		color: #FFFFFF;
		font-size: 32rpx;
		font-weight: 600;
		text-align: center;
		line-height: 90rpx;
		border-radius: 30rpx;
		position: fixed;
		left: 50%;
		transform: translateX(-50%);
		bottom: 30rpx;
	}
 .wangguan{
 	padding: 0 30rpx;
 	box-sizing: border-box;
 	
 	.wglist{
 		width: 100%;
 		min-height: 200rpx;
 		max-height: 740rpx;
		overflow: scroll;
 		background: #FFFFFF;
 		box-shadow: 0rpx 0rpx 38rpx 0rpx rgba(128,128,128,0.15);
 		margin: auto;
 		margin-top: 20rpx;
 		border-radius: 24rpx;
 		padding: 32rpx 40rpx;
 		box-sizing: border-box;
 		
 		.wgtit{
 			font-size: 32rpx;
 			color: #3D3D3D;
 			font-weight: 600;
 			margin-bottom: 20rpx;
 		}
 		
 		.wgitem{
 			margin-top: 30rpx;
			max-height: 730rpx;
			overflow: scroll;
 			display: flex;
 			justify-content: space-between;
 			align-items: center;
 			padding-bottom: 30rpx;
 			border-bottom: 1rpx solid #F0F0F0;
 			
 			&:last-child{
 				border-bottom: none;
 			}
 			
 			image{
 				width: 78rpx;
 				height: 84rpx;
 				border-radius: 12rpx;
 				background: #F5F5F5;
 			}
 			
 			.cen{
 				flex: 1;
 				margin-left: 24rpx;
 				
 				text{
 					display: block;
 					font-weight: 600;
 					font-size: 28rpx;
 					color: #3D3D3D;
 					
 					&:last-child{
 						margin-top: 8rpx;
 						font-weight: 400;
 						font-size: 24rpx;
 						color: #808080;
 					}
 				}
 			}
 			
 			.item-status{
 				width: 16rpx;
 				height: 16rpx;
 				border-radius: 50%;
 				
 				&.status-online-dot{
 					background: #15C55D;
 					box-shadow: 0 0 8rpx rgba(21, 197, 93, 0.4);
 				}
 				
 				&.status-offline-dot{
 					background: #999999;
 				}
 			}
 		}
 		
 		.empty-device{
 			text-align: center;
 			padding: 60rpx 0;
 			color: #999;
 			font-size: 28rpx;
 		}
 	}
 	
 	.wgtime{
 		width: 100%;
 		background: #FFFFFF;
 		box-shadow: 0rpx 0rpx 38rpx 0rpx rgba(128,128,128,0.15);
 		margin-top: 20rpx;
 		border-radius: 24rpx;
 		padding: 30rpx 40rpx;
 		box-sizing: border-box;
 		
 		.time-item{
 			margin-bottom: 20rpx;
 			
 			&:last-child{
 				margin-bottom: 0;
 			}
 			
 			.time-label{
 				font-size: 28rpx;
 				color: #808080;
 			}
 			
 			.time-value{
 				font-size: 28rpx;
 				color: #3D3D3D;
 				margin-left: 10rpx;
 			}
 		}
 	}
 	
 	.wgcaozuo{
 		width: 100%;
 		background: #FFFFFF;
 		box-shadow: 0rpx 0rpx 38rpx 0rpx rgba(128,128,128,0.15);
 		margin-top: 20rpx;
 		border-radius: 24rpx;
 		padding: 0 40rpx;
 		box-sizing: border-box;
 		
 		.wgkg{
 			height: 110rpx;
 			line-height: 110rpx;
 			border-bottom: 1px solid #D8D8D8;
 			
 			.lt{
 				width: 100%;
 				display: flex;
 				justify-content: space-between;
 				align-items: center;
 				
 				.status-switch{
 					.status-text{
 						font-size: 26rpx;
 						padding: 6rpx 16rpx;
 						border-radius: 20rpx;
 						
 						&.status-online-text{
 							background: rgba(21, 197, 93, 0.1);
 							color: #15C55D;
 						}
 						
 						&.status-offline-text{
 							background: rgba(153, 153, 153, 0.1);
 							color: #999999;
 						}
 					}
 				}
 			}
 		}
 		
 		.wggx{
 			height: 110rpx;
 			line-height: 110rpx;
 			
 			.lt{
 				width: 100%;
 				display: flex;
 				justify-content: space-between;
 				align-items: center;
 				
 				image{
 					width: 32rpx;
 					height: 32rpx;
 					margin-left: 10rpx;
 				}
 				
 				view{
 					display: flex;
 					align-items: center;
 				}
 			}
 		}
 	}
 	
 	.wgsnmac{
 		width: 100%;
 		height: 92rpx;
 		background: #FFFFFF;
 		box-shadow: 0rpx 0rpx 38rpx 0rpx rgba(128,128,128,0.15);
 		border-radius: 24rpx;
 		display: flex;
 		justify-content: space-between;
 		// padding: 0 30rpx;
 		box-sizing: border-box;
 		padding-top: 16rpx;
 		
 		.ltsn{
 			border-right: 1px solid #D8D8D8;
 		}
 		
 		view{
 			height: 60rpx;
 			width: 50%;
 			text-align: center;
 			line-height: 60rpx;
 			font-size: 28rpx;
 			color: #808080;
 		}
 	}
 	
 	.wgshebei{
 		width: 100%;
 		text-align: center;
 		margin-top: 40rpx;
 		margin-bottom: 30rpx;
 		
 		image{
 			width: 168rpx;
 			height: 168rpx;
 			border-radius: 20rpx;
 			background: #F5F5F5;
 		}
 		
 		.wgname{
 			font-weight: 600;
 			font-size: 36rpx;
 			color: #3D3D3D;
 			display: flex;
 			align-items: center;
 			justify-content: center;
 			margin-top: 30rpx;
 			flex-wrap: wrap;
 			
 			text{
 				margin-right: 16rpx;
 			}
 			
 			.status-badge{
 				display: inline-block;
 				padding: 6rpx 20rpx;
 				border-radius: 20rpx;
 				font-size: 24rpx;
 				font-weight: 500;
 				
 				&.status-online{
 					background: rgba(21, 197, 93, 0.1);
 					color: #15C55D;
 				}
 				
 				&.status-offline{
 					background: rgba(153, 153, 153, 0.1);
 					color: #999999;
 				}
 			}
		}
	}
}
</style>