<!--
  @description: 中选结果通知书
  @Modifier: haofengxian
  @routerPath:
  @date: 2021-3-23-9:16
-->
<template>
  <el-dialog
    :visible.sync="dialogVisible"
    :lock-scroll="false"
    append-to-body
    title="中选通知书"
    width="1200px"
    custom-class="el-dialog__body-p8 el-dialog_table"
  >
    <pdf v-if="isPdf" :pdf-url="pdfUrl" />
    <div v-else v-html="contentText" />
    <!--底部操作按钮-->
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">关 闭</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { getNoticePdfAttachment } from '@/api/procurement/procurementResult' // 预览发送结果通知书接口
import { getNoticeHtmlByPackId } from '@/api/procurement/procurementResult'
/*  pdf*/
import { queryBaseProcurementProjectInfo } from '@/api/procurement/procurementProject'
import { getFileDetail } from '@/api/common/uploadCenter' // 文件下载方法
import { readImageRoot } from '@api/common/uploadCenter' // 图片查看路径
/* 组件*/
import pdf from '@comp/common/pdf/pdf'
export default {
  name: 'ProcurementWinningResultNoticeDialog',
  components: { pdf },
  props: {
    supplierId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      dialogVisible: false, // 弹框是否打开
      contentText: '', // html 文件
      pdfUrl: '',
      isPdf: true,
      readImageUrl: readImageRoot
    }
  },
  methods: {
    // 获取项目信息
    winningResultNoticeLoad() {
      this.dialogVisible = true
      const tenderId = this.$route.query.id
      queryBaseProcurementProjectInfo({ tenderId: tenderId }).then((res) => {
        this.tenderBase = res.data
        this.getProjectNotice(tenderId)
      })
    },
    // 查询通知书html
    getProjectNotice() {
      const DATA = {
        packId: this.tenderBase.packId,
        supplierId: this.supplierId
      }
      getNoticePdfAttachment(DATA).then((res) => {
        const params = {
          bizId: res.data.bizId,
          fileType: 'pro_procurement_notice_template_base'
        }
        getFileDetail(params).then((response) => {
          this.isPdf = response.data.length > 0
          const url = this.readImageUrl + response.data[0].path
          // 加密处理
          this.pdfUrl = encodeURIComponent(url)
        })
      })
      getNoticeHtmlByPackId(this.tenderBase.packId)
        .then((res) => {
          // 获取公告html文本
          this.contentText = res.data
        })
        .catch(() => {})
    }
  }
}
</script>

<style scoped>
</style>
