<template>
|
<view class="page">
|
<!-- 通知栏 -->
|
<uni-notice-bar show-icon text="仅能查出该亲友最新的体检报告哦!" class="notice-bar" />
|
|
<!-- 报告列表 -->
|
<scroll-view scroll-y class="report-list" v-if="reports.length > 0">
|
<view class="card" v-for="(report, index) in reports" :key="report.tjNum" @click="ReportDetails(report)">
|
<view class="card-inner">
|
<view class="card-left">
|
<text class="name">{{ report.name || '未知姓名' }}</text>
|
<text class="sex">{{ report.sex || '未知性别' }}</text>
|
</view>
|
<view class="card-right">
|
<view class="info">
|
<text class="time">{{ report.time || '未知时间' }}</text>
|
<text class="hospital">泾川县人民医院体检中心</text>
|
<text class="tj-num">体检号:{{ report.tjNum }}</text>
|
</view>
|
<view class="label">
|
<text class="label-text">体检报告</text>
|
</view>
|
</view>
|
</view>
|
</view>
|
</scroll-view>
|
|
<!-- 无数据提示 -->
|
<view v-else class="no-data">
|
<text>暂无体检报告</text>
|
</view>
|
</view>
|
</template>
|
|
<script>
|
import { PDF } from "@/api/system/report";
|
|
export default {
|
name: 'FriendReportOverview',
|
data() {
|
return {
|
reports: [],
|
customer: null,
|
};
|
},
|
onLoad(option) {
|
if (option.reportData) {
|
const reportData = JSON.parse(decodeURIComponent(option.reportData));
|
console.log('Parsed reportData:', reportData);
|
this.reports = reportData;
|
this.customer = { name: reportData[0]?.name };
|
}
|
},
|
methods: {
|
ReportDetails(report) {
|
uni.showLoading({ title: '加载中...' });
|
// uni.navigateTo({
|
// url: `/pages/ReportDetails/ReportBaogao?tjNum=${report.tjNum}`,
|
// });
|
PDF({ tjNum: report.tjNum })
|
.then((res) => {
|
console.log('PDF response:', res);
|
|
// 检查 res.msg 是否存在
|
if (!res.msg || typeof res.msg !== 'string') {
|
console.error('无效的 PDF 文件路径:', res.msg);
|
uni.showToast({ title: 'PDF 文件路径无效', icon: 'none', duration: 3000 });
|
uni.hideLoading();
|
return;
|
}
|
|
// 动态拼接 PDF URL
|
const pdfUrl = `${window.location.origin}/report-file/${encodeURIComponent(res.msg)}`;
|
const fileName = `${res.msg}`;
|
const isWeChat = /MicroMessenger/i.test(navigator.userAgent);
|
|
try {
|
if (isWeChat) {
|
const downloadLink = document.createElement('a');
|
downloadLink.href = pdfUrl;
|
downloadLink.download = fileName;
|
document.body.appendChild(downloadLink);
|
downloadLink.dispatchEvent(new MouseEvent('click', { view: window, bubbles: true, cancelable: true }));
|
document.body.removeChild(downloadLink);
|
} else {
|
const newWindow = window.open('', '_blank');
|
if (!newWindow) {
|
const downloadLink = document.createElement('a');
|
downloadLink.href = pdfUrl;
|
downloadLink.download = fileName;
|
downloadLink.dispatchEvent(new MouseEvent('click', { view: window, bubbles: true, cancelable: true }));
|
return;
|
}
|
|
newWindow.document.write(`
|
<html>
|
<head>
|
<title>PDF 预览</title>
|
<style>
|
html, body { margin: 0; height: 100%; }
|
iframe { width: 100%; height: 100%; border: none; }
|
</style>
|
</head>
|
<body>
|
<iframe src="${pdfUrl}"></iframe>
|
<div style="text-align:center; margin:20px;">
|
<a href="${pdfUrl}" download="${fileName}" style="color:#419ffd;font-size:16px;">
|
若无法预览,请点击此处下载 PDF
|
</a>
|
</div>
|
</body>
|
</html>
|
`);
|
newWindow.document.close();
|
}
|
} catch (e) {
|
console.error('PDF 预览失败:', e);
|
uni.showToast({ title: '预览失败,请重试', icon: 'none', duration: 3000 });
|
} finally {
|
uni.hideLoading();
|
}
|
})
|
.catch((err) => {
|
uni.hideLoading();
|
console.error('PDF 接口错误:', err);
|
uni.showToast({
|
title: err?.data?.message || '获取 PDF 失败,请稍后重试',
|
icon: 'none',
|
duration: 3000,
|
});
|
});
|
},
|
|
},
|
};
|
</script>
|
|
<style lang="scss">
|
.page {
|
width: 100%;
|
min-height: 100vh;
|
background: linear-gradient(180deg, #fff 10%, #f5f7fa 100%);
|
padding-bottom: 20rpx;
|
}
|
|
.notice-bar {
|
margin: 20rpx 30rpx;
|
border-radius: 16rpx;
|
background: rgba(255, 245, 230, 0.95);
|
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
|
font-size: 28rpx;
|
color: #e58e26;
|
}
|
|
.report-list {
|
height: calc(100vh - 120rpx);
|
padding: 0 30rpx;
|
}
|
|
.card {
|
margin-top: 30rpx;
|
}
|
|
.card-inner {
|
width: 100%;
|
height: 180rpx;
|
background: #ffffff;
|
border-radius: 20rpx;
|
box-shadow: 0 6rpx 16rpx rgba(0, 0, 0, 0.08);
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
transition: transform 0.2s ease;
|
}
|
|
.card-inner:active {
|
transform: scale(0.98);
|
}
|
|
.card-left {
|
width: 140rpx;
|
height: 100%;
|
display: flex;
|
flex-direction: column;
|
justify-content: center;
|
align-items: center;
|
border-right: 2rpx dashed #e0e0e0;
|
}
|
|
.name {
|
font-size: 34rpx;
|
font-weight: 600;
|
color: #333;
|
margin-bottom: 10rpx;
|
}
|
|
.sex {
|
font-size: 26rpx;
|
color: #888;
|
}
|
|
.card-right {
|
flex: 1;
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
padding: 20rpx 0;
|
}
|
|
.info {
|
padding: 0 30rpx;
|
display: flex;
|
flex-direction: column;
|
gap: 12rpx;
|
}
|
|
.time {
|
font-size: 28rpx;
|
color: #666;
|
}
|
|
.hospital {
|
font-size: 26rpx;
|
color: #999;
|
}
|
|
.tj-num {
|
font-size: 28rpx;
|
color: #fd8b4d;
|
font-weight: 500;
|
}
|
|
.label {
|
width: 80rpx;
|
height: 100%;
|
background: linear-gradient(135deg, #fd8b4d, #ffaa70);
|
border-radius: 0 20rpx 20rpx 0;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
padding: 22rpx;
|
}
|
|
.label-text {
|
font-size: 30rpx;
|
color: #fff;
|
font-weight: 600;
|
writing-mode: vertical-rl;
|
letter-spacing: 4rpx;
|
}
|
|
.no-data {
|
height: calc(100vh - 120rpx);
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
font-size: 32rpx;
|
color: #999;
|
}
|
</style>
|