<!--
  @description:竞价大厅-我的报价
  @Modifier:gmy
  @routerPath:/biddingLobby/offerLobbyBidding
  @date:2020/5/9-15:48
-->
<template>
  <div class="offer-my left-common">
    <p class="offer-mytit" style="padding-left: 10px">
      我的报价
    </p>
    <div class="offer-realTime">
      <ul class="real-time-ul">
        <li class="real-time-li clearfix">
          <div class="fl">
            <p style="color:#00CC00 " class="real-time-p">
              {{ myOffer.offerPriceNew }}
            </p>
            <p>当前报价({{ filterDictText(comparePriceTypeData, projectRulesData.comparePriceType) }})</p>
          </div>
          <div class="fr">
            <p class="real-time-p">
              {{ myOffer.offerPriceBegin }}
            </p>
            <p>起始报价({{ filterDictText(comparePriceTypeData, projectRulesData.comparePriceType) }})</p>
          </div>
          <div class="border-right" />
        </li>
        <li class="clearfix">
          <div class="fl">
            <p class="real-time-p">
              {{ myOffer.sort }}
            </p>
            <p>我的排名</p>
          </div>
          <div class="fr">
            <p class="real-time-p">
              {{ myOffer.num }}
            </p>
            <p>当前报价次数</p>
          </div>
          <div class="border-right" />
        </li>
      </ul>
      <div>
        <p style="color:red;height:16px">
          {{ realQoute }}
        </p>
        <!-- :min="comparePriceMin" :max="comparePriceMax" -->
        <el-input-number
          v-model="realnum"
          :disabled="projectRulesData.isBidding === '00'"
          :precision="2"
          class="offer-iptnum"
          size="medium"
          label=""
          @change="handleChange"
        />
        <el-button type="primary" style="width:100%;height:30px" :disabled="projectRulesData.isBidding === '00'" @click="offer">
          报价
        </el-button>
      </div>
    </div>
  </div>
</template>

<script>
/* api接口*/
import { getBidOfSupplier, addBidPriceOffer } from '@/api/procurement/procurementOffer'
/* 公共方法*/
import { filterDictText, numberChinese } from '@/assets/js/utils' // 数字转大写
import { procurementBiddingGroupMixin } from '../mixins/procurementBiddingGrounpMixins'
export default {
  name: 'OfferLobbyMyAddVue',
  mixins: [procurementBiddingGroupMixin],
  props: {
    // 竞价状态 00竞价未开始 01竞价开始 02竞价结束
    biddingStatus: {
      type: String,
      default: '00'
    },
    // 竞价规则
    projectRulesData: {
      type: Object,
      default: () => {}
    }
  },
  inject: ['getTenderBase'],
  data() {
    return {
      num: 0,
      realnum: this.projectRulesData.comparePrice, // 初始报价
      realQoute: '零元',
      quoteRangePrice: 10,
      myOffer: {
        num: 0, // 当前报价次数
        offerPriceBegin: '', // 起始报价
        offerPriceNew: '', // 当前报价
        sort: '' // 我的排名
      },
      // 获取项目信息
      tenderBase: this.getTenderBase()
    }
  },
  watch: {
    // 监听报价最小幅度字段quoteRangeType 00 无限制 01 有限制
    projectRulesData: {
      handler(val) {
        // 报价幅度
        if (val.quoteRangeType === '00') {
          // 报价幅度默认值
          this.quoteRangePrice = 10
        } else {
          // 获取竞价规则报价幅度值
          this.quoteRangePrice = this.projectRulesData.quoteRangePrice ? this.projectRulesData.quoteRangePrice : 10
        }
      },
      deep: true,
      immediate: true
    }
  },
  created() {
    // 获取我的报价
    this.getBidOfSupplierData(this.tenderBase.packId)
  },
  methods: {
    // 字典检索
    filterDictText,
    // 点击+-动态改变价格
    handleChange(value) {
      this.realQoute = numberChinese(value)
      this.realnum = value
    },
    // 获取计数器获取焦点事件 动态获取输入的值
    // hanldFocus(Event) {
    //   if (Event) {
    //     this.realQoute = numberChinese(Event)
    //     this.realnum = Event
    //   }
    // },
    // 获取我的报价
    getBidOfSupplierData(packId) {
      getBidOfSupplier(packId).then(res => {
        this.myOffer = res.data
        if (res.data.offerPriceNew !== 0) {
          this.realnum = res.data.offerPriceNew
          // 初始报价中文
          this.handleChange(this.realnum)
        }
      }).catch(() => {
      })
    },
    // 报价
    offer() {
      const params = {
        packId: this.tenderBase.packId,
        offerTotal: this.realnum
      }
      addBidPriceOffer(params).then(res => {
        // 获取我的报价
        this.getBidOfSupplierData(this.tenderBase.packId)
        // 更新页面图表内容
        this.$emit('reloadData')
        this.$message({
          message: '报价成功！',
          type: 'success'
        })
      }).catch(() => {
      })
    }
  }
}
</script>

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

</style>
