<template>
	<view>
		<web-view v-if="pdfUrl" :src="pdfUrl" @message="getPostMessage"></web-view>
		<ssDownload ref="ssRef"></ssDownload>
	</view>
</template>

<script setup>
	import {ref} from "vue"
	import {onLoad} from "@dcloudio/uni-app"
	import ssDownload from "./ssDownload.vue"
  import * as httpApi from "@/api/pdf.js"

	const pdfUrl = ref('');
	const httpUrl = ref('');
	const ssRef = ref(null)
	
	function updatePdfUrl({banben,nianji}) {
    httpApi.getPDFUrl({
      banben,
      nianji,
    }).then(url => {
      httpUrl.value = url;
      pdfUrl.value = '/hybrid/html/web/viewer.html?file=' + encodeURIComponent(url);
    })
	}
	
	function getPostMessage() {
		// console.log('执行下载操作')
		ssRef.value.toDownload({
			type:2,
			src: httpUrl.value
		})
	}
	
	
	onLoad(({banben, nianji}) => {
		updatePdfUrl({banben, nianji});
	})
	
</script>

<style>

</style>
