<!--
  @description: 公告信息弹框-采购单审核及中选结果审批时，增加一个“公告预览”的按钮，点击后弹出展示对外的公告页面
  @Modifier: haofengxian
  @routerPath:
  @date: 2021-3-5-15:03
-->
<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>
/* api接口*/
import { getTemplate } from '@api/procurement/procurementResult'
import { queryBaseProcurementProjectInfo } from '@/api/procurement/procurementProject'
/* pdf*/
import { queryPublicityListByPackId } from '@/api/procurement/procurementResult' // 获取成交结果公告列表
import { getFileDetail } from '@/api/common/uploadCenter' // 文件下载方法
import { readImageRoot } from '@api/common/uploadCenter' // 图片查看路径
/* 组件*/
import pdf from '@comp/common/pdf/pdf'
export default {
  name: 'ProcurementProjectLetterDialog',
  components: { pdf },
  data() {
    return {
      dialogVisible: false, // 弹框是否打开
      contentText: '', // html 文件
      pdfUrl: '',
      isPdf: true,
      readImageUrl: readImageRoot
    }
  },
  methods: {
    // 获取项目信息
    resultNoticeLoad() {
      this.dialogVisible = true
      const tenderId = this.$route.query.id
      queryBaseProcurementProjectInfo({ tenderId: tenderId }).then(res => {
        this.tenderBase = res.data
        this.getProjectNotice(tenderId)
      })
    },
    // 获取结果公告项目信息
    getProjectNotice(tenderId) {
      queryPublicityListByPackId(this.tenderBase.packId).then((res) => {
        const params = {
          bizId: res.data.length > 0 && res.data[0].id,
          fileType: 'prot_procurement_result_bulletin_pdf'
        }
        getFileDetail(params).then((response) => {
          this.isPdf = response.data.length > 0
          if (response.data.length > 0) {
            const url = this.readImageUrl + response.data[0].path
            this.pdfUrl = encodeURIComponent(url)
          }
        })
      })
      getTemplate(tenderId, this.tenderBase.packId).then(res => {
        // 获取公告html文本
        this.contentText = res.data
      }).catch(() => {
      })
    }
  }
}
</script>

<style scoped>

</style>
