<!--扫描二维码页面-->
<template>
	<view id="saoCode">
		<web-view :src="baseUrl+'admin/#/codeHtml?code='+code+'&type='+type"></web-view>
	</view>
</template>

<script>
	import {
		config
	} from '@/api/request/config.js'
	import {
		chemicalAioIdentityScanLogin
	} from '@/api/basicsModules/index.js'

	export default {
		name: "saoCode",
		data() {
			return {
				baseUrl: config.base_url,
				code: "",
				type: "",
			}
		},
		onLoad(option) {
			let self = this;
			if (option.q) {
				let text = decodeURIComponent(option.q)
				let list = text.split("?")[1].split("&");
				let codeData = {};
				list.forEach((item) => {
					codeData[item.split("=")[0]] = item.split("=")[1];
				})
				if (!uni.getStorageSync('token')) {
					uni.setStorageSync('codeData', codeData);
					uni.redirectTo({
						url: '/pages/login/login',
					});
				} else {
					if (codeData.type == 11) {
						//化学品终端-扫码登录
						this.chemicalAioIdentityScanLogin(codeData.code, codeData.subId, codeData.macId);
					}
				}
			} else {
				let codeData = uni.getStorageSync('codeData');
				uni.removeStorageSync('codeData');
				if (codeData.type == 11) {
					//化学品终端-扫码登录
					this.chemicalAioIdentityScanLogin(codeData.code, codeData.subId, codeData.macId);
				}
			}
		},
		mounted() {

		},

		methods: {
			//化学品终端-扫码登录
			async chemicalAioIdentityScanLogin(code, subId, macId) {
				const {
					data
				} = await chemicalAioIdentityScanLogin({
					code: code,
					subId: subId,
					userId: uni.getStorageSync('userId'),
					macId: macId
				});
				uni.showToast({
					mask: true,
					icon: "none",
					position: "center",
					title: data.message,
					duration: 2000
				});
				setTimeout(function() {
					uni.redirectTo({
						url: '/pages/mine/mine',
					});
				}, 2000);
			},
		},
	}
</script>

<style lang="stylus" scoped>
	#saoCode {
		overflow scroll
	}
</style>