<template>
	<view>
		<web-view id="webviewId" :update-title="false" :webview-styles="webviewStyles" @message="getMessage" :src="webViewSrc"
			style="height: 100%;" ref="webView"></web-view>
	</view>
</template>

<script>
	import {
		getToken
	} from '@/utils/auth';
	// import '@/utils/webview.js'
	let wv // 计划创建的webview
	export default {
		data() {
			return {
				webViewHeight: 0,
				webviewStyles: {
					top: "30px",
				},
				phoneNumber: uni.getStorageSync('mobile'),
				token: getToken(),
				webView: null
			};
		},
		computed: {
			webViewSrc() {
				// return `/SDT_ZHST_APP?token=${this.token}`;//本地
				//return `../../static/yjCanteen/SDT_ZHST_APP?token=${uni.getStorageSync('token')}`;//本地
				// return `/canteen/SDT_ZHST_APP?token=${uni.getStorageSync('token')}`;//本地
				  const token = uni.getStorageSync('token');
				  const mobile = uni.getStorageSync('mobile');
				  const origin = location.origin;
				  console.log(origin)
				  return `${origin}/canteen/SDT_ZHST_APP/index.html?token=${token}&mobile=${mobile}`;
			}
		},
		onReady() {
			// #ifdef APP-PLUS
			const currentWebview = this.$scope.$getAppWebview() // 获取当前页面的webview对象
			setTimeout(()=>{
				this.webView = currentWebview.children()[0]
				this.webView.setStyle({
					scalable: true
				})
			}, 1000); // 如果是页面初始化调用时，需要延时一下
			// #endif
			window.addEventListener("message", this.getMessage);
		},
		methods: {
			getMessage(event) { //在H5端使用通信返回App端
				console.log(event, '0000000000000000000000000')
				if (event.data.data.arg.action == 'stage_navigateBack') {
					uni.reLaunch({
						url: '/pages/system'
					});
				}else if (event.data.data.arg.action == 'logOut') {
					uni.reLaunch({
						url: '/pages/login'
					});
				}else if (event.data.data.arg.action == 'sbdCanteen') {// 跳转到sbd食堂
					// uni.reLaunch({
					// 	url: '/pages/index'  // 测试
					// });
          this.$router.push({ path: '/pages/index' })
				}
			}
		},
		mounted() {
			window.onQrScanSuccess = (result) => {
				return onQrScanSuccess(result);
			}
		  }
	};
</script>
<style lang="scss" scoped>
	page {
		background: #fff;
	}
</style>
