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

		<div class="mui-content">
			<div class="vongi-opendoor">
				<div class="flew-items">
					<div class="mui-col-xs-3">
						<div class="vongi-opendoor-img">
							<img :src="person_data.faceImageUrl" />
						</div>
						{{person_popedom.personRoleName}}
					</div>
					<div class="mui-col-xs-9 mui-media-body">
						{{person_popedom.companyName}}
						<h5 v-text="person_popedom.deptName"></h5>
					</div>
				</div>
				<div class="vongi-yuan vongi-yuan1"></div>
				<div class="vongi-yuan vongi-yuan2"></div>
			</div>
			<div class="vongi-opendoor-bottom">
				<div v-for="(item,index) in doorList" class="flew-sp">
					{{item.name}}({{item.remoteOpenStartTime}}~{{item.remoteOpenEndTime}})
					<button :disabled="!item.isOnline || !item.isOpen" class="mui-btn mui-btn-primary" @click="open(item.id)">开门</button>
				</div>
			</div>
		</div>

		<loading :visible="isLoading"></loading>
	</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 {
		mapGetters,
		mapMutations
	} from 'vuex'
	export default {
		name: 'CommonDeviceOpenDoor',
		components: {
			Common,
			Loading,
			TopHeader
		},
		data() {
			return {
				pageTitle: '手机开门',
				doorList: [],
				isLoading: false,
				onNum: 0,
				offNum: 0,
			}
		},
		created() {},
		methods: {
			//获取列表
			getDoorList() {
				this.isLoading = true;
				API_Device.getDoorList().then(response => {
					this.isLoading = false;
					this.doorList = response;
				}).catch(error => {
					this.isLoading = false;
					mui.toast(error);
				})
			},
			//开门
			open(id) {
				var _this = this;
				var btnArray = ['否', '是'];
				mui.confirm('确认开门？', '提示', btnArray, function(e) {
					if (e.index == 1) {
						_this.openDoor(id);
					}
				})
			},
			//开门操作
			openDoor(id) {
				this.isLoading = true;
				API_Device.openDoor(id).then(response => {
					this.isLoading = false;
					mui.toast('开门成功');
				}).catch(error => {
					this.isLoading = false;
					mui.toast(error);
				})
			},
			asynCallBack() {

			},
		},
		mounted() {
			//获取列表
			this.getDoorList();
		},
		destroyed() {},
		computed: {
			...mapGetters({
				openId: 'wx_openid',
				token: 'token',
				person_data: 'person_data',
				person_popedom: 'person_popedom',
			})
		}
	}
</script>

<style scoped src="$project/assets/css/xpgj.css"></style>
<style scoped>
</style>
