<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, onBackPress} 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)
  const banben1 =ref('');
  const nianji1 =ref('');

	function updatePdfUrl({banben,nianji}) {
    httpApi.getPDFUrl({
      banben,
      nianji,
    }).then(res => {
      httpUrl.value = res.data;
      pdfUrl.value = '/static/pdf/web/viewer.html?file=' + encodeURIComponent(res.data);
    })
	}
	
	function getPostMessage() {
		// console.log('执行下载操作')
		ssRef.value.toDownload({
			type:2,
			src: httpUrl.value
		})
	}


  onBackPress((d) => {
	  console.log('地址：',`/pages/my/sxtkPage?banben=${banben1.value}&nianji=${nianji1.value}`)
	  uni.redirectTo({
	    url: `/pages/my/sxtkPage?banben=${banben1.value}&nianji=${nianji1.value}`
	  })
	return true
  })
	
	onLoad(({banben, nianji}) => {
    nianji1.value = nianji;
    banben1.value = banben;
		updatePdfUrl({banben, nianji});
	})
	
</script>

<style>

</style>
