<template>
	<view>
		<view class="top">
			<!-- #ifdef MP-WEIXIN -->
			<NavigateBar title="手机开门" control="back"  bgcolor="#a09cc4"></NavigateBar>
			<!-- #endif -->
			<!-- #ifdef MP-ALIPAY -->
			<NavigateBar title="手机开门" bgcolor="#a09cc4"></NavigateBar>
			<!-- #endif -->
		</view>
		<view v-if="Object.keys(checkinInfo).length > 0">
			<view class="info">
				<view class="title">
					<view class="hotel-name">
						<u-text :text="checkinInfo.hotelName" bold color="#333333" size="30rpx"></u-text>
					</view>
					<view class="tips">
						<u-text text="入住信息" color="#666666" size="24rpx"></u-text>
					</view>
				</view>
				<view class="checkin-info">
					<view class="checkin-info--item">
						<view class="checkin-info--item--text">
							<u-text text="所在楼层 : " color="#999999" size="26rpx"></u-text>
						</view>
						<view class="checkin-info--item--text">
							<u-text :text="checkinInfo.floor+'楼'" color="#999999" size="26rpx"></u-text>
						</view>
					</view>
					<view class="checkin-info--item">
						<view class="checkin-info--item--text">
							<u-text text="房间信息 : " color="#999999" size="26rpx"></u-text>
						</view>
						<view class="checkin-info--item--text">
							<u-text :text="checkinInfo.room+'楼'" color="#999999" size="26rpx"></u-text>
						</view>
					</view>
					<view class="checkin-info--item">
						<view class="checkin-info--item--text">
							<u-text text="起始时间 : " color="#999999" size="26rpx"></u-text>
						</view>
						<view class="checkin-info--item--text">
							<u-text :text="formatDateTime(checkinInfo.startTime)" color="#999999" size="26rpx"></u-text>
						</view>
					</view>
					<view class="checkin-info--item">
						<view class="checkin-info--item--text">
							<u-text text="结束时间 : " color="#999999" size="26rpx"></u-text>
						</view>
						<view class="checkin-info--item--text">
							<u-text :text="formatDateTime(checkinInfo.endTime)" color="#999999" size="26rpx"></u-text>
						</view>
					</view>
				</view>
			</view>

			<view class="room__operate">
				<view v-if="allowedOpenDoor === 0" class="room__operate--display" @click="bluetoothOperate">
					<u-icon name="lock-open" color="#FFFFFF" size="25"></u-icon>
					<view class="display__desc">手机开门</view>
				</view>
				<view v-else-if="allowedOpenDoor === 1" class="room__operate--display">
					<u-loading-icon :show="isOpeningDoor" :text="loadingContent" color="#FFFFFF" textColor="#FFFFFF"></u-loading-icon>
				</view>
				<view v-else-if="allowedOpenDoor === 2" class="room__operate--display" @click="preventOpenDoor">
					<u-icon name="lock-open" color="#FFFFFF" size="30"></u-icon>
					<view class="display__desc">手机开门</view>
				</view>
			</view>
		</view>
		<view v-else class="not-reservation">
			<text class="tip">您还未入住!</text>
		</view>
	</view>
</template>

<script>
	import { bluetooth } from "../../mixins/bluetoothMixin";
	import moment from "moment";
	import NavigateBar from "../../components/navigateBar/navigate-bar.vue";
	export default {
		mixins: [bluetooth],
		components: {
			NavigateBar
		},
		data() {
			return {};
		},
		methods: {
			preventOpenDoor() {
				uni.showModal({
					title: "温馨提示",
					content: "未获取到房间门锁设备信息，请稍后重试",
				});
			},
			formatDateTime(dateTime) {
				return moment(dateTime).format("YYYY年MM月DD日HH时mm分");
			},
		},
		// #ifdef MP-WEIXIN
		onShareAppMessage(info) {
			return {
				title: '源享住',
				path: 'pages/login/login',
				imageUrl: "/static/logo.png"
			}
		}
		// #endif
	};
</script>

<style lang="scss">
	page {
		background-color: #FFFFFF;

		.info {
			background: #F5F8FE;
			box-shadow: -6px 17px 21px 0px rgba(112, 152, 246, 0.14);
			margin-bottom: 200rpx;

			.title {
				display: flex;
				justify-content: space-between;
				padding: 0 40rpx;
				line-height: 80rpx;
				border-bottom: 2rpx solid #E0E8FB;
			}

			.checkin-info {
				margin: 20rpx auto;

				.checkin-info--item {
					display: flex;
					margin: 0 40rpx;

					.checkin-info--item--text {
						margin: 10rpx;
						margin-left: 0;
					}

					&:last-child {
						padding-bottom: 20rpx;
					}
				}
			}
		}

		.room__operate {
			height: 90rpx;
			display: flex;
			margin: 2*5rpx 2 * 15rpx;
			background-color: #9e97c3;
			align-items: center;
			justify-content: center;
			border-radius: 10rpx;

			.room__operate--display {
				height: 2 * 25rpx;
				margin: 5rpx;
				padding: 2 * 6rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				width: 100%;

				.display__desc {
					height: 100%;
					display: flex;
					align-items: center;
					justify-content: center;
					padding-left: 10rpx;
					font-size: 40rpx;
					color: #FFFFFF;
					font-size: 32rpx;
				}
			}
		}

		.not-reservation {
			display: flex;
			justify-content: center;
			height: 100%;
			text-align: center;
			vertical-align: 100rpx;

			.tip {
				padding-top: 40%;
			}
		}
	}
</style>