<!--
  @description:采购立项-供应商-竞价大厅-当前竞价状态组件
  @Modifier:gmy
  @routerPath:
  @date:2020/5/9-15:48
-->
<template>
  <div class="right-components">
    <p class="title offer-at">
      <span>
        当前竞价状态
      </span>
      <!-- <gx-button v-if="biddingStatus === '00' && hallType === '00'" :code="'001_013_002'" class="startBidding">
        开始竞价
      </gx-button> -->
      <gx-button v-if="biddingStatus === '01' && hallType === '00' && purchaseProjectStatus === '01'" class="startBidding" size="mini" @click="endBidding">
        结束竞价
      </gx-button>
    </p>
    <div class="offer-state offer-state-color1 mt10">
      <!-- {{ biddingText }} -->
      {{ projectRulesData.statusName }}
    </div>
    <div class="offer-content-time">
      <p class="mt_20 offer-title">
        距离竞价结束还剩
      </p>
      <count-down
        :end-time="$Moment(projectRulesData.quoteEndTime).format(momentSaveFormat)"
        :start-time="$Moment(projectRulesData.quoteStartTime).format(momentSaveFormat)"
        :sys-current-time="currentTimes"
        @end_callback="countDownE_cb"
      />
      <div class="duration countdown" />
    </div>
    <div class="offer-rules">
      <p class="offer-rules-title">
        竞价规则
      </p>
      <div>
        <p class="offer-rules-content clearfix">
          <span class="rules-title">竞价开始时间:</span>
          <span class="rules-content">{{ $Moment(projectRulesData.quoteStartTime).format(momentSaveFormat) }}</span>
        </p>
        <p class="offer-rules-content clearfix">
          <span class="rules-title">{{ filterDictText(protproject_quoteCountTypeList, projectRulesData.quoteCountType) }}:</span>
          <span class="rules-content">{{ projectRulesData.quoteCount }}</span>
        </p>
        <p class="offer-rules-content clearfix">
          <span class="rules-title">报价时长:</span>
          <span class="rules-content">{{ projectRulesData.quoteTime }}</span>
          <span class="rules-content">{{ filterDictText(protproject_quoteTimeUnitList, projectRulesData.quoteTimeUnit) }}</span>
        </p>
        <p class="offer-rules-contents">
          <span class="rules-title">
            超时竞价延迟:
          </span>
          <span class="rules-content">
            {{ projectRulesData.quoteOutTimeAddTime }}
            {{ filterDictText(protproject_quoteOutTimeUnitList, projectRulesData.quoteOutTimeUnit) }}
          </span>
        </p>
        <p class="offer-rules-content clearfix">
          <span class="rules-title"> {{ filterDictText(protproject_quoteRangeTypeList, projectRulesData.quoteRangeType) }}:</span>
          <span class="rules-content">
            {{ projectRulesData.quoteRangePrice }}{{ projectRulesData.comparePriceType==='00'? '元' : '%' }}
          </span>
        </p>
        <p class="offer-rules-content clearfix">
          <span class="rules-title">是否公开竞价家数:</span>
          <span class="rules-content">
            {{ filterDictText(protproject_isPublicSupplierCountList, projectRulesData.isPublicSupplierCount) }}
          </span>
        </p>
        <p class="offer-rules-content clearfix">
          <span class="rules-title">是否公开竞价方名称:</span>
          <span class="rules-content">
            {{ filterDictText(protproject_isPublicSupplierNameList, projectRulesData.isPublicSupplierName) }}
          </span>
        </p>
        <p class="offer-rules-content clearfix">
          <span class="rules-title">是否公开报价金额:</span>
          <span class="rules-content">
            {{ filterDictText(protproject_isPublicSupplierPriceList, projectRulesData.isPublicSupplierPrice) }}
          </span>
        </p>
        <p class="offer-rules-content clearfix">
          <span class="rules-title">是否公开竞价排名:</span>
          <span class="rules-content">
            {{ filterDictText(protproject_isPublicSupplierRankingList, projectRulesData.isPublicSupplierRanking) }}
          </span>
        </p>
      </div>
    </div>
  </div>
</template>
<script>
/** api接口 */
import { getTime } from '@api/common/tools.js' // 获取服务器时间
import { endBidding } from '@/api/procurement/procurementOffer'
/* 公共方法*/
import { filterDictText } from '@/assets/js/utils'// 常用方法
/* 引入公共方法*/
import { procurementBiddingGroupMixin } from '../mixins/procurementBiddingGrounpMixins'
/* 公共组件 */
import countdown from '@comp/procurement/countdownCom/countdown' // 倒计时组件
export default {
  name: 'OfferLobbyRulesDetailVue',
  components: {
    'count-down': countdown
  },
  mixins: [procurementBiddingGroupMixin],
  props: {
    // 竞价规则
    projectRulesData: {
      type: Object,
      default: () => {
        return {}
      }
    },
    // 竞价状态 00竞价未开始 01竞价开始 02竞价结束
    biddingStatus: {
      type: String,
      default: ''
    },
    // 大厅类型 00采购 01供应商
    hallType: {
      type: String,
      default: ''
    }
  },
  inject: ['getTenderBase', 'getDriveTask'],
  data() {
    return {
      dictionaryType: ['protproject_quoteTimeUnit', 'protproject_quoteCountType', 'protproject_quoteOutTimeUnit', 'protproject_quoteRangeType', 'protproject_isPublicSupplierCount', 'protproject_isPublicSupplierName', 'protproject_isPublicSupplierPrice', 'protproject_isPublicSupplierRanking'], // 字典类型
      protproject_quoteTimeUnitList: [], // 竞价时长
      protproject_comparePriceMethodList: [], // 竞价方式
      protproject_quoteCountTypeList: [], // 竞价次数
      protproject_quoteOutTimeUnitList: [], // 超时竞价单位
      protproject_quoteRangeTypeList: [], // 报价幅度
      protproject_isPublicSupplierCountList: [], // 是否公开竞价家数
      protproject_isPublicSupplierNameList: [], // 是否公开竞价方名称
      protproject_isPublicSupplierPriceList: [], // 是否公开报价金额
      protproject_isPublicSupplierRankingList: [], // 是否公开竞价排名
      // 时间截止返回状态 布尔 默认true
      flag: '00',
      // 获取当前时间
      currentTimes: '',
      biddingText: '未开始',
      // 获取项目信息
      tenderBase: this.getTenderBase(),
      purchaseProjectStatus: this.getTenderBase().purchaseProjectStatus
    }
  },
  watch: {
    biddingStatus: {
      handler(val) {
        if (val === '00') {
          this.biddingText = '未开始'
        } else if (val === '01') {
        //   this.biddingText = '竞价进行中'
        // } else if (val === '02') {
          this.biddingText = '竞价结束'
        }
      },
      immediate: true
    }
  },
  created() {
    // 查询当前时间
    this.getCurrentTime()
    // 页面初始
    this.pageInit()
    console.log(this.projectRulesData)
  },
  methods: {
    // 字典检索
    filterDictText,
    // 页面初始
    pageInit() {
      // 获取字典信息
      this.$store.dispatch('getGroupType', this.dictionaryType).then((data) => {
        // 遍历key存储相应的数据
        for (const key in data.bidTypeData) {
          /* 是否有数据*/
          if (data.bidTypeData[key]) {
            this[key] = data.bidTypeData[key]
          }
        }
      })
    },
    // 监听倒计时截止状态
    countDownE_cb(type) {
      // 时间截止返回fasle
      this.flag = type
      if (!type) {
        this.biddingText = '进行中'
      }
    },
    // 获取当前时间
    getCurrentTime() {
      getTime().then(res => {
        this.currentTimes = res.data.time
      }).catch(() => {
      })
    },
    // 结束竞价
    endBidding() {
      const params = {
        packId: this.tenderBase.packId
      }
      endBidding(params).then(res => {
        this.$message({
          message: '操作成功！',
          type: 'success'
        })
        // 刷新驱动
        this.getDriveTask()
        // 关闭大厅
        this.closeHall()
      }).catch(() => {
      })
    },
    // 关闭大厅
    closeHall() {
      this.$emit('closeHall')
    }
  }
}
</script>

<style lang="less" scoped>
 @import "~@assets/style/procurement/procurement.bidding.less";

</style>
