1
wwl
2025-07-31 c3c6cf8cb3f73755ac9fad29f2b2c0cf64f27979
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
<template>
    <div class="container">
        <image class="bg-image" src="/static/images/tabbar/loginbg.png" mode="scaleToFill"></image>
        <u-tabs :list="list1" @click="click"></u-tabs>
        <template v-if="index == 0">
            <scroll-view scroll-y class="report-list" v-if="reports.length > 0">
                <view class="card" v-for="(report, index) in reports" :key="report.tjNum">
                    <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">{{ hospName || '未知医院' }}</text>
                                <text class="tj-num">体检号:{{ report.tjNum }}</text>
                            </view>
                            <view class="label">
                                <text class="label-text">体检报告</text>
                            </view>
                        </view>
                    </view>
                    <view class="button-group">
                        <view class="action-button open-pdf" @click.stop="openPDF(report)">打开PDF</view>
                        <view class="action-button go-report" @click.stop="goToReportBaogao(report)">查看报告详情</view>
                    </view>
                </view>
            </scroll-view>
            <template v-else>
                <u-empty mode="list" icon="http://cdn.uviewui.com/uview/empty/car.png"></u-empty>
            </template>
        </template>
        <template v-if="index == 1">
            <u-alert :title="title" type="warning"></u-alert>
            <div class="formbox">
                <u-form :model="formData" ref="uForm" :rules="rules" :label-width="200">
                    <u-form-item label="体检人姓名" prop="cusName" required>
                        <u--input placeholder="请输入姓名" border="surround" v-model="formData.cusName" maxlength="5"
                            @input="trimSpaces('cusName', $event)"></u--input>
                    </u-form-item>
                    <u-form-item label="身份证号码" prop="idcard" required>
                        <u--input placeholder="请输入身份证号" border="surround" v-model="formData.idcard" maxlength="18"
                            @input="trimSpaces('idcard', $event)"></u--input>
                    </u-form-item>
                </u-form>
            </div>
            <div @click="submit" class="chaxun">查询</div>
        </template>
    </div>
</template>
 
<script>
import { getRelativeReportList, PDF } from "@/api/system/report";
 
export default {
  data() {
    return {
      reports: [],
      index: 0,
      list1: [
        { name: '报告查询' },
        { name: '亲友查询' },
      ],
      title: "仅能查出该亲友最新体检报告哦",
      formData: {
        cusName: '',
        idcard: '',
      },
      rules: {
        cusName: [
          { required: true, message: '姓名不能为空', trigger: 'blur' }
        ],
        idcard: [
          { required: true, message: '身份证号不能为空', trigger: 'blur' },
          {
            validator: (rule, value, callback) => {
              const idCardReg = /^[1-9]\d{5}(19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
              if (!value) return callback(new Error('身份证号不能为空'));
              if (!idCardReg.test(value)) return callback(new Error('身份证号格式不正确'));
 
              const factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
              const checkCode = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
              let sum = 0;
              for (let i = 0; i < 17; i++) {
                sum += parseInt(value.charAt(i)) * factor[i];
              }
              const mod = sum % 11;
              const lastChar = value.charAt(17).toUpperCase();
              if (checkCode[mod] !== lastChar) {
                return callback(new Error('身份证号校验码错误'));
              }
              callback();
            },
            trigger: 'blur',
          },
        ],
      },
      hospName: '' // 存储医院名称
    };
  },
  created() {
    // 从本地存储获取 hospName
    this.hospName = uni.getStorageSync('hospName') || '未知医院';
 
    // H5环境下通过路由参数获取 orderList 和 sfzh
    // const { orderList, sfzh } = this.$route.query;
    // this.reports = orderList ? JSON.parse(decodeURIComponent(orderList)) : [];
    let sfzh = JSON.parse(localStorage.getItem('sfzh'))
    let orderList = JSON.parse(localStorage.getItem('orderList'))
     this.reports = orderList ? JSON.parse(localStorage.getItem('orderList')) : [];
    if (sfzh) {
      console.log('查询中...');
      getRelativeReportList({ card: sfzh })
        .then((response) => {
          console.log('查询完成');
          if (!response.data || response.data.length === 0) {
            uni.showToast({ title: '暂无体检报告!', icon: 'none', duration: 2000 });
          } else {
            this.reports = response.data;
          }
        })
        .catch(() => {
          console.log('查询完成');
          uni.showToast({ title: '查询失败,请稍后重试', icon: 'none', duration: 2000 });
        });
    }
  },
  methods: {
    click(item) {
      this.index = item.index;
      if (this.index === 1) {
        this.formData = {
          cusName: '',
          idcard: ''
        };
        this.$nextTick(() => {
          if (this.$refs.uForm) {
            this.$refs.uForm.setRules(this.rules);
            this.$refs.uForm.clearValidate();
          }
        });
      }
    },
    trimSpaces(field, value) {
      const trimmedValue = value.replace(/\s/g, '');
      if (this.formData[field] !== trimmedValue) {
        this.formData[field] = trimmedValue;
      }
    },
    submit() {
      if (!this.$refs.uForm) {
        uni.showToast({ title: '表单未加载', icon: 'none', duration: 2000 });
        return;
      }
      this.$refs.uForm.validate().then(() => {
        const { cusName, idcard } = this.formData;
        console.log('查询中...');
        getRelativeReportList({ card: idcard, name: cusName })
          .then((response) => {
            console.log('查询完成');
            if (!response.data || response.data.length === 0) {
              uni.showToast({ title: '该亲友暂无体检报告!', icon: 'none', duration: 2000 });
            } else {
              // const reportData = encodeURIComponent(JSON.stringify(response.data));
                uni.setStorageSync('reportData', JSON.stringify(response.data)); 
              this.$router.push({
                path: '/pages/friendReportOverview/friendReportOverview',
                // query: { reportData }
              });
            }
          })
          .catch(() => {
            console.log('查询完成');
            uni.showToast({ title: '查询失败,请稍后重试', icon: 'none', duration: 2000 });
          });
      }).catch(() => {
        uni.showToast({ title: '请检查输入信息是否正确', icon: 'none', duration: 2000 });
      });
    },
    async openPDF(report) {
      console.log('加载中...', { tjNum: report.tjNum });
      try {
        const res = await PDF({ tjNum: report.tjNum });
        console.log('PDF response:', res);
 
        if (!res.msg || typeof res.msg !== 'string') {
          console.error('无效的 PDF 文件路径:', res.msg);
          uni.showToast({ title: 'PDF 文件路径无效', icon: 'none', duration: 2000 });
          console.log('加载完成');
          return;
        }
 
        // 构造 PDF URL
        const pdfPath = encodeURIComponent(res.msg);
        const isTestEnv = process.env.VUE_APP_ENV === 'test' || process.env.NODE_ENV === 'development';
        const pdfUrl = isTestEnv
          ? `http://ltpeis.xaltjdkj.cn:5904/report-file/${pdfPath}`
          : `${window.location.origin}/report-file/${pdfPath}`;
        const fileName = res.msg;
        console.log('Generated PDF URL:', pdfUrl);
 
        // 测试 URL 状态码
        try {
          const response = await fetch(pdfUrl, {
            method: 'HEAD',
            credentials: 'include'
          });
          console.log('URL 状态码:', response.status);
 
          if (response.status === 404) {
            uni.showToast({ title: '文件不存在,请联系管理员', icon: 'none', duration: 2000 });
            console.log('加载完成');
            return;
          }
 
          if (response.status >= 300 && response.status < 400) {
            const redirectUrl = response.headers.get('Location') || '未知重定向地址';
            console.warn('URL 被重定向:', redirectUrl);
            uni.showToast({ title: `文件请求被重定向到: ${redirectUrl}`, icon: 'none', duration: 2000 });
            console.log('加载完成');
            return;
          }
 
          if (response.status !== 200) {
            console.error('URL 请求失败,状态码:', response.status);
            uni.showToast({ title: `无法访问文件,状态码: ${response.status}`, icon: 'none', duration: 2000 });
            console.log('加载完成');
            return;
          }
 
          // 状态码为 200,尝试打开 PDF
          const newWindow = window.open(pdfUrl, '_blank');
          if (!newWindow) {
            console.warn('窗口被阻止,尝试下载PDF');
            const downloadLink = document.createElement('a');
            downloadLink.href = pdfUrl;
            downloadLink.download = fileName;
            downloadLink.dispatchEvent(new MouseEvent('click', { view: window, bubbles: true, cancelable: true }));
            uni.showToast({ title: '窗口被阻止,已触发下载', icon: 'none', duration: 2000 });
            console.log('加载完成');
            return;
          }
 
          // 检查是否被重定向
          setTimeout(() => {
            try {
              const currentUrl = newWindow.location.href;
              console.log('新窗口当前 URL:', currentUrl);
              if (
                currentUrl === 'about:blank' ||
                currentUrl === window.location.origin + '/' ||
                currentUrl.includes('select-hospital') ||
                newWindow.closed
              ) {
                console.warn('新窗口可能被重定向或加载失败,尝试下载PDF');
                newWindow.close();
                const downloadLink = document.createElement('a');
                downloadLink.href = pdfUrl;
                downloadLink.download = fileName;
                downloadLink.dispatchEvent(new MouseEvent('click', { view: window, bubbles: true, cancelable: true }));
                uni.showToast({ title: 'PDF 加载失败,已触发下载', icon: 'none', duration: 2000 });
              }
            } catch (e) {
              console.error('检查新窗口 URL 失败:', e);
              uni.showToast({ title: '无法加载 PDF,已触发下载', icon: 'none', duration: 2000 });
              newWindow.close();
              const downloadLink = document.createElement('a');
              downloadLink.href = pdfUrl;
              downloadLink.download = fileName;
              downloadLink.dispatchEvent(new MouseEvent('click', { view: window, bubbles: true, cancelable: true }));
            }
            console.log('加载完成');
          }, 2000);
        } catch (fetchError) {
          console.error('测试 URL 失败:', fetchError);
          uni.showToast({ title: '无法验证文件状态,请稍后重试', icon: 'none', duration: 2000 });
          console.log('加载完成');
        }
      } catch (err) {
        console.log('加载完成');
        console.error('PDF 接口错误:', err);
        uni.showToast({ title: err?.msg || '获取 PDF 失败,请稍后重试', icon: 'none', duration: 2000 });
      }
    },
    goToReportBaogao(report) {
      console.log('跳转到ReportBaogao', { tjNum: report.tjNum });
      localStorage.setItem('tjNum', JSON.stringify(report.tjNum));
      this.$router.push({
        path: '/pages/ReportBaogao/ReportBaogao',
        // query: { tjNum: report.tjNum }
      });
    }
  }
};
</script>
 
<style lang="scss" scoped>
/* 样式保持不变 */
::v-deep .u-alert__content__title {
  font-size: 26rpx !important;
  text-align: center !important;
}
 
.container {
  position: relative;
  min-height: 100vh;
  padding: 0;
  overflow: auto;
  box-sizing: border-box;
}
 
.bg-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: -1;
  left: 50%;
  transform: translateX(-50%);
  object-fit: cover;
}
 
.formbox {
  width: 80vw;
  max-width: 600px;
  margin: 246rpx auto 315rpx;
}
 
.chaxun {
  width: 80vw;
  max-width: 600px;
  margin: 0 auto;
  font-weight: 500;
  font-size: 16px;
  color: #ffffff;
  text-align: center;
  padding: 15px 0;
  background: #419ffd;
  border-radius: 8px;
  box-sizing: border-box;
}
 
@media (-webkit-min-device-pixel-ratio: 1) and (max-width: 750px) {
  .formbox {
    width: 600rpx;
    margin: 246rpx auto 315rpx;
  }
 
  .chaxun {
    width: 600rpx;
    font-size: 36rpx;
    padding: 31rpx 0;
    border-radius: 8rpx;
  }
}
 
@media screen and (min-width: 751px) {
  .chaxun {
    width: 80vw;
    max-width: 600px;
    font-size: 16px;
    padding: 15px 0;
    border-radius: 8px;
  }
}
 
::v-deep .u-form-item__body {
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-start !important;
}
 
::v-deep .u-form-item__body__left {
  margin-bottom: 38rpx !important;
}
 
::v-deep .u-form-item__body__left__content__label {
  font-size: 32rpx !important;
  color: #333 !important;
  white-space: nowrap !important;
}
 
::v-deep .u-form-item {
  margin-bottom: 62rpx !important;
}
 
::v-deep .u-form-item__body__right {
  width: 100% !important;
}
 
::v-deep .u-form-item__body__right__message {
  text-align: left !important;
  margin-top: 10rpx !important;
}
 
::v-deep .u-tabs__wrapper__nav__item {
  flex: 1 1 0% !important;
}
 
.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;
}
 
.button-group {
  display: flex;
  justify-content: space-between;
  padding: 20rpx 30rpx;
  margin-top: 10rpx;
}
 
.action-button {
  flex: 1;
  text-align: center;
  padding: 20rpx 0;
  font-size: 28rpx;
  color: #ffffff;
  border-radius: 8rpx;
  margin: 0 10rpx;
  cursor: pointer;
}
 
.open-pdf {
  background: #419ffd;
}
 
.go-report {
  background: #fd8b4d;
}
</style>