<template>
  <div class="flex-box app-container part-container">
    <div class="bid-zbph">
      <div class="common-title">招标偏好</div>
      <template v-if="dataAll.totalCount||dataAll.lastYearCount||dataAll.bidAmount||this.dtdata.length>0">
        <div class="flex-box zbph-item">
          <div>历史招标总数
            <el-popover
              placement="top-start"
              trigger="hover"
              content="统计企业历年来公开招标总数">
              <img src="@/assets/images/detail/overview/zbph_question.png" style="width: 12px; height: 12px;" slot="reference">
            </el-popover>
            <span class="zbph-item-num">{{dataAll.totalCount || '--'}}</span></div>
          <div>近一年招标总数
            <el-popover
              placement="top-start"
              trigger="hover"
              content="统计企业近一年公开招标总数">
              <img src="@/assets/images/detail/overview/zbph_question.png" style="width: 12px; height: 12px;" slot="reference">
            </el-popover>
            <span class="zbph-item-num">{{dataAll.lastYearCount || '--'}}</span></div>
          <div>历史招标总额（万元）
            <el-popover
              placement="top-start"
              trigger="hover"
              content="统计企业历年来公开招标项目总金额">
              <img src="@/assets/images/detail/overview/zbph_question.png" style="width: 12px; height: 12px;" slot="reference">
            </el-popover>
            <span class="zbph-item-num">{{dataAll.bidAmount?parseFloat(dataAll.bidAmount.toFixed(6)):'--'}}</span></div>
        </div>
        <div class="zbph-account">招标动态
          <div class="labels">
            <div :class="{'on':datatype==3}" @click="getDT(3)">周</div>
            <div :class="{'on':datatype==2}" @click="getDT(2)">月</div>
            <div :class="{'on':datatype==1}" @click="getDT(1)">年</div>
          </div>
        </div>
        <div id="myEcharts" style="width: 100%;height:250px; margin: 0 auto;"></div>
      </template>
      <div class="bid-no-data" v-else>
        <no-data />
      </div>
    </div>
    <div class="bid-ywwl">
      <div class="common-title">业务往来供应商TOP5</div>
      <div class="table-item">
        <el-table
          :data="tableData"
          style="width: 100%"
        >
          <el-table-column
            prop="ico"
            width="55"
            label="排行">
            <template slot-scope="scope">
              <img class="ywwl-ico" :src="scope.row.ico">
            </template>
          </el-table-column>
          <el-table-column
            prop="companyName"
            label="公司名称">
            <template slot-scope="scope">
              <router-link :to="`/company/${encodeStr(scope.row.companyId)}`" tag="a" class="a-link">{{ scope.row.companyName }}</router-link>
            </template>
          </el-table-column>
          <el-table-column
            prop="count"
            width="160"
            label="合作次数">
          </el-table-column>
          <el-table-column
            prop="amount"
            width="160"
            label="合作总金额（万元）">
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import {encodeStr} from "@/assets/js/common"
import {bidDataGroup, supplierPage} from '@/api/detail/party-a/overview'
import * as echarts from 'echarts'
import NoData from '../../component/noData'
export default {
  name: 'Bidding',
  props: ['companyId'],
  components: {
    NoData
  },
  data() {
    return {
      encodeStr,
      datatype:'3',//切换类型
      dataAll: {},
      dtdata:[],//数据
      dttime:[],//坐标
      //表格数据
      tableData:[]
    }
  },
  created() {
    this.handleBid()
    this.handleSupplier()
  },
  mounted() {
  },
  methods: {
    async handleBid(){
      let res = await bidDataGroup({cid: this.companyId, spanId: this.datatype})
      if(res.code==200){
        let {totalCount, lastYearCount, bidAmount} = res.data
        this.dataAll = {totalCount, lastYearCount, bidAmount}
        this.dtdata=res.data.groupCount.map(item=>{
          return item.count
        })
        this.dttime=res.data.groupCount.map(item=>{
          return item.span
        })
        if(this.dtdata.length>0&&this.dttime.length>0){
          this.$nextTick(() => {
            this.initDT(this.dtdata,this.dttime)
          })
        }
      }
    },
    async handleSupplier() {
      let res = await supplierPage({cid: this.companyId, sort: 1, pageNum: 1, pageSize: 5})
      if(res.code==200){
        this.tableData = res.rows
        this.tableData.forEach((item, index) => {
          item.amount = item.amount?parseFloat(item.amount.toFixed(6)):0
          item.ico = require(`@/assets/images/detail/overview/ywwl_top${index+1}.png`)
        })
      }
    },
    initDT(datas,labels){
      let myChart = echarts.init(document.getElementById("myEcharts"))
      let option = {
        xAxis: {
          type: 'category',
          data: labels
        },
        yAxis: {
          type: 'value'
        },
        grid:{
          left:'6%',
          top:'8%',
          right:'2%',
          bottom:'8%',
        },
        tooltip:{
          axisPointer:{ //悬浮于圆点展示标签
            type:'axis'
          },
          borderWidth:0,
          backgroundColor:"rgba(255, 255, 255, 0.8)",
          formatter: '{a}<br/>{c}',
          extraCssText:'width:100px!important;',
        },
        series: [
          {
            name: '招标数',
            data: datas,
            type: 'line',
            smooth: true,
            itemStyle: {
              normal:{
                color:'#0081FF'
              }
            },
            label:{
              normal:{
                show:false
              }
            },
            areaStyle: {
              color: {
                type: 'linear',
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [{
                  offset: 0, color: 'rgba(0, 129, 255, 0.5)'
                }, {
                  offset: 1, color: 'rgba(0, 129, 255, 0)'
                } ],
                global: false
              }
            },
          }
        ]
      }
      myChart.setOption(option)
    },
    getDT(type){
      this.datatype = type
      this.handleBid()
    }
  }
}
</script>

<style lang="scss" scoped>
  .part-container{
    margin: 0;
    padding: 0;
    justify-content: space-between;
    align-items: normal;
    .bid-zbph{
      width: calc(50% - 8px);
      padding: 24px 16px;
      background: #FFFFFF;
      overflow: hidden;
      border-radius: 4px;
      .zbph-item{
        justify-content: space-around;
        padding-top: 26px;
        >div{
          width: 33%;
          font-size: 12px;
          color: #3D3D3D;
          text-align: center;
          border-left: 1px solid #EEEEEE;
          &:first-child{
            border-left: 0;
          }
          img{
            display: inline;
            vertical-align: text-top;
          }
          .zbph-item-num{
            font-weight: bold;
            display: block;
            padding-top: 8px;
          }
        }
      }
      .bid-no-data{
        margin-top: 16px;
      }
      .zbph-account{
        position: relative;
        font-weight: bold;
        margin-top: 35px;
        font-size: 14px;
        .labels{
          width: 120px;
          height: 22px;
          position: absolute;
          border-radius: 2px;
          right: 0;
          top: 2px;
          >div{
            width: 40px;
            height: 100%;
            text-align: center;
            line-height: 22px;
            float: left;
            border: 1px solid #EFEFEF;
            margin-left: -1px;
            font-weight: 400;
            font-size: 12px;
            color: rgba(35, 35, 35, 0.80);
            cursor: pointer;
            &.on{
              background: #0081FF;
              color: #FFFFFF;
            }
            &:first-child{
              border-radius: 2px 0px 0px 2px;
            }
            &:last-child{
              border-radius: 0px 2px 2px 0px;
            }
          }
        }
      }
    }
    .bid-ywwl{
      width: calc(50% - 8px);
      padding: 24px 16px;
      background: #FFFFFF;
      border-radius: 4px;
      .table-item{
        margin-top:15px;
        .ywwl-ico{
          width: 36px;
          height: 36px;
          margin-left: -6px;
        }
        ::v-deep .el-table .el-table__body-wrapper tr:nth-child(2n){
          background: #FFFFFF;
        }
      }
    }
  }
</style>
