import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { NavController } from '@ionic/angular';

@Component({
  selector: 'app-eye-exam',
  templateUrl: './eye-exam.page.html', // 确保这里使用了正确的模板文件路径
  styleUrls: ['./eye-exam.page.scss']
})
export class EyeExamPage implements OnInit {
  index: number = -1; // 给 index 一个默认值
  report: any;

  constructor(private route: ActivatedRoute, private navController: NavController) {}

  ngOnInit() {
    const paramMap = this.route.snapshot.paramMap;
    if (paramMap) {
      const indexParam = paramMap.get('index');
      if (indexParam !== null) {
        this.index = +indexParam;
        // 假设你有一个方法来获取报告数据
        this.report = this.getReportData(this.index);
      } else {
        console.error('Invalid index parameter.');
      }
    } else {
      console.error('Route snapshot paramMap is null or undefined.');
    }
  }

  getReportData(index: number): any {
    // 这里模拟从服务中获取报告数据
    return {
      title: '眼科检查报告',
      date: new Date(),
      details: '<p>视力良好，无异常。</p><p>建议定期复查。</p>',
      attachments: [
        { url: 'https://example.com/attachment1.jpg', name: '附件1' },
        { url: 'https://example.com/attachment2.jpg', name: '附件2' }
      ]
    };
  }

  goBack() {
    this.navController.navigateBack('/tabs/tab3'); // 返回到 tab3
  }
}