<!--
  @description:供应商-报价-提交报价
  @Modifier:gmy
  @date:2021/2/18-12:30
-->
<template>
  <div>
    <el-dialog
      v-dialogDrag
      :visible.sync="dialogData.dialog"
      :close-on-click-modal="false"
      title="报价单"
      width="1180px"
      append-to-body
      top="calc((5vh) / 2)"
      custom-class="el-dialog__body-p0"
    >
      <!-- pdf报价单查看 -->
      <pdf
        :pdf-url="pdfUrl"
      />
      <!--底部操作按钮-->
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancelDialog">
          关闭
        </el-button>
        <!-- 签章暂时隐藏 -->
        <!-- <template v-if="isEdit">
          <el-button :loading="confirmLoading" @click="signatureClick">
            电子签章
          </el-button>
          <el-button :loading="confirmLoading" type="primary" @click="submit">
            提交
          </el-button>
        </template> -->
      </span>
    </el-dialog>
  </div>
</template>

<script>
/* api接口 */
import { procurementOfferMixin } from '../mixins/procurementOfferMixin' // 公共方法
/* 公共组件 */
import pdf from '@comp/common/pdf/pdf'
// import pdfSignature from '@comp/procurement/pdf/pdf' // pdf签章
import { readImageRoot } from '@api/common/uploadCenter' // 文件预览下载//根路径+路径
import { getFileDetail } from '@/api/common/uploadCenter'
export default {
  name: 'ConsignContractSelectDialog',
  inject: ['driveReload', 'getTenderBase'],
  components: {
    pdf
    // pdfSignature // 报价签章
  },
  mixins: [procurementOfferMixin],
  props: {
    // 弹框展示状态
    dialogData: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      isEdit: true, // 是否可编辑 true 可编辑 false 不可编辑
      confirmLoading: true, // 按钮loading
      readImageUrl: readImageRoot, // 文件预览下载//根路径+路径
      pdfUrl: '', // pdf文件路径
      contentData: '',
      tenderBase: this.getTenderBase() // 获取项目信息

    }
  },
  mounted() {
    // 获取pdf
    this.GetFileDetail()
  },
  methods: {
    /*
    * 获取pdf请求
    * @params data {bizId:业务id,fileType:文件类型}
    * 返回查看的文件path前端处理地址后展示pdf
    */
    GetFileDetail() {
      const data = {
        bizId: this.dialogData.bizId,
        fileType: this.dialogData.fileType
      }
      // 报价单无filePath
      getFileDetail(data)
        .then(res => {
          // signatureClass 区分报价单和应答文件 00 报价单 01应答文件
          if (this.dialogData.signatureClass === '01') {
            const filePath = res.data.find(fileItem => fileItem.fileId === this.dialogData.fileId).path
            const url = this.readImageUrl + filePath
            this.pdfUrl = encodeURIComponent(url)
            return
          }
          const url = this.readImageUrl + res.data[0].path
          this.pdfUrl = encodeURIComponent(url)
        })
        .catch(() => {})
    },
    // 关闭弹框
    cancelDialog() {
      this.dialogData.dialog = false
    },
    // ==================================签章功能暂时不用后期签章在开发============================================
    // 签章成功之后的回调
    reloadDriver(val) {
      if (val) {
        // 重新加载pdf
        this.GetFileDetail()
        this.isEdit = false
      }
    },
    // 扫码获取签章
    signatureClick() {
      this.$refs.pdfSignature.signatureClick()
    },
    // 提交
    submit() {
      this.$refs.pdfSignature.GetStamps()
    },
    // 签章回调
    insertBack(data) {
      // 按钮状态
      this.confirmLoading = data.laoding
    }
  }
  // ==================================签章功能暂时不用后期签章在开发============================================
}
</script>

<style scoped lang="less">
</style>
