<template>
  <div>
    <layout-card>
      <div v-if="loading">加载中...</div>
      <div v-else>
        <layout-pdf
          v-model:visible="pdfDialog.visible"
          :src="pdfDialog.src"
          append-to-body
        ></layout-pdf>
      </div>
    </layout-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import { useRoute } from "vue-router";
import LayoutPdf from "@/components/pdf/index.vue";
import { infoAssessmentView } from "@/request/traffic_safety_assessment.js";

const VITE_FILE_URL = import.meta.env.VITE_FILE_URL;
const route = useRoute();
const SAFETYASSESSMENT_ID = route.query.SAFETYASSESSMENT_ID;
const loading = ref(true); // 用于指示文件是否正在加载
const pdfDialog = ref({ visible: false, src: "" });

onMounted(async () => {
  const response = await infoAssessmentView({ SAFETYASSESSMENT_ID });
  if (response.pd && response.pd.ATTACHMENT_ROUTE) {
    pdfDialog.value.src = VITE_FILE_URL + response.pd.ATTACHMENT_ROUTE;
    pdfDialog.value.visible = true;
  }
  loading.value = false; // 加载完成
});
</script>

<style scoped></style>
