<template>
    <el-dialog v-model="visible" width="90%" append-to-body title="综合表彰材料">
        <auth-img v-for="src in imgUrl" :key="src.title" :authSrc="src.url" style="height:1000px;"></auth-img>
    </el-dialog>
</template>

<script setup lang="ts">
  import { ref, nextTick, defineAsyncComponent } from 'vue';
  const authImg = defineAsyncComponent(() => import('/@/components/tools/auth-img.vue'))

  interface ImageItem {
    title: string
    url: string
  }

  // 响应式数据
  const visible = ref(false)
  const row = ref<any>({})
  const pdfSrc = ref('')
  const imgUrl = ref<ImageItem[]>([])

  // 方法（保留以备将来使用）
  // const checkIsImg = (url: string) => {
  //   if ((url.indexOf('.jpg') == -1)
  //     && (url.indexOf('.jpeg') == -1)
  //     && (url.indexOf('.png') == -1)
  //     && (url.indexOf('.JPG') == -1)
  //     && (url.indexOf('.JPEG') == -1)
  //     && (url.indexOf('.PNG') == -1)) {
  //     return false
  //   }
  //   return true
  // }

  // const downLoadFileForLook = (fileUrl: string, teacherNo: string) => {
  //   const index = fileUrl.indexOf('fileName')
  //   const firstIndex = index + 'fileName'.length + 1
  //   const lastIndex = fileUrl.indexOf('&')
  //   const fileName = fileUrl.substr(firstIndex, lastIndex - firstIndex)
  //   pdfSrc.value = "/professional/file/showPdf?fileName=" + fileName + "&type=attachment&teacherNo=" + teacherNo
  // }

  const init = (rowData: any) => {
    row.value = rowData
    pdfSrc.value = ''
    imgUrl.value = []
    nextTick(() => {
      const obj: ImageItem = {
        title: "",
        url: row.value.attachment
      }
      imgUrl.value.push(obj)
      // if(checkIsImg(rowData.attachment)){
      //   const obj: ImageItem = {
      //     title: "",
      //     url: row.value.attachment
      //   }
      //   imgUrl.value.push(obj)
      // }else{
      //   downLoadFileForLook(rowData.attachment, rowData.teacherNo)
      // }
      visible.value = true
    })
  }

  // 暴露方法给父组件
  defineExpose({
    init
  })
</script>

<style scoped>

</style>
