<template>
	<div>
		<common ref="common" @asynCallBack="asynCallBack"></common>
		<top-header :pageTitle="pageTitle" routeName="Master"></top-header>

		<div class="mui-content vongi-qqhm vongi-sblist">
			<ul class="mui-table-view">
				<li v-for="(item,index) in watchList" class="mui-table-view-cell">
					<a @click="defaultWatch(item.deviceNo)" class="mui-radio">
						<div class="mui-col-xs-10  mui-pull-left ">
							<div class="mui-media-object mui-pull-left "><img src="~$project/assets/img/icon_watch.png" width="50" /></div>
							<div class="mui-media-body">
								<h3 class='mui-ellipsis' v-text="item.aliasName"></h3>
								<p class='mui-ellipsis mui-h3' v-text="item.deviceNo"></p>
							</div>
						</div>
						<input name="radio1" type="radio" :checked="item.isDefault" readonly="readonly">
					</a>
				</li>
			</ul>
		</div>
		<NullList :remark="'暂无设备，来关联一下吧'" v-if="!watchList.length"></NullList>
		<div class="fyy-footer">
			<div class="bindfyy-btn" @click="addDevice"><button type="submit" class="mui-btn mui-btn-pink ">关联新设备</button></div>
		</div>
	</div>
</template>

<script>
	import * as API_Device from '@/apis/Common/device'
	import Common from '$project/components/Common.vue'
	import Loading from '$project/components/Loading.vue'
	import TopHeader from '$project/components/TopHeader.vue'
	import NavMenu from '@/components/NavMenu.vue'
	import NullList from '$project/components/NullList.vue'
	import {
		mapGetters,
		mapMutations
	} from 'vuex'
	export default {
		name: 'CommonDeviceList',
		components: {
			Common,
			Loading,
			TopHeader,
			NavMenu,
			NullList
		},
		data() {
			return {
				isLoading: false,

				watchList: [],

				pageTitle: '设备列表',
			}
		},
		created() {},
		methods: {
			//获取手环列表
			getWatchList() {
				this.isLoading = true;
				API_Device.getWatchList().then(response => {
					this.isLoading = false;

					this.watchList = response;
				}).catch(error => {
					this.isLoading = false;
					mui.toast(error);
				})
			},
			//切换默认手环
			defaultWatch(deviceNo) {
				this.isLoading = true;
				API_Device.setDefaultWatch(deviceNo).then(response => {
					this.isLoading = false;

					this.getWatchList();
					mui.toast('切换成功');
					/* this.$router.push({
						name: 'Master'
					}) */
				}).catch(error => {
					this.isLoading = false;
					mui.toast(error);
				})
			},
			//关联新设备
			addDevice() {
				this.$router.push({
					name: 'CommonDeviceAdd'
				})
			},

			asynCallBack() {},
		},
		mounted() {
			//获取手环列表
			this.getWatchList();
		},
		destroyed() {

		},
		computed: {
			...mapGetters({
				openId: 'wx_openid',
				token: 'token',
				person_data: 'person_data',
				person_popedom: 'person_popedom',
				menu_list: 'menu_list',
				common_menu_list: 'common_menu_list',
				persion_home_model: 'persion_home_model'
			})
		}
	}
</script>

<style scoped src="$project/assets/css/pension.css"></style>
<style scoped src="$project/assets/css/xpwyfyy.css"></style>
<style src="$project/assets/css/iconfont.css"></style>
<style>
</style>
