<template>
    <web-view
		v-if="authtoken"
        :src="dibootUrl">
    </web-view>
    <!-- 测试地址 http://localhost:8080/mobile/pages/flow/flow?redirect=/pages/workflowTask/webviewPages/dealTask&id=cb864164-d638-11ee-b785-00ff0b7e144b&definitionId=system_flow_veh%3A46%3A40240578-d634-11ee-8076-00ff0b7e144b&instId=a7551e2f-d638-11ee-b785-00ff0b7e144b&category=todo&allowDeal=true-->
</template>

<script>
import webview from './webview'
export default {
    mixins: [webview],
    data() {
        return {
            dibootUrl: '',
			query: {},
			fetched: false,
        };
    },
    onLoad(query) {
		this.query = query
		// console.log(query,'queryqueryquery')
		if(this.authtoken) this.initData(query)
        
    },
	watch: {
		authtoken: {
			immediate: true,
			deep: true,
			handler(newVal) {
				// console.log(newVal,'newValnewValnewVal')
				this.initData(this.query)
			}
		}
	},
    methods: {
		initData(query) {
			console.log('query', query)
			let urlParams = ''
			let redirect = ''
			for (let key in query) {
			    if (key != 'authtoken') {
			        urlParams += `&${key}=${query[key]}`
			    }
				if (key == 'redirect') {
			        redirect = query[key]
			    }
			}
			if(!redirect) return
			urlParams = urlParams.replace('&', '?')
			this.dibootUrl = `${this.webviewServer}${redirect}${urlParams}&authtoken=${this.authtoken}`
			console.log('工作流地址', this.dibootUrl)
			
			window.addEventListener("message", receiveMessage, false);
			
			function receiveMessage(event) {
			    console.log('收到消息',event)
			    uni.switchTab({
					url: event.data
				})
			}
		},
        getLocation() {

        },
        scanCode() {

        }
    }
}
</script>

<style lang="scss"></style>
