
<!--
  @description: 成交通知书-预览模板
  @author: wxy/gmy
  @routerPath:/procurement/procurementDrive/procurementAdvicenoteResult
  @date: 2020-7-6 10:03:58
-->
<template>
  <div>
    <div class="main">
      <pdf v-if="isPdf" :pdf-url="pdfUrl" />
      <div v-else class="clearfix" v-html="htmlContent" />
    </div>
    <!--关闭按钮-->
    <div class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <!-- 关闭 -->
          <gx-button :code="'001_009_002'" @click="adviceClose">
            关 闭
          </gx-button>
          <!-- 导出 -->
          <gx-button :code="'001_009_003'" type="primary" @click="adviceDerive">
            导 出
          </gx-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
/* api接口*/
import { queryNoticeOrSupplier, getNoticePdfAttachment } from '@/api/procurement/procurementResult' // 预览发送结果通知书接口
import { downLoadFile } from '@/api/common/uploadCenter' // 前端文件下载接口
import { readImageRoot } from '@api/common/uploadCenter' // 图片查看路径
import { getFileDetail } from '@/api/common/uploadCenter' // 文件下载方法
/* 组件*/
import pdf from '@comp/common/pdf/pdf'
/*  公共方法 */
import { download } from '@/assets/js/utils'
export default {
  name: 'ProcurementProjectAdd',
  components: { pdf },
  inject: ['getTenderBase'],
  data() {
    return {
      confirmLoading: false,
      htmlContent: '', // 通知书html
      tenderBase: this.getTenderBase(), // 获取项目信息
      isPdf: true,
      pdfUrl: '',
      readImageUrl: readImageRoot
    }
  },
  watch: {
  },
  created() {
    this.initNoticeInfo()
  },
  methods: {
    // 查询成交通知书条件
    searchData() {
      const searchData = {
        winningResultId: this.$route.query.winningResultId,
        supplierId: this.$route.query.supplierId
      }
      return searchData
    },
    // 导出
    adviceDerive() {
      // 调用获取附件信息
      this.getNoticePdfAttachmentData()
    },
    // 关闭按钮
    adviceClose() {
      this.$router.push({ path: '/procurement/procurementDrive/procurementAdvicenoteList' })
    },
    // 获取成交通知书信息
    initNoticeInfo() {
      const data = this.searchData() // 获取查询条件
      if (!data.winningResultId || !data.supplierId) {
        this.$message.warning('缺少必填参数')
        return
      }
      const DATA = {
        packId: this.tenderBase.packId,
        supplierId: this.$route.query.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)
        })
      })
      queryNoticeOrSupplier(data).then(res => {
        this.htmlContent = res.data
      })
    },
    // 获取中选通知书附件信息
    getNoticePdfAttachmentData() {
      const data = {
        packId: this.tenderBase.packId,
        supplierId: this.$route.query.supplierId
      }
      getNoticePdfAttachment(data).then(response => {
        const fileData = {
          fileId: response.data.fileId,
          fileType: response.data.fileType
        }
        this.setDownLoadFile(fileData)
      })
    },
    // 文件下载请求
    setDownLoadFile(data) {
      downLoadFile(data).then(res => {
        download(res, '【' + this.tenderBase.tenderName + '】成交通知书文件.pdf')
      })
    }
  }
}
</script>

<style lang="less" scoped>

  /deep/.show-word-limit-padding{
    .el-input__inner{
      padding-right: 70px;
    }
  }
</style>
