<!--准备弃用
  @description: 开标大厅-开标中-（1宫格分包点击查看包 2不分包子页面）
  @Modifier: haoFx
  @routerPath:
  @date: 2020/3/19-15:47
-->
<template>
  <div :class="isPackage==='00'?'wrap-height':''">
    <div class="pack_info clearfix">
      [ {{ bidderDecryptionInfo.packNo }}]
      {{ bidderDecryptionInfo.packName }}
      <div class="fr">
        <!--01开标完成 显示唱标结果-->
        <el-button
          v-if="bidderDecryptionInfo.openingStatus === '01'"
          @click="singResults"
        >
          查看{{ bidAnnouncementText }}结果
        </el-button>
        <!--00 不显示(按规则判断没有唱标显示,已唱标不显示) 01 显示-->
        <!--00未开标 01开标完成 02开标中 -->
        <el-button
          v-if="bidderDecryptionInfo.openingStatus==='02' || isReSingingButtonDisplay==='01'"
          :loading="bidAnnouncementLoading"
          icon="iconfont icon-laba"
          @click="bidAnnouncement"
        >
          {{ bidAnnouncementText }}
        </el-button>
        <!--01集中解密 显示重新解密-->
        <el-button
          v-if="todayOpeningInfo.bidDocumentDecryptionMethod === '01' && isReDecryptDisplay==='01'"
          @click="reDecryption"
        >
          重新解密
        </el-button>
      </div>
    </div>
    <el-row class="row-height" type="flex">
      <!--左侧投标人信息-->
      <el-col :span="20">
        <el-scrollbar class="pack_wrap_scrollbar scrollbar">
          <el-table
            ref="filterTable"
            max-height="100%"
            :border="false"
            :data="packList"
            :show-header="false"
            class="bidder_wrap"
            size="mini"
          >
            <!--            <el-table-column
              label=""
              width="50">
              <template>
                <i class="iconfont icon-zaixian"/>
              </template>
            </el-table-column>-->
            <el-table-column
              label="投标人名称"
              min-width="230"
            >
              <template slot-scope="scope">
                {{ scope.$index+1 }}、{{ scope.row.supplierName }}
              </template>
            </el-table-column>
            <!--投标人解密显示 服务端集中解密不显示-->
            <el-table-column
              v-if="todayOpeningInfo.bidDocumentDecryptionMethod ==='00'"
              min-width="100"
              align="center"
              label="签到人"
            >
              <template slot-scope="scope">
                <p>{{ scope.row.signPerson }}</p>
                <p>{{ scope.row.signTime && $Moment(scope.row.signTime).format(momentTimeFormat) }}</p>
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              min-width="100"
              label="解密状态"
            >
              <template slot-scope="scope">
                <!--解密状态 00 未解密 01 解密成功-->
                <template v-if="scope.row.decryptionStatus!=='02'">
                  <i :class="scope.row.decryptionStatus==='01'?'icon-kaisuo':'icon-suo'" class="iconfont" />
                </template>
                <!--02 解密失败展示-->
                <i v-if="scope.row.decryptionStatus==='02'" class="iconfont icon-suo decryptionStatus" />
                <!--解密时间-->
                <el-popover
                  trigger="click"
                  placement="bottom-end"
                >
                  <p>{{ scope.row.decryptionTime }}</p>
                  <p slot="reference">
                    {{ scope.row.decryptionTime && $Moment(scope.row.decryptionTime).format(momentTimeFormat) }}
                  </p>
                </el-popover>
              </template>
            </el-table-column>
          </el-table>
        </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">{{ bidderDecryptionInfo.validDecryptNumber }}</span>
              <!--有效投标人项目数-->
              <span v-show="currentIndex === 1">{{ bidderDecryptionInfo.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>{{ bidderDecryptionInfo.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="bidderDecryptionInfo.decryptionFailedNumber>0"
                class="bidOpen-badge"
                :value="bidderDecryptionInfo.decryptionFailedNumber"
              >
                {{ bidderDecryptionInfo.decryptionNumber }}
              </el-badge>
              <!--解密成功-解密数-->
              <span v-else>
                {{ bidderDecryptionInfo.decryptionNumber }}
              </span>
            </el-col>
            <el-col :span="4">
              <span class="jiaci">家次</span>
            </el-col>
          </el-row>
        </div>
      </el-col>
    </el-row>
    <bidAnnouncement ref="bidAnnouncementDialog" @handelBidAnnouncement="handelBidAnnouncement" />
  </div>
</template>

<script>
/* api*/
import { getTenderPackageBidderByStageId,
  getValidBidderSignAndDecryptionNumberByStageId,
  uploadSingingResult,
  startFocusBidOpening
} from '@api/bidding/bidOpening'
import { getSystemConfigValueByConfigType } from '@/api/common/systemConfigCenter'
/* 混入 */
import { bidOpeningMixin } from '../mixins/bidOpeningMixin'
/* 组件 */
import bidAnnouncement from '../bidAnnouncement/bidAnnouncement-dialog'// 查看唱标结果-弹框
export default {
  name: 'PackageDialog',
  components: {
    bidAnnouncement// 查看唱标结果-弹框
  },
  mixins: [bidOpeningMixin],
  props: {
    isPackage: {
      type: String,
      default: '00' // 01开标大厅多包查看弹框 00驱动进入或者不分包页面查看
    }
  },
  data() {
    return {
      bidAnnouncementLoading: false, // 唱标loading
      packList: [], // 投标人信息
      params: {
        stageId: '', // 阶段id
        openStageType: '', // 00一次开标阶段(商务技术经济)，01非价格开标阶段(商务技术)，02价格开标阶段(经济)
        openBidStartTime: '', // 开标时间
        bidDocumentDecryptionMethod: '' // 投标文件解密方式 00:投标人解密 01:服务端集中解密
      },
      // 有效投标数，已签到，已解密数，解密失败数(右侧)()
      bidderDecryptionInfo: {
        packNo: '', // 标段编号
        packName: '', // 标段名称
        tenderId: '', // 项目id
        signNumber: '', // 签到数
        decryptionFailedNumber: '', // 解密失败数
        decryptionNumber: '', // 解密数
        tenderOpeningResultId: '', // 开标结果id
        validBidderNumber: '', // 有效投标人项目数
        validDecryptNumber: '', // 可解密
        openingStatus: '' // 00未开标 01开标完成 02开标中
      },
      isReDecryptDisplay: '', // 是否显示重新解密配置
      isReSingingButtonDisplay: '' // 唱标按钮是否显示: 00 不显示 01 显示
    }
  },
  beforeDestroy() {
    // 离开页面销毁定时器
    clearInterval(this.sumNumberTimer)
  },
  methods: {
    // 打开开标大厅调用-查看投标人信息
    openPackage(packInfo, todayOpeningInfo) {
      // 查询条件
      const stageId = packInfo && packInfo.stageId || this.openTypeStageIds.stageIds// 阶段id
      todayOpeningInfo = todayOpeningInfo || this.openTypeStageIds// 查询条件
      this.params = {
        stageId: stageId,
        ...todayOpeningInfo
      }
      /* ----------开标信息---------- */
      // 根据阶段id查看某标段开标详情列表
      this.getTenderPackageBidder()
      // 获取该阶段已投标已签到已解密解密失败总次数(开标界面查看某包) 定时获取
      this.getValidBidderSignAndDecryptionNumber()
      // 集中解密是否显示重新解密配置
      this.getSystemConfigValue()
      // 是否显示唱标按钮
      this.getReSingingButtonDisplay()
      // 启用定时器-开标信息
      this.sumNumberTimer = setInterval(() => {
        // 根据阶段id查看某标段开标详情列表
        this.getTenderPackageBidder()
        // 获取该阶段已投标已签到已解密解密失败总次数(开标界面查看某包) 定时获取
        this.getValidBidderSignAndDecryptionNumber()
      }, this.bidderNumberTimer)
    },
    // 根据阶段id查看某标段开标详情列表
    getTenderPackageBidder() {
      getTenderPackageBidderByStageId(this.params).then(response => {
        this.packList = response.data
      }).catch(() => {
      })
    },
    // 获取该阶段已投标已签到已解密解密失败总次数(开标界面查看某包) 定时获取
    getValidBidderSignAndDecryptionNumber() {
      getValidBidderSignAndDecryptionNumberByStageId(this.params).then(res => {
        this.bidderDecryptionInfo = res.data
        // 开标完成 清除定时器
        if (this.bidderDecryptionInfo.openingStatus === '01') {
          clearInterval(this.sumNumberTimer)
        }
      }).catch(() => {
      })
    },
    // 唱标
    bidAnnouncement() {
      this.$confirm(`确认${this.bidAnnouncementText}吗，确认${this.bidAnnouncementText}后将结束解密?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        const data = {
          ...this.params,
          tenderId: this.bidderDecryptionInfo.tenderId
        }
        this.bidAnnouncementLoading = true
        uploadSingingResult(data).then(res => {
          this.$message({
            type: 'success',
            message: res.header.msg
          })
          // 打开唱标结果查看
          this.singResults()
        }).catch(() => {
        })
      }).catch(() => {
        this.bidAnnouncementLoading = false
      })
    },
    // 控制唱标按钮loading
    handelBidAnnouncement() {
      this.bidAnnouncementLoading = false
    },
    // 查看唱标结果
    singResults() {
      const data = {
        stageId: this.params.stageId,
        openStageType: this.params.openStageType,
        type: '00' // 00 开标大厅查看唱标结果 01 开标结果查看确认文件
      }
      this.$refs.bidAnnouncementDialog.openBidAnnouncement(data)
    },
    // 分包父组件关闭弹框 清除定时器
    clearIntervalTime() {
      clearInterval(this.sumNumberTimer)
    },
    // 重新解密
    reDecryption() {
      this.$confirm('确认重新解密吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        const data = {
          stageIds: this.params.stageId,
          openStageType: this.params.openStageType,
          openBidStartTime: this.params.openBidStartTime
        }
        startFocusBidOpening(data).then(res => {
          this.$message({
            type: 'success',
            message: res.header.msg
          })
        }).catch(() => {
        })
      }).catch(() => {
      })
    },
    // 集中解密是否显示重新解密配置 01 显示
    getSystemConfigValue() {
      getSystemConfigValueByConfigType('tenderOpen-reDecryptDisplay').then(res => {
        this.isReDecryptDisplay = res.data
      }).catch(() => {
      })
    },
    // 唱标按钮是否显示: 00 不显示(按规则判断没有唱标显示,已唱标不显示) 01 显示
    getReSingingButtonDisplay() {
      getSystemConfigValueByConfigType('tenderOpen-reSingingButtonDisplay').then(res => {
        this.isReSingingButtonDisplay = res.data
      }).catch(() => {
      })
    },
    // 切换显示可解密、已投标
    handover() {
      if (this.currentIndex === this.bidInfoToggleArr.length - 1) {
        this.currentIndex = 0
      } else {
        ++this.currentIndex
      }
    }
  }
}
</script>

<style scoped lang="less">
  @import "../index";
  .bidder_wrap{
    .iconfont{
      font-size: 14px!important;
      color: #49AC1E;
      &.decryptionStatus{
        color: #FFAD27!important;
      }
    }
  }
  .pack_info{
    background-color: #204EBC;
    padding: 16px;
    box-sizing: border-box;
    color: #fff;
    /deep/.el-button{
      .icon-yinlianglabashengyin{
        margin-right: 3px;
      }
    }
  }
  .row-height{
    height: calc(100% - 64px);
  }
  .wrap-height{
    height: calc(100% - 25px);
  }
</style>
