<!--
  @description:采购/供应商驱动采购公告/邀请函查看
  @Modifier:gmy
  @routerPath:/procurement/procurementDriveSupplier/procurementParticpatingNotice 供应商
  @routerPath:/procurement/procurementDrive/procurementView/procurementParticpatingNotice采购员
  @date:2020/8/25-11:27
-->
<template>
  <div class="p16">
    <pdf v-if="isPdf" :pdf-url="pdfUrl" />
    <div v-else v-html="contentText" />
  </div>
</template>
<script>
/* api*/
import { seeProjectNotice } from '@api/procurement/procurementBulletin'
import { lookInvitationAsk } from '@api/procurement/procurementInvitation'
import { readImageRoot } from '@api/common/uploadCenter' // 图片查看路径
import { getFileDetail } from '@/api/common/uploadCenter' // 文件下载方法

/* 组件*/
import pdf from '@comp/common/pdf/pdf'
export default {
  name: 'ProcurementParticpatingNoticeVue',
  components: { pdf },
  props: {
    // tenderType项目类型 00 公开 01 邀请
    tenderType: {
      type: String,
      default: ''
    },
    packId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      pdfUrl: '',
      isPdf: true,
      readImageUrl: readImageRoot,
      contentText: '' // html 文件
    }
  },
  mounted() {
    // 获取项目信息 tenderType项目类型 00 公开 01 邀请
    // 获取采购方式确定文件类型
    // 00 公开 01邀请
    if (this.tenderType === '00') {
      // 调用请求公开公告请求
      this.getProjectNotice()
    } else {
      // 调用请求邀请函公告请求
      this.getProjectNoticeh()
    }
  },
  methods: {
    // 获取采购公告项目信息
    async getProjectNotice() {
      seeProjectNotice(this.packId).then((res) => {
        const params = {
          bizId: res.data.id,
          fileType: 'prot_procurement_bulletin_and_change_pdf'
        }
        getFileDetail(params).then((response) => {
          this.isPdf = response.data.length > 0
          const url = this.readImageUrl + response.data[0].path
          this.pdfUrl = encodeURIComponent(url)
        })
        // 获取公告html文本
        this.contentText = res.data.contentText
      })
    },
    // 获取邀请函项目信息
    async getProjectNoticeh() {
      lookInvitationAsk(this.packId).then((res) => {
        const params = {
          bizId: res.data.id,
          fileType: 'prot_procurement_invitation_bulletin_pdf'
        }
        getFileDetail(params).then((response) => {
          this.isPdf = response.data.length > 0
          const url = this.readImageUrl + response.data[0].path
          this.pdfUrl = encodeURIComponent(url)
        })
        // 获取公告html文本
        this.contentText = res.data.contentText
      })
    }
  }
}
</script>

<style scoped>
</style>
