<template>
	<view>
		<!-- <view class="pdfBox" id="mycanvas" ref="mycanvas"></view> -->
		<!-- <iframe :src="'http://10.0.1.159:9100/' + pdfUrl" frameborder="0"  class="pdfBox"></iframe> -->
		<!-- <iframe src="https://docs.oracle.com/javaee/6/tutorial/doc/javaeetutorial6.pdf" frameborder="0"  class="pdfBox"></iframe> -->
		<!-- <web-view :src="'http://172.16.1.159:9100/' + pdfUrl"></web-view> -->
		<view v-if="this.pdfUrl != ''">pdf文件如下：</view>
		<view class="fileDown" v-if="this.pdfUrl != ''">
			<view style="display: inline-block;">法律法规详情介绍PDF</view>
			<view style="float: right;margin-right:20upx;color: #0000BF;" @click="download(pdfUrl,'法律法规详情介绍PDF')">下载
			</view>
			<view></view>
		</view>

		<!-- <web-view src="https://www.geidcp.com/api/file/pub/cms/2021/05/10/c8db4efaf7fa4b49adf515b9334f2e77.pdf"></web-view> -->
		<!-- <web-view src="https://www.geidcp.com/api/file/pub/cms/2021/05/10/c8db4efaf7fa4b49adf515b9334f2e77.pdf"></web-view> -->
		<view class="pdfBox" v-if="this.pdfUrl == ''" style="text-align: center">{{$t('common.NoFile')}}</view>
	</view>
</template>

<script>
	import pdf from "@/static/pdf/build/pdf"
	export default {
		props: {

			baseEntityId: '',
		},
		data() {
			return {
				isLogin: false,
				token: '',
				info4: [],
				pdfUrl: '',


			}
		},
		mounted() {
			this.token = uni.getStorageSync('Auth-Token') ? uni.getStorageSync('Auth-Token') : '';
			// this.getUrl();
			this.tab4()
			console.log('this.baseEntityId')
			console.log(this.baseEntityId)
		},

		methods: {


			// getUrl() {
			// 	if (this.pdfUrl) {
			// 		console.log('this.pdfUrl')
			// 		console.log(this.pdfUrl)
			// 	}
			// },

			async tab4(baseEntityId) {
				const res = await this.$myRequest({
					url: '/cms/cmsInformationViews/getInformationList/',
					data: {
						pageSize: 5,
						pageNo: 1,
						businessType: 'countryShow',
						businessId: this.baseEntityId,
						typeDict: 8,
						language: this.$i18n.locale.toUpperCase()
					}
				});
				if (res.data.allDataList.length != 0) {
					this.info4 = res.data ? res.data.allDataList[0] : [];
					this.pdfUrl = this.info4.pdfPath ? this.info4.pdfPath : '';
					// this.pdfUrl = this.info4 ?pdfPath ? 'api/file/pub/' + this.info4 ? pdfPath : '':'';
				}
				console.log('info4', res)
				console.log('this.pdfUrl', this.pdfUrl)
			},
			download(path, fileName) {
				console.log('path,fileName')
				console.log(path, fileName)
				// const downloadTask = uni.downloadFile({
				uni.downloadFile({
					url: 'https://m.geidcp.com/api/file/pub/' + path, //下载地址接口返回
					success: (data) => {
						console.log(data)
						if (data.statusCode === 200) {
							//文件保存到本地
							uni.saveFile({
								tempFilePath: data.tempFilePath, //临时路径
								success: function(res) {
									uni.showToast({
										icon: 'none',
										mask: true,
										title: '文件已保存：' + res.savedFilePath, //保存路径
										duration: 3000,
									});
									setTimeout(() => {
										//打开文档查看
										uni.openDocument({
											filePath: res.savedFilePath,
											success: function(res) {
												// console.log('打开文档成功');
											}
										});
									}, 3000)
								}
							});
						}
					},
					fail: (err) => {
						console.log(err);
						uni.showToast({
							icon: 'none',
							mask: true,
							title: '	',
						});
					},
				});
				// downloadTask.onProgressUpdate((res) => {
				//     console.log('下载进度' + res.progress);
				//     console.log('已经下载的数据长度' + res.totalBytesWritten);
				//     console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite);
				//
				//     // 测试条件，取消下载任务。
				//     if (res.progress > 50) {
				//         downloadTask.abort();
				//     }
				// });
				// console.log('下载成功', 'https://localhost:8080/api/file/pub/' + path);
			},


		}
	}
</script>

<style scoped>
	.pdfBox {
		width: 100%;
		height: 50upx;

	}

	.footerText {
		text-align: center;
		color: #0c27ff;
		padding-bottom: 10px;

	}

	.loginText {
		cursor: pointer;
	}

	.pdfStyle {
		position: absolute;
		display: block;
		border: 0px;
		top: 0;
		left: 0px;
		width: 375px;
		height: 623px;
		z-index: 999;

	}

	.fileDown {
		width: 100%;
		padding: 20upx 0 40upx;

	}
</style>
