<template>
	<view>
		<ujp-navbar :title="title" :is-back="false"  ></ujp-navbar>
		<div class="openMain">
			<div class="open1" v-if="asynCallBackBl" > 
				<img src="@/assets/img/9-4/身份认证通过.svg">
				
			</div>
			<div class="open1" v-else  >
				<img src="@/assets/img/9-4/未身份认证.svg">
				
			</div>
			
			<div  class="open2"  v-if="!asynCallBackIng">
				加载中，请稍后...
			</div>
			<div  class="open2"  v-else-if="asynCallBackIng&&asynCallBackBl">
				身份已核实，请开门进入
			</div>
			<div  class="open2"  v-show="asynCallBackIng&&!asynCallBackBl">
				您的身份暂无开门权限
			</div>
			
			<div class="open3" v-show="asynCallBackIng&&!asynCallBackBl">
				<span>此房间仅限{{projectName}}车主和小鹏管家用户使用</span>
			</div>
			<div  class="open4" v-show="asynCallBackIng&&asynCallBackBl">
				<button @click="asynCallBack()">
					<img src="@/assets/img/9-4/riLine-lock-unlock-line.svg">
					重新解锁
				</button>
			</div>
			
			<div  class="open4" v-show="asynCallBackIng&&!asynCallBackBl">
				<button @click="thispush()">
					
					前往注册
				</button>
			</div>
		</div>
		
	</view>
</template>

<script>
	import * as loginApi from '@/apis/login.js'
	import * as API from '@/apis/xpgj.js'
	export default {
		data() {
			return {
				title: '扫码开门',
				asynCallBackIng:false,
				asynCallBackBl:false,
				imei:'861658065434626',
				isLoading: false,
				openId:"",
			}
		},
		onLoad(op){
			if (op.imei) {
			
				this.imei=op.imei;
			}
			this.getUserInfo()
		},
		methods: {
			thispush(){
				uni.navigateTo({
					url: '/pages/login/login?imei='+this.imei
				})
			},
			getUserInfo() {
				this.openId= this.carhelp.getOpenId()
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				loginApi.findByOpenId({
					openId: this.carhelp.getOpenId(),
					noerror: true,
				}).then((res) => {
					uni.hideLoading();
					console.log(res)
					if(res.result&&res.data.regUser.userType==2){
						this.asynCallBack()
					}else{
						this.asynCallBack(true)
					}
					
					
					
			
			
				}).catch(error => {
					uni.showToast({
						title: error,
						icon: "none"
					})
				})
			},
			asynCallBack(bl) {
				
				this.asynCallBackIng=true;
				if (!bl) {
					this.asynCallBackBl=true;
					
					
					
					API.remoteControl({
						openId:this.openId,
						source:"xpgj",
						imei:this.imei,
						state:'1',
						channel:'1'
					}).then(response => {
						
						uni.showToast({
							title:"开门成功"
						})
						
					}).catch(error => {
						uni.showToast({
							title:error
						})
					})
					
					API.playVoice({
						source:"xpgj",
						openId:this.openId,
						imei:this.imei,
						volume:'7',
						message:'欢迎光临'
					}).then(response => {
						
					}).catch(error => {
							uni.showToast({
								title:error
							})
					})
					
				}
			},
		}
	}
</script>


<style scoped>
	.openMain{
		margin-top: 160px;
		    text-align: center;
	}
	.open1>img {
		width: 80px;
		height: 80px;
	}
	.open2{
		color: rgba(51, 51, 51, 1);
		font-size: 24px;
		margin-top: 16px;
	}
	.open3{
		color: rgba(102, 102, 102, 1);
		font-size: 14px;
		margin-top: 4px;
	}
	.open4{
		margin-top: 26px;
	}
	.open4>button{
		
		font-size: 20px;
		height: 48px;
		width: 255px;

		line-height: 20px;
		border-radius: 50px;
		background-color: rgba(255, 255, 255, 1);
		text-align: center;
		border: 1px solid rgba(187, 196, 192, 1);
		
		    display: flex;
		    margin: 0 auto;
		    align-items: center;
		    justify-content: center;
	}
</style>

