<template>
	<view class="content">
		<view class="textBoard">
			<text style="color: #fff; font-size: 48rpx;">Need permissions?</text>
		</view>
		<view class="textBoard">
			<text style="color: #fff; font-size: 36rpx;">Camera permission is requeired to</text>
		</view>
		<view class="textBoard">
			<text style="color: #0186FF; font-size: 36rpx;">QR Code Scanner & barcode Reader.</text>
		</view>
		<view class="textBoard">
			<text style="color: #fff; font-size: 36rpx;">1.Open settings</text>
		</view>
		<view class="textBoard">
			<text style="color: #fff; font-size: 36rpx;">2.Tap permissions</text>
		</view>
		<view class="textBoard">
			<text style="color: #fff; font-size: 36rpx;">3.Turn on Camera</text>
		</view>
		<view class="textBoard">
			<tn-button @click="setPermission()" :backgroundColor="btnBackgroundColor" :fontColor="btnFontColor" width="300rpx" height="100rpx"
			:fontSize="btnFontSize">Open settings</tn-button>
		</view>
	</view>
</template>

<script>
	import permision from "@/js_sdk/wa-permission/permission.js"
	export default {
		data() {
			return {
				btnFontSize: 36,
				btnBackgroundColor: '#0186ff',
				btnFontColor: '#fff',
			}
		},
		async onLaunch() {
			let that = this;
			that.ifAppOnlaunched = true;
			that.$isResolve()
		},
    	async onShow(){
			let that = this;
			if(!that.ifAppOnlaunched){
				await that.$onLaunched;
				console.log('setonShow')
				await that.requestAndroidPermission('android.permission.CAMERA');
			}
		},
		onHide() {
			console.log('onHide')
		},
		onUnload(){
			console.log('onUnload')
		},
		methods: {
			
			//打开设置权限界面
			setPermission(){
				permision.gotoAppPermissionSetting();
			},
			
			//判断是否有相机权限
			async requestAndroidPermission(permisionID) {
				let that = this;
			    var result = await permision.requestAndroidPermission(permisionID)
				console.log('setting判断权限结果',result) 
				if (result == '1') {
				//有权限,跳转到扫码界面
				that.jumpToRights('/pages/scan/Scan');
				}
			},
			
			//跳转到授权设置页面
			jumpToRights(url){
				uni.switchTab({
					url: url
				})
			}
			
		}
	}
</script>

<style lang="scss">
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		background-color: #1F222B;
		height:100vh;
	}
	
	.textBoard{
		margin-top: 1vh;
	}
</style>