<template>
	<view class="blacklog-container">
		<!-- 		<uni-nav-bar fixed="true" statusBar="true" left-icon="back" :title="title" @clickLeft="back">
		</uni-nav-bar> -->
		<!-- 		<div style="height: 88rpx;width: 100%;"></div> -->
		<web-view style="margin-top: 88rpx;" :src="webViewUrl" ref="webViewRef" @message="getMessage"></web-view>
	</view>
</template>

<script>
	import Vue from "vue";
	import {
		getParentIdListByDeptId
	} from '@/api/common.js'
	export default {
		data() {
			return {
				isShow: false,
				webViewUrl: '',
				title: '申请'
			}
		},

		methods: {
			getMessage(event) {
				let data = event.detail.data
				console.log(data, 'dsdsd')
				if (data[0].type == 'selectWork') {
					uni.navigateTo({
						url: `/pages/salesServiceManagement/accessory/components/selectWork?isPieCar=1`
					})
				}

			}
		},
		mounted() {
			uni.$off('updateWorkData')
			uni.$on('updateWorkData', ({
				data
			}) => {
				this.$nextTick(() => {
					console.log(this.$scope.$getAppWebview(), 'this.$refs.webViewRef')
					let webView = this.$scope.$getAppWebview()

					if (webView) {
						webView.children()[0].evalJS(`window.x_sun('${
							JSON.stringify({
								id: data.id, // 列表工单ID
								code: data.code, // 列表工单编号（要显示的code）
								name: data.planName // 列表工单名称（可选，根据弹窗需求传递）
							})
						}')`)

					}

				})
			})
		},


		async onLoad(option = {}) {


			let headers = {};
			const value = uni.getStorageSync("token"); //取存本地的token
			// const apiInfo = uni.getStorageSync("apiInfo"); //取存本地的token

			console.log(Vue.prototype.apiUrl, 'apiInfo')
			headers = {
				"content-type": "application/json",
				"zoomwin-token": value,
				Authorization: value,
				"zoomwin-sid": uni.getStorageSync("userInfo").sessionId,
				serverInfo: Vue.prototype.apiUrl || '',
			};
			//http://192.168.1.105:18086
			let params = JSON.parse(option.params)
			let userInfo = uni.getStorageSync("userInfo")
			params.userInfo = {
				userId: userInfo.userId,
				groupId: userInfo.groupId
			}
			let html = params.type == 'add' ? 'a.html' : 'c.html'
			this.title = params.type == 'add' ? '申请' : '审批'
			try {
				params.userInfo.groupIdList = await getParentIdListByDeptId(params.userInfo.groupId)
			} catch {
				params.userInfo.groupIdList = []
			}
			console.log(params)
			setTimeout(() => {
				this.webViewUrl =
					`/hybrid/html/${html}?params=${JSON.stringify(params)}&headers=${JSON.stringify(headers)}`
				this.isShow = true
			})
		},
	}
</script>

<style>
</style>