<!--
  @description: 评审结果查看页面
  @author: yf
  @routerPath: /procurement/procurementDrive/procurementDocumentsPurchase/evaluationResults
  @date: 2020-8-24 17:28:58
-->
<template>
  <div class="main ">
    <!-- 评标步骤退回 -->
    <div class="evaluationTitle clearfix">
      <div class="activeText fl" />
      <p class="text fl">
        1. 评审步骤退回
      </p>
    </div>
    <div v-if="toggleStatus">
      <!-- 评标步骤退回 -->
      <step-rollback ref="stepRollback" :get-tender-base="getTenderBase" @reloadRollbackData="reloadRollbackData" />
    </div>
    <!-- 评标进度 -->
    <div class="evaluationTitle clearfix">
      <div class="activeText fl" />
      <p class="text fl">
        2. 评审进度
      </p>
      <!-- <gx-button :code="'001_005_002'" size="small" type="text" @click="startVideoConference">
        启动视频会议
      </gx-button> -->
      <gx-button v-if="evaluationAlreadyEnd==='00' || evaluationAlreadyEnd==='01'" :code="'001_005_003'" type="text" size="small" @click="dialogData.dialog=true">
        终止评审
      </gx-button>
      <gx-button v-if="evaluationAlreadyEnd==='02'" :code="'001_005_004'" type="text" size="small" @click="dialogData.dialog=true">
        已终止评审
      </gx-button>
      <gx-button v-if="evaluationAlreadyEnd==='01'" :code="'001_005_005'" type="text" size="small" @click="finishEvaluation">
        确认完成评审
      </gx-button>
      <gx-button v-if="evaluationAlreadyEnd==='03'" :code="'001_005_006'" type="text" size="small">
        已完成评审
      </gx-button>
      <!-- <gx-button v-if="getTenderBase.tenderMethod!=='11'" :code="'001_005_007'" type="text" size="small" @click="inviteSupplier">
        邀请供应商加入视频
      </gx-button> -->
      <gx-button v-if="openDetailEvalFlag" :code="'001_005_008'" type="text" size="small" @click="setOpenReview">
        开启详细评审
      </gx-button>
    </div>
    <div class="mb16">
      <!-- 评标进度 -->
      <evaluation-progress ref="evaluationProgress" :get-tender-base="getTenderBase" @getStepBackInfo="getStepBackInfo" @openDetailEvalStatus="openDetailEvalStatus" />
    </div>
    <!--终止评审弹框-->
    <select-supplier :dialog-data="selectSupplierFlag" />
    <termination-evaluation-dialog :dialog-data="dialogData" :get-tender-base="getTenderBase" @initData="initData" />
  </div>
</template>

<script>
/* api接口*/
import {
  queryEvalProjectStatus,
  timingQryProtProjectManagerReload,
  finishProtProjectProcurementEndEvalHall,
  openDetailEvalDictateByManager,
  qryManagerOpenFSMeetingRoomStatus
} from '@/api/procurement/procurementEvaluation'
// 引入组件
import StepRollback from './procurementEvaluationStepRollbackTableComp-detail'
import evaluationProgress from './procurementEvaluationProgress-detail'
import selectSupplier from './procurementEvaluationSelectSupplier-dialog' // 报价记录
import terminationEvaluationDialog from './procurementEvaluationTermination-dialog'
export default {
  name: 'EvaluationResult',
  inject: ['getTenderBase', 'getDriveTask', 'driveReload'],
  components: {
    'step-rollback': StepRollback,
    'evaluation-progress': evaluationProgress,
    'select-supplier': selectSupplier,
    'termination-evaluation-dialog': terminationEvaluationDialog
  },
  mixins: [],
  data() {
    return {
      dialogData: {
        dialog: false,
        reviewStatus: ''
      },
      getTenderBase: this.getTenderBase(), // 获取项目基本信息
      timer: null, // 定时任务
      evaluationAlreadyEnd: '', // 是否已经结束评标和已完成评标,00-显示结束评标按钮,01-显示结束评标、确认完成评标按钮,02显示已结束评标按钮,03-显示已完成评标按钮
      openFSFlag: false, // 是否启动视频会议 若是则可发起邀请供应商加入视频
      toggleStatus: true, // 展开退回列表
      openDetailEvalFlag: false,
      selectSupplierFlag: { dialog: false, packId: '', dataId: '', type: '' } // 选择供应商弹出框
    }
  },
  created() {
  },
  beforeDestroy() {
    // 清楚倒计时
    this.clearEvaProcTimer()
  },
  methods: {
    // 初始化页面数据
    initData() {
      queryEvalProjectStatus(this.getTenderBase.packId).then(res => {
        this.evaluationAlreadyEnd = res.data.qryEvalStatusType
        this.dialogData.reviewStatus = res.data.qryEvalStatusType
      })
    },
    // 同意回退步骤后刷新数据
    reloadRollbackData() {
      this.initData()
      // 调取子页面方法
      this.$refs.evaluationProgress.initData()
    },
    // 项目经理开始视频会议 - 暂时隐藏
    // startVideoConference() {
    //   openFSMeetingRoomByManager(this.getTenderBase.packId).then(res => {
    //     this.openFSFlag = true
    //     window.open(res.data.visitUrl)
    //   })
    // },
    // 判断项目经理是否要刷新数据
    managerReload() {
      this.timer = setInterval(() => {
        timingQryProtProjectManagerReload(this.getTenderBase.packId).then(res => {
          // 数据需要刷新
          if (res.data) {
            // 刷新页面按钮展示
            this.initData()
            // 刷新回退列表
            this.$refs.stepRollback.initData()
            // 刷新驱动
            this.$refs.evaluationProgress.initData()
          }
        }).catch(() => {
          // 清楚倒计时
          this.clearEvaProcTimer()
        })
      }, 10000)
    },
    // 驱动完成评标
    finishEvaluation() {
      this.$confirm('确认完成评审，进行中选吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        finishProtProjectProcurementEndEvalHall(this.getTenderBase.packId).then(res => {
          this.$message.success('成功完成评审！')
          this.initData()
          // 刷新驱动
          this.driveReload()
          this.getDriveTask()
        })
      })
    },
    // 邀请供应商加入视频会议
    inviteSupplier() {
      // openFSFlag 如果没有启动视频会议 则提示：请先启动视频会议。
      qryManagerOpenFSMeetingRoomStatus({ packId: this.getTenderBase.packId }).then(res => {
        if (res.data && res.data != null) {
          this.selectSupplierFlag.packId = this.getTenderBase.packId
          this.selectSupplierFlag.dataId = res.data
          this.selectSupplierFlag.type = 'invite'
          this.selectSupplierFlag.dialog = true
        } else {
          this.$message({
            message: '请先启动视频会议',
            type: 'warning'
          })
        }
      })
    },
    // 获取步骤回退信息
    getStepBackInfo() {
      // 是否已经结束评标和已完成评标,00-显示结束评标按钮,01-显示结束评标、确认完成评标按钮,02显示已结束评标按钮,03-显示已完成评标按钮
      this.initData()
      // 清楚倒计时
      this.clearEvaProcTimer()
      // 开启定时任务
      this.managerReload()
    },
    // 子组件传递过来的值 开启/关闭详细状态按钮的值
    openDetailEvalStatus(val) {
      this.openDetailEvalFlag = val
    },
    // 点击确认开启详细评审吗？
    setOpenReview() {
      this.$confirm('确认开启详细评审吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      })
        .then(() => {
          // 调用开启新轮次方法 供应商和评标的都要调用接口
          this.openDetailReview()
        })
        .catch(() => {})
    },
    // 开启详细评审
    openDetailReview() {
      const data = {
        packId: this.getTenderBase.packId
      }
      openDetailEvalDictateByManager(data).then(res => {
        if (res.header.ret === '0') {
          this.$message.success(res.data)
          this.openDetailEvalFlag = false
        }
      })
    },
    // 清楚倒计时
    clearEvaProcTimer() {
      clearInterval(this.timer)
      this.timer = ''
    }
  }
}
</script>

<style lang="less" scoped>
@import "~@/assets/style/common/public.less";
.evaluationTitle {
  width: 100%;
  height: 30px;
  margin: 16px 0;
  background-color: @french-grey;
}
.activeText {
  width: 3px;
  height: 100%;
  margin-right: 20px;
  background-color: @hyacinthine;
}
.text {
  line-height: 30px;
  color: @dark-font;
  font-weight: bold;
  margin-right: 20px;
}
</style>
