<template>
	<view>
		<web-view v-if="show"  :src="url"></web-view>
	</view>
</template>
<script>
	import { fileLocationQuery } from 'api/fileLocationQuery'
	export default {
		onShareAppMessage(res) {
			if (res.from === 'button') {// 来自页面内分享按钮
				console.log(res.target)
			}
			return {
				title: '',
				path: `/pages/Policy/PolicyDetails?id=${this.id}&token=wutoken`
			}
		},
		async onLoad(option){
			var that = this
			that.url = `https://www.sxwikionline.com/miniprogram/index.html?id=` + option.id + `&token=` + option.token
			that.id = option.id
			if(option.t && option.e){
				that.show = false
				const params = {
					param:{
						fileLocation: option.e
					}
				}
				const data = await fileLocationQuery(params)
				console.log(data)
				// 请求后台查询文件路径，截取文件后缀
				// console.log(option.t + '?path=' + option.e)
				const arr = data[0].fileLocation.split('.')
				const lastName = arr[arr.length-1]
				console.log(lastName)
				uni.downloadFile({
				    url: option.t + '?path=' + option.e,
						success(res) {
							const lastPath = res.tempFilePath
							console.log(lastPath)
							uni.openDocument({
								filePath: lastPath,
								fileType: lastName,
								success: function (res) {
									console.log('打开文档成功')
									console.log(res)
								},
								fail:function(err){
									console.log(err)
								}
							});
						},
						fail(err){
							console.log(err)
						}
				})
			}
		},
		data() {
			return {
				url:'',
				content:{},
				show:true,
				id:0,
			}
		}
	}
</script>
<style lang="scss">
*{
	display: none;
}
</style>
