<template>
	<view class="detail-page">
		<!-- PDF 预览 -->
		<web-view v-if="fileType === 'pdf' && fileUrl" :src="fileUrl"></web-view>

		<!-- 图片预览 -->
		<scroll-view v-else-if="fileType === 'image' && fileUrl" scroll-y class="image-scroll">
			<image class="contract-image" :src="fileUrl" mode="widthFix" @click="previewImage" />
		</scroll-view>

		<view class="empty" v-else>暂无合同文件</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			fileType: '',
			fileUrl: '',
		}
	},
	onLoad(query) {
		this.fileType = query.fileType || 'pdf'
		this.fileUrl = decodeURIComponent(query.fileUrl || '')
		if (query.title) {
			uni.setNavigationBarTitle({ title: query.title })
		}
	},
	methods: {
		previewImage() {
			if (!this.fileUrl) return
			uni.previewImage({
				urls: [this.fileUrl],
				current: this.fileUrl,
			})
		},
	},
}
</script>

<style lang="scss" scoped>
.detail-page {
	min-height: 100vh;
	background: #f5f5f5;
}

.image-scroll {
	height: 100vh;
}

.contract-image {
	width: 100%;
	display: block;
}

.empty {
	text-align: center;
	padding: 120rpx 0;
	font-size: 28rpx;
	color: #999;
}
</style>
