
<!--
  @description: 评标大厅-评审报表
  @Modifier：wxy/yf
  @routerPath:
  @date： 2020-08-05 21:28:26
-->
<template>
  <div>
    <!-- 当前评委会为组长 -->
    <div v-if="tenderBase.isEvalLeader === '01'" style="padding: 0">
      <!-- 不是组长不可编辑  -->
      <p v-if="!tenderBase.isEdit && tenderBase.isEvalLeader==='00'" style="color:red;margin:10px 0">
        提示：评标报告已经生成，共3位评委，共1位已经签章
      </p>
      <!-- 不是组长可编辑 -->
      <p v-if="tenderBase.isEdit && tenderBase.isEvalLeader==='00'" style="color:red;margin:10px 0">
        提示：请等待组长完成评标报告编辑！
      </p>
      <p v-if="tenderBase.isEdit && tenderBase.isEvalLeader==='01' && isTransferPdfFile==='00'" style="color:red;margin:10px 0">
        提示：评审已经完成，请尽快导入或手动编辑评标报告模板，格式为：*.doc ; *.docx。
      </p>
      <!-- 组长未转pdf签章 -->
      <editor v-if="tenderBase.isEvalLeader==='01' && isTransferPdfFile === '00'" v-model="reviewReportParam.content" class="mt16 editor" />
      <!-- 组长查看pdf页面 -->
      <pdfDetail v-if="isTransferPdfFile === '01' && !isPdfSignature" :pdf-url="pdfUrl" />
      <!-- pdf签章 -->
      <pdfSignature v-if="isPdfSignature&&isTransferPdfFile === '01'" :pdf-url="pdfUrl" :get-tender-base="tenderBase" @reloadDriver="reloadDriver" />
      <!-- 底部按钮 -->
      <div v-if="tenderBase.isEdit" class="but_footer">
        <div class="but_footer-h">
          <div class="but_footer-but">
            <!-- 初次上传按钮 -->
            <upload
              v-if="isUploadFile === '00'"
              ref="upload"
              :on-change="principalFile"
              :data="reviewReportFilsData"
              :auto-delete="true"
              :auto-upload="true"
              :show-file-list="false"
              :but-text="'导入评审报告'"
              :but-type="'primary'"
              :success="successList"
              accept=".doc,.docx"
              title=""
              file-ref="fileRef"
            />
            <!-- 再次上传 -->
            <el-button v-if="isUploadFile === '01'" :loading="loading" type="primary" size="medium" @click="uploadFile">
              导入评审报告
            </el-button>
            <!-- 已上传过评审word文件 -->
            <el-button :loading="loading" :disabled="(isUploadFile === '00'|| isTransferPdfFile === '01') ? true : false" type="primary" size="medium" @click="reportContentToPDF">
              转为PDF文件
            </el-button>
            <!-- <el-button :loading="loading" :disabled="(isUploadFile === '00'|| isTransferPdfFile === '00' || isPdfSignature) ? true : false" type="primary" size="medium" @click="electronicSignature">
              电子签章
            </el-button> -->
            <!-- <el-button :disabled="(isUploadFile === '00' || isTransferPdfFile === '00') ? true : false" type="primary" size="medium">完成签章</el-button> -->
            <el-button :loading="loading" :disabled="(isUploadFile === '00' || isTransferPdfFile === '00') ? true : false" size="medium" @click="exportReviewReport">
              导出评标报告
            </el-button>
          </div>
        </div>
      </div>
    </div>
    <!-- 当前评委会不为组长 -->
    <div v-else class="p0-16">
      <!--组长为转pdf-->
      <template v-if="isTransferPdfFile !== '01'">
        <button type="text" class="el-button mb10 el-button--text el-button--mini">
          <p style="color:red;margin:10px 0">
            提示:请等待组长完成评标报告编辑！
          </p>
        </button>
        <div class="noData">
          <img style="width:200px;height:160px" src="@assets/img/procurement/procurementEvaluation/avoid.png" alt="已回避">
          <p style="text-align:center;font-size:16px;margin-top:20px;width:210px">
            暂无数据
          </p>
        </div>
      </template>
      <template v-if="isTransferPdfFile === '01' && !isPdfSignature">
        <!-- 非组长查看pdf页面 -->
        <pdfDetail :pdf-url="pdfUrl" />
      </template>
      <!-- pdf签章 -->
      <pdfSignature v-if="isPdfSignature&&isTransferPdfFile === '01'" :pdf-url="pdfUrl" :get-tender-base="tenderBase" @reloadDriver="reloadDriver" />
      <div class="but_footer">
        <div class="but_footer-h">
          <div class="but_footer-but">
            <el-button :disabled="(isUploadFile === '00'|| isTransferPdfFile === '00' || isPdfSignature) ? true : false" type="primary" size="medium" @click="electronicSignature">
              电子签章
            </el-button>
            <!-- <el-button :disabled="(isUploadFile === '00' || isTransferPdfFile === '00') ? true : false" type="primary" size="medium">完成签章</el-button> -->
            <el-button :disabled="(isUploadFile === '00' || isTransferPdfFile === '00') ? true : false" size="medium" @click="exportReviewReport">
              导出评标报告
            </el-button>
          </div>
        </div>
      </div>
    </div>
    <!-- 重新上传弹框 -->
    <reuploadReport
      :dialog-data="dialogData"
      :get-tender-base="tenderBase"
      @changeUploadstatus="changeUploadstatus"
      @uploadEvalInformData="uploadEvalInformData"
    />
  </div>
</template>

<script>
/*   api接口 */
import {
  getEvalReportUUid,
  uploadEvalInform,
  procurementReportContentToPDF,
  exportProtProjectProcedureExpertEvalReportFile,
  qryProcurementEvalReportUploadStatus
} from '@/api/procurement/procurementEvaluation'
/** 公共组件 */
import upload from '@comp/common/updownload/upload' // 附件上传组件
import editor from '@comp/common/editor/editor' // 富文本编辑器
import pdfDetail from '@comp/common/pdf/pdf' // pdf查看
import pdfSignature from '@comp/procurement/pdf/pdf' // pdf签章
// import downloadFile from '@comp/common/updownload/downloadFile'// 文件回显组件
import { readImageRoot } from '@api/common/uploadCenter' // 图片查看路径
// import driveStepRight from '../procurementEvaluationLobbyDrive/components/procurementDriveStepRight'
/* 公共方法 */
import { download } from '@/assets/js/utils/index'
/* 弹框组件 */
// import reuploadReport from './procurementReuploadReport-dialog'
export default {
  components: {
    editor, // 富文本编辑器
    pdfDetail, // pdf
    pdfSignature, // pdf签章
    upload // 文件上传
    // downloadFile, // 文件下载
    // reuploadReport // 文件重新上传弹框
    // 'drive-step-right': driveStepRight // 顶部右侧菜单
  },
  inject: ['getTenderBase', 'getDriveTask', 'driveReload'],
  data() {
    return {
      loading: false,
      // 上传评审报告
      reviewReportFilsData: {
        bizId: '', // 业务主键Id
        fileType: 'reviewReports'// 文件类型
      },
      principalList: [], // 附件上传列表
      // 评审报表内容参数
      reviewReportParam: {
        reviewReportId: '', // 公告Id
        content: '', // 公告内容
        contentTest: '' // 公告转码内容
      },
      pdfUrl: '', // pdf地址
      readImageUrl: readImageRoot, // 公共下载地址
      showFile: false, // 是否展示文件列表
      tenderBase: this.getTenderBase(), // 获取项目基本参数
      isTransferPdfFile: '', // 是否已转为PDF签章,01为已转，00-未转为PDF签章
      isUploadFile: '', // 是否上传过评审word文件，00-未上传，01-已上传
      dialogData: {
        dialog: false // 弹框是否显示
      },
      timer: null, // 定时器任务
      isPdfSignature: false // 是否显示pdf签章
    }
  },
  created() {
    // 初始化调用获取文件主键id方法
    this.getEvalReportUUidData()
    // 非组长调定时器查看组长是否转pdf
    if (this.tenderBase.isEvalLeader === '00' && this.isTransferPdfFile === '00') {
      this.timer = setInterval(() => {
        this.queryReportUploadStatus()
      }, 10000)
    }
  },
  methods: {
    // 附件上传
    principalFile(file, fileList) {
      this.principalList = fileList
    },
    // 附件上传成功的回调
    successList(file) {
      this.loading = false
      const data = {
        id: this.reviewReportFilsData.bizId, // UUid
        packId: this.tenderBase.packId, // 标段id
        stageId: '' // 阶段id
      }
      this.uploadEvalInformData(data)
      // 查询上传word状态
      this.queryReportUploadStatus()
    },
    //  获取文件上传的主键id请求
    getEvalReportUUidData() {
      const packId = this.tenderBase.packId
      getEvalReportUUid(packId).then(res => {
        this.reviewReportFilsData.bizId = res.data
        // 查询上传word状态
        this.queryReportUploadStatus()
      }).catch(() => {
      })
    },
    // 专家上传评审报告方法
    uploadEvalInformData(data) {
      uploadEvalInform(data).then(res => {
        this.reviewReportParam.content = res.data.htmlContent
        // 查询上传word状态
        this.queryReportUploadStatus()
      }).catch(() => {

      })
    },
    // 转为pdf签章
    reportContentToPDF() {
      this.loading = true
      const data = {
        htmlContent: this.reviewReportParam.content,
        id: this.reviewReportFilsData.bizId,
        packId: this.tenderBase.packId,
        evalExpertId: this.tenderBase.evalExpertId
      }
      procurementReportContentToPDF(data).then(res => {
        this.loading = false
        // 拼接pdf的url路径
        const url = this.readImageUrl + res.data.pdfUrl
        // 加密处理
        this.pdfUrl = encodeURIComponent(url)
        // 刷新是否已上传word，是否已转pdf签章
        this.queryReportUploadStatus()
      }).catch(() => {
        this.loading = false
      })
    },
    // 导出评审报告
    exportReviewReport() {
      exportProtProjectProcedureExpertEvalReportFile(this.tenderBase.packId).then(res => {
        download(res, '评审报告.pdf')
      })
    },
    // 查询是否已上传word，是否已转pdf签章
    queryReportUploadStatus() {
      this.loading = false
      qryProcurementEvalReportUploadStatus(this.tenderBase.packId).then(res => {
        // 是否已转为PDF签章,01为已转，00-未转为PDF签章
        this.isTransferPdfFile = res.data.isTransferPdfFile
        // 是否上传过评审word文件，00-未上传，01-已上传
        this.isUploadFile = res.data.isUploadFile
        // 判断已转签章且非组长
        if (this.isTransferPdfFile === '01' && this.tenderBase.isEvalLeader === '00') {
          // 清除定时器
          clearInterval(this.timer)
          // 拼接pdf的url路径
          const url = this.readImageUrl + res.data.pdfUrl
          // 加密处理
          this.pdfUrl = encodeURIComponent(url)
          this.nonLeaderViewSignature()
        }
        // 判断已签章且组长
        if (this.isTransferPdfFile === '01' && this.tenderBase.isEvalLeader === '01') {
          // 拼接pdf的url路径
          const url = this.readImageUrl + res.data.pdfUrl
          // 加密处理
          this.pdfUrl = encodeURIComponent(url)
        }
        // 判断上传文件未签章组长页面
        if (this.isUploadFile === '01' && this.isTransferPdfFile === '00' && this.tenderBase.isEvalLeader === '01') {
          this.reviewReportParam.content = res.data.htmlContent
        }
      })
    },
    // 已转为pdf签章非组长查看页面
    nonLeaderViewSignature() {
      this.$confirm('评委您好，评标报告已上传，请尽快完成签章！', '提示', {
        confirmButtonText: '我知道了',
        confirmButtonClass: 'confirmBtn',
        showCancelButton: false,
        type: 'warning'
      }).then(() => {
      })
    },
    // 点击上传按钮
    uploadFile() {
      this.loading = true
      this.dialogData.dialog = true
    },
    // 更改文件上传状态
    changeUploadstatus() {
      // 01 为上传过，显示富文本编辑器
      this.isUploadFile = '01'
      // 还未转pdf
      this.isTransferPdfFile = '00'
    },
    // 电子签章
    electronicSignature() {
      // 显示pdf签章
      this.isPdfSignature = true
    },
    // 刷新驱动
    reloadDriver() {
      this.driveReload()
      this.getDriveTask()
    }
  }
}
</script>

<style lang="less" scoped>
/deep/.but_footer .but_footer-but{
  display: -moz-inline-box;
}
/deep/.fileBtn{
    margin-bottom: 2px !important;
    margin-right: 16px;
}
.noData{
  width: 300px;
  height: 300px;
  position: absolute;
  left: 0;
  top: 15%;
  right: 0;
  margin:auto;
}
.editor {
  min-height: 200px;
}
</style>
