<template>
	<view>
		<tm-nav-bar title="我的设备" @clickLeft="back" />
		<view class="content">
			<view class="content-header">
				<view class="title">设备</view>
			</view>
			<view class="content-item" v-for="(item, index) in deviceList" v-if="item.user" :class="item.device_id == getActiceDevice.device_id? 'active' : '' " @click="changeDev(item)">
				<view class="title">
					<text>绑定人: {{item.user.mobile}}</text>
				</view>
				<view class="desc">
					<text>蓝牙设备: {{item.device_id}}</text>
				</view>
			</view>
		</view>
		
		<navtab :current="1"></navtab>
	</view>
</template>

<script>
	import store from "@/store/index.js";
	import { mapGetters } from "vuex";
	
	export default {
		data() {
			return {
				deviceList: [],
			}
		},
		onLoad() {
			this.$store.dispatch('api/getBindUserDeviceId').then(res => {
				this.deviceList = res;
			});
		},
		computed: {
			...mapGetters({
				getActiceDevice: "api/getActiceDevice"
			}),
		},
		methods: {
			// 选中的设备
			changeDev(item) {
				this.$store.commit('api/setActiceDevice', item)
			},
			getNameByKey(key) {
			    return this.keyNameMap[key] || "Key not found";
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		padding: 20rpx 30rpx;
		margin-top: 20rpx;
		.content-header {
			margin-bottom: 20rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			font-size: 40rpx;
			font-weight: 800;
			.add {
				image {
					width: 50rpx;
					height: 50rpx;
				}
			}
		}
		.content-item {
			padding: 30rpx;
			border: none;
			border-radius: 30rpx ;
			-webkit-box-shadow: 0 0 60rpx 0 rgba(43,86,112,.1) ;
			box-shadow: 0 0 60rpx 0 rgba(43,86,112,.1);
			margin-bottom: 30rpx;
			.title {
				font-size: 36rpx;
				font-weight: 800;
				margin-bottom: 10rpx;
			}
			.desc {
				font-size: 30rpx;
				opacity: .6;
			}
		}
		.active {
			border: 2rpx solid #000;
		}
	}
</style>
