<!--准备弃用
  @description: 开标大厅-开标中（宫格分包）{集中解密，非集中解密公用}
  @Modifier: haoFx
  @routerPath:/bidding/projectDrive/bidOpening/packageBidOpeningDecryption
  @date: 2020/3/18-14:54
-->
<template>
  <div>
    <div class="open-info">
      <el-row type="flex" class="row-bg">
        <el-col :span="5" class="left-center-left">
          <div class="openInfo-left">
            <p>当前时间</p>
            <span>
              {{ presentTime?presentTime: sysCurrentTime }}
            </span>
          </div>
        </el-col>
        <el-col :span="14" class="left-center-right">
          <div ref="purpleLight" class="bg-purple-light">
            <el-row type="flex" style="height: 100%">
              <!--左侧标段包信息-->
              <el-col :span="20">
                <el-scrollbar class="pack_wrap_scrollbar" wrap-class="pack_wrap" tag="ul">
                  <li
                    v-for="(item,index) in packList"
                    :key="index"
                    :class="`pack_wrap_status_`+ item.openingStatus"
                    class="pointer fl"
                    :style="{height: packWrapHeight}"
                    @click="viewPackInfo(item)"
                  >
                    <div class="top_title">
                      [{{ item.packNo }}]
                      <span class="pack_name">
                        {{ item.packName }}
                      </span>
                    </div>
                    <div class="info clearfix">
                      <div
                        v-for="(itemName,key) in bidPackInfoToggleArr"
                        v-show="currentIndex === key"
                        :key="key"
                        class="bottom_wrap fl"
                      >
                        <span class="nums">
                          <!--未开标 && 已投标为0-->
                          <template v-if="item.openingStatus==='00' && item.validBidderNumber ===0">
                            {{ item.validBidderNumber }}
                          </template>
                          <template v-else>
                            <!--可解密数-->
                            <template v-if="currentIndex===0">{{ item.validDecryptNumber }}</template>
                            <!--有效投标人家次数-->
                            <template v-if="currentIndex===1">{{ item.validBidderNumber }}</template>
                          </template>
                          <i>家</i>
                        </span>
                        <span class="border_radius">
                          <!--未开标 && 已投标为0-->
                          <template v-if="item.openingStatus==='00' && item.validBidderNumber ===0">
                            已投标
                          </template>
                          <template v-else>
                            {{ itemName }}
                          </template>
                        </span>
                      </div>

                      <!--投标人解密显示 服务端集中解密不显示 已签到-->
                      <div v-if="todayOpeningInfo.bidDocumentDecryptionMethod ==='00'" class="bottom_wrap fl">
                        <span class="nums">{{ item.signNumber }}<i>家</i></span>
                        <span class="border_radius">已签到</span>
                      </div>
                      <div class="bottom_wrap fr">
                        <!--某标段解密失败展示-->
                        <el-badge v-if="item.decryptionFailedNumber>0" :value="item.decryptionFailedNumber" class="bidOpen-badge">
                          <span class="nums">{{ item.decryptionNumber }}<i>家</i></span>
                        </el-badge>
                        <span v-else class="nums">{{ item.decryptionNumber }}<i>家</i></span>
                        <span class="border_radius">已解密</span>
                      </div>
                    </div>
                    <div class="bid_opening_status">
                      <span v-if="item.openingStatus ==='02'">开标中...</span>
                      <span v-if="item.openingStatus ==='00'">未开标</span>
                      <span v-if="item.openingStatus ==='01'">已完成</span>
                      <el-progress
                        :text-inside="true"
                        :stroke-width="12"
                        :percentage="item.progressBar"
                        status="success"
                      />
                    </div>
                  </li>
                </el-scrollbar>
              </el-col>
              <!--右侧显示有效投标人、已签到、已解密数字-->
              <el-col :span="4">
                <!--客户端解密/服务端解密动态切换class 右侧解密数动态设置高度-->
                <div class="jiemi_info" :class="todayOpeningInfo.bidDocumentDecryptionMethod ==='00'?'jiemi_height3':'jiemi_height2'">
                  <!--有效投标人、可解密切换展示-->
                  <el-row
                    v-for="(item,index) in bidInfoToggleArr"
                    v-show="currentIndex === index"
                    :key="index"
                    class="jiemi_status"
                  >
                    <el-col :span="4" class="status_txt">
                      {{ item }}
                    </el-col>
                    <el-col :span="16" class="num">
                      <!--可解密-->
                      <span v-show="currentIndex===0">{{ validBidderSignAndDecryptionSumNumber.validDecryptNumber }}</span>
                      <!--有效投标人总数-->
                      <span v-show="currentIndex===1">{{ validBidderSignAndDecryptionSumNumber.validBidderNumber }}</span>
                    </el-col>
                    <el-col :span="4">
                      <i class="iconfont icon-shuffle pointer" @click="handover()" />
                      <span class="jiaci">家次</span>
                    </el-col>
                  </el-row>
                  <!--投标人解密显示 服务端集中解密不显示 已签到-->
                  <el-row v-if="todayOpeningInfo.bidDocumentDecryptionMethod ==='00'" class="jiemi_status">
                    <el-col :span="4" class="status_txt">
                      已签到
                    </el-col>
                    <el-col :span="16" class="num">
                      <span>{{ validBidderSignAndDecryptionSumNumber.signNumber }}</span>
                    </el-col>
                    <el-col :span="4">
                      <span class="jiaci">家次</span>
                    </el-col>
                  </el-row>
                  <!--已解密-->
                  <el-row class="jiemi_status">
                    <el-col :span="4" class="status_txt">
                      已解密
                    </el-col>
                    <el-col :span="16" class="num">
                      <!--解密失败展示 el-badge-->
                      <el-badge
                        v-if="validBidderSignAndDecryptionSumNumber.decryptionFailedNumber>0"
                        :value="validBidderSignAndDecryptionSumNumber.decryptionFailedNumber"
                        class="bidOpen-badge"
                      >
                        {{ validBidderSignAndDecryptionSumNumber.decryptionNumber }}
                      </el-badge>
                      <!--解密成功-->
                      <span v-else>
                        {{ validBidderSignAndDecryptionSumNumber.decryptionNumber }}
                      </span>
                    </el-col>
                    <el-col :span="4">
                      <span class="jiaci">家次</span>
                    </el-col>
                  </el-row>
                </div>
              </el-col>
            </el-row>
          </div>
        </el-col>

        <el-col :span="5" class="right-center-right">
          <div class="openInfo-right">
            <p>开标时间</p>
            <span>
              {{ todayOpeningInfo.openBidStartTime && $Moment(todayOpeningInfo.openBidStartTime).format(momentDateTime) }}
            </span>
          </div>
        </el-col>
      </el-row>
      <!--底部信息-->
      <div class="footer_bottom_wrap clearfix">
        <!--<div class="mask">
          <el-scrollbar class="mask_scrollbar scrollbar">
            <ul>
              <li v-for="(item,index) in openingInfo" :key="index" >
                【 {{ item.supplierName }}】
                【 {{ item.info }}】
                【 {{ item.time }}】
              </li>
            </ul>
          </el-scrollbar>
        </div>-->
        <!--更多操作-->
        <template v-if="todayOpeningInfo.bidDocumentDecryptionMethod==='01'">
          <el-dropdown trigger="click" class="more-dropdown" @command="handleCommand">
            <el-button type="primary" @click="moreOperation">
              更多操作<i class="el-icon-arrow-down el-icon--right" />
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item :disabled="refreshDisabled" command="00">
                刷新
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
        <!--启动视频会议-->
        <template v-if="tenderOpenVideoConferenceDisplay==='01'">
          <el-button
            type="primary"
            icon="iconfont icon-shipinhuiyi"
            @click="startVideoConferencing"
          >
            启动视频会议
          </el-button>
          <!--启动视频会议-->
          <el-button
            type="primary"
            icon="iconfont icon-yaoqing"
            @click="videoConferenceInvitation"
          >
            会议邀请
          </el-button>
        </template>
        <el-button
          type="primary"
          icon="iconfont icon-laba"
          @click="batchSingingResult"
        >
          批量{{ bidAnnouncementText }}
        </el-button>
        <!--投标人解密显示 服务端集中解密不显示 发送消息-->
        <el-button
          v-if="todayOpeningInfo.bidDocumentDecryptionMethod ==='00'"
          type="primary"
          icon="iconfont icon-xiaoxi"
          @click="sendMsg"
        >
          发送消息
        </el-button>
        <el-button
          type="primary"
          icon="iconfont icon-xuanzhongshangcheng"
          @click="backHome"
        >
          返回主页
        </el-button>
      </div>
      <!-- 监标人-->
      <div class="bidTenderSupervisor" />
    </div>

    <el-dialog
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      :title="openStageTypeTitle"
      custom-class="el-dialog__body-minHeight el-dialog__body-p0"
      width="70%"
      @close="closeDialog"
    >
      <!--查看标包信息-->
      <packageBidderInfo ref="packageBidderInfo" is-package="01" style="height: 100%" />
    </el-dialog>
    <!--批量唱标列表-->
    <batchSingingPackListDialog ref="batchSingingPack" is-package="01" style="height: 100%" />
    <!--通知消息组件-->
    <msg-writer ref="msgWriter" />
    <!--视频会议邀请投标人-->
    <supplierVideoConferenceDialog ref="supplierVideoConference" />
  </div>
</template>
<script>
/* api*/
import { getOpeningTenderPackageInfoListByStageIdList,
  getValidBidderSignAndDecryptionSumNumberByStageIdList, managerOpenFSMeetingRoom, startFocusBidOpening } from '@api/bidding/bidOpening'
  /* 组件*/
import packageBidderInfo from './packageBidderInfo'
import { bidOpeningMixin } from '../mixins/bidOpeningMixin'
import msgWriter from '../msgWriterCom/msgWriter'
import batchSingingPackListDialog from '../bidAnnouncement/batchSingingPackList-dialog'// 批量唱标标段弹框
import supplierVideoConferenceDialog from '../supplierVideoConference/supplierVideoConference-dialog' // 邀请投标人参与视频会议
export default {
  name: 'ClientDecryption',
  components: {
    packageBidderInfo, // 开标大厅-开标中-（1宫格分包点击查看包）
    'msg-writer': msgWriter, // 发送消息组件
    batchSingingPackListDialog, // 批量唱标标段弹框
    supplierVideoConferenceDialog // 邀请投标人参与视频会议
  },
  mixins: [bidOpeningMixin],
  data() {
    return {
      dialogVisible: false,
      // 项目标段列表
      packList: [],
      // 开标信息
      openingInfo: [],
      // 有效投标数，已签到，已解密数，解密失败数(右侧)
      validBidderSignAndDecryptionSumNumber: {
        decryptionFailedNumber: 0, // 解密失败数
        decryptionNumber: 0, // 解密数
        signNumber: 0, // 签到数
        validBidderNumber: 0, // 有效投标人项目数
        validDecryptNumber: 0 // 可解密
      }
    }
  },
  computed: {
    // 标段包li高度
    packWrapHeight: function() {
      let clientHeight = this.$refs.purpleLight.clientHeight
      if ((clientHeight / 3) < 156) {
        clientHeight = 156 // 设置最小高度不能小于156
      } else {
        clientHeight = clientHeight / 3
      }
      return clientHeight + 'px' // 自定义高度需求
    }
  },
  created() {
    // 视频会议是否显示: 00 不显示 01 显示
    this.getReSingingButtonDisplay()
    // 获取该阶段集合下开标详情列表 定时刷
    this.getOpeningTenderPackageInfo()
    // 获取该阶段集合下已投标已签到已解密解密失败总次数((开标界面 分包列表右侧总次数))
    this.getValidBidderSignAndDecryptionSumNumber()
  },
  mounted() {
    // 初始化数据定时刷新接口
    this.rimeRefresh()
    // 初始化获取系统当前时间
    this.getCurrentTime('setIntervalTime')
  },
  methods: {
    // 初始化数据定时刷新接口
    rimeRefresh() {
      this.timer = setInterval(() => {
        // 获取该阶段集合下开标详情列表 定时刷
        this.getOpeningTenderPackageInfo()
        // 获取该阶段集合下已投标已签到已解密解密失败总次数((开标界面 分包列表右侧总次数))
        this.getValidBidderSignAndDecryptionSumNumber()
      }, this.bidderNumberTimer)
      // 清除定时器
      this.$once('hook:beforeDestroy', () => {
        clearInterval(this.timer)
      })
    },
    // 获取该阶段集合下开标详情列表 定时刷
    getOpeningTenderPackageInfo() {
      getOpeningTenderPackageInfoListByStageIdList(this.openTypeStageIds).then(res => {
        this.packList = res.data // 分包标段列表
        const len = this.packList.length
        for (let i = 0; i < len; i++) {
          this.packList[i].progressBar = Number(this.packList[i].progressBar)
        }
      }).catch(() => {
      })
    },
    // 获取该阶段集合下已投标已签到已解密解密失败总次数((开标界面 分包列表右侧总次数))
    getValidBidderSignAndDecryptionSumNumber() {
      getValidBidderSignAndDecryptionSumNumberByStageIdList(this.openTypeStageIds).then(res => {
        this.validBidderSignAndDecryptionSumNumber = res.data
      }).catch(() => {
      })
    },
    // 关闭弹框
    closeDialog() {
      // 清除定时器查看投标解密信息定时器（触发子组件方法）
      this.$refs.packageBidderInfo.clearIntervalTime()
      // 开始调用本页面方法
      this.rimeRefresh()
    },
    // 打开弹框查看标包信息
    viewPackInfo(item) {
      // 销毁定时器
      clearInterval(this.timer)
      this.dialogVisible = true
      this.$nextTick(function() {
        this.$refs.packageBidderInfo.openPackage(item, this.todayOpeningInfo)
      })
    },
    // 返回主页
    backHome() {
      this.$router.push({
        path: '/bidOpeningHall/bidOpeningTodayList',
        query: {
          ...this.$route.query
        }
      })
    },
    // 发送消息
    sendMsg() {
      const len = this.packList.length // 分包标段列表
      const stageIdsArr = []
      let stageIds = ''
      for (let i = 0; i < len; i++) {
        // 取开标进行中的stageId
        if (this.packList[i].openingStatus === '02') {
          stageIdsArr.push(this.packList[i].stageId)
        }
      }
      stageIds = stageIdsArr.join(',')
      this.$refs.msgWriter.openMsgDialog(stageIds)
    },
    // 标段批量唱标列表
    batchSingingResult() {
      this.$refs.batchSingingPack.open()
    },
    // 启动视频会议
    startVideoConferencing() {
      managerOpenFSMeetingRoom(this.openTypeStageIds).then(res => {
        window.open(res.data.visitUrl, '_self')
      }).catch(() => {
      })
    },
    // 视频会议邀请
    videoConferenceInvitation() {
      this.$refs.supplierVideoConference.openDialogSupplierVideoConference(this.openTypeStageIds)
    },
    // 切换显示可解密、已投标
    handover() {
      /* bidInfoToggleArr: ['可解密', '有效投标']*/
      if (this.currentIndex === this.bidInfoToggleArr.length - 1) {
        this.currentIndex = 0
      } else {
        ++this.currentIndex
      }
    },
    // 点击更多操作
    moreOperation() {
      const sumDecryptionNum = this.validBidderSignAndDecryptionSumNumber.decryptionNumber // 解密总数
      const sumValidDecryptNum = this.validBidderSignAndDecryptionSumNumber.validDecryptNumber // 可解密
      // 解密总数 === 可解密 则不可刷新 否则可以点击刷新
      if (sumDecryptionNum === sumValidDecryptNum) {
        this.refreshDisabled = true
      }
    },
    // 点击菜单项后会触发事件（刷新command="00">）
    handleCommand(command) {
      if (command === '00') {
        // 刷新调用的集中解密方法
        this.refreshDecryption()
        this.refreshDisabled = true
        const that = this
        this.refreshDisabledTime = setTimeout(() => {
          that.refreshDisabled = false
        }, this.millisec)
        // this.millisec 定时器时间变量
      }
    },
    // 刷新调用的集中解密方法
    refreshDecryption() {
      const packList = [] // 开标中的标段的stageId集合
      let bidOpeningStageIds = '' // 开标中的标段的StageId集合转换成字符串
      // 过滤开标中的标段的stageId
      this.packList
        .filter(v => v.openingStatus === '02')
        .map((item) => {
          packList.push(item.stageId)
        })
      bidOpeningStageIds = packList.join(',')
      const data = {
        stageIds: bidOpeningStageIds,
        openStageType: this.openTypeStageIds.openStageType,
        openBidStartTime: this.openTypeStageIds.openBidStartTime
      }
      startFocusBidOpening(data).then(() => {
      }).catch(() => {
      })
    }
  }
}
</script>

<style scoped lang="less">
  @import "../index";
  /deep/.el-dialog__body-minHeight{
    .el-dialog__header{
      background-color: #2B59C6;
    }
    .el-dialog__body {
      height: 70vh;
    }
  }
</style>
