<template>
  <div class="app-container clue-container">
    <div class="common-title">商机线索</div>
    <el-tabs v-model="activeIndex" @tab-click="handleQuery" class="tabpane selfTab">
      <el-tab-pane label="按金额" name="0"></el-tab-pane>
      <el-tab-pane label="按项目" name="1"></el-tab-pane>
    </el-tabs>
    <div class="flex-box clue-box">
      <div class="clue-echarts"><div id="echartsClue" style="width: 100%;height:300px; margin: 0 auto;"></div></div>
      <div class="table-item">
        <el-table
          :data="viewData"
          border
          style="width: 100%"
          :default-sort = "{prop: 'date', order: 'descending'}"
        >
          <el-table-column
            prop="name"
            label="名称"></el-table-column>
          <el-table-column
            prop="value"
            label="数量">
          </el-table-column>
          <el-table-column
            prop="percent"
            label="占比">
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="flex-box clue-type">
      <div class="flex-box clue-type-item" :class="!item.count?'disab':''" v-for="(item, index) in typeList" :key="index" @click="handleType(item, index)"><img :src="!item.count?item.dis_ico:item.ico">{{item.name}}</div>
    </div>
  </div>
</template>

<script>
import {projectTenderDataGroup} from '@/api/detail/party-a/overview'
import * as echarts from 'echarts'
import {changePath} from "@/assets/js/common"
export default {
  name: 'Busclue',
  props: ['companyId', 'statistic'],
  data() {
    return {
      viewData:[],
      activeIndex:0,
      typeList:[
        {name: '土地交易', pathName: 'landtransaction', ico: require("@/assets/images/detail/overview/clue_ico1.png"), count: 0, category:'global', field:'landInfo', dis_ico: require("@/assets/images/detail/overview/clue_dis_ico1.png")},
        {name: '拟建项目', pathName: 'proposed', ico: require("@/assets/images/detail/overview/clue_ico2.png"), count: 0, category:'global', field:'proposedProject', dis_ico: require("@/assets/images/detail/overview/clue_dis_ico2.png")},
        {name: '专项债项目', pathName: 'bond', ico: require("@//assets/images/detail/overview/clue_ico3.png"), count: 0, category:'xxx', field:'yy', dis_ico: require("@/assets/images/detail/overview/clue_dis_ico3.png")},
        {name: '招标计划', pathName: 'biddingplan', ico: require("@/assets/images/detail/overview/clue_ico4.png"), count: 0, category:'xxx', field:'zz', dis_ico: require("@/assets/images/detail/overview/clue_dis_ico4.png")},
        {name: '招标公告', pathName: 'announcement', ico: require("@/assets/images/detail/overview/clue_ico5.png"), count: 0, category:'business', field:'biddingAnnouncement', dis_ico: require("@/assets/images/detail/overview/clue_dis_ico5.png")},
        {name: '标讯Pro', pathName: 'tencent', ico: require("@/assets/images/detail/overview/clue_ico6.png"), count: 0, category:'business', field:'proCount', dis_ico: require("@/assets/images/detail/overview/clue_dis_ico6.png")},
        {name: '行政许可', pathName: 'administrative', ico: require("@/assets/images/detail/overview/clue_ico7.png"), count: 0, category:'business', field:'adminLicensing', dis_ico: require("@/assets/images/detail/overview/clue_dis_ico7.png")},
      ]
    }
  },
  created() {
    this.handleStatistic()
    this.handleQuery()
  },
  mounted() {
  },
  methods: {
    async handleQuery(){
      let res = await projectTenderDataGroup({cid: this.companyId, type: this.activeIndex})
      if(res.code==200){
        let data = res.data, totalVal = data.map(item => item.value).reduce((prev, cur) => prev + cur)
        this.viewData = data.map(item => {
          let it = {name:item.name, value:item.value, percent:parseFloat(Number(Number(item.value)/Number(totalVal)*100).toFixed(2))+'%'}
          return it
        })
        this.getDT()
      }
    },
    getDT(val){
      let myChart = echarts.init(document.getElementById("echartsClue")), data = val ? val : this.viewData
      let option = {
        tooltip: {
          trigger: 'item',
          borderWidth:0,
          backgroundColor:"rgba(255, 255, 255, 0.8)",
          formatter: '{b}<br/>{d}%',
          extraCssText:'width:100px!important;',
        },
        legend: {
          type: 'scroll',
          orient: 'horizontal',
          bottom: 20,
          data: data,
          pageButtonPosition: 'end',
        },
        color: ['#8A82F3','#5B9CF7','#43BBE0','#8ECF95','#FFDC6B'],
        series: [
          {
            type: 'pie',
            radius: '55%',
            center: ['50%', '40%'],
            data: data,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      }
      myChart.setOption(option)
    },
    handleStatistic() {
      this.typeList.forEach((item, index) => {
        item.count = this.statistic[item.category]?this.statistic[item.category][item.field]:0
      })
    },
    handleType(it, idx){
      if(it.count){
        changePath(this, it.pathName)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
  .clue-container{
    margin: 0;
    padding: 24px 16px;
    background: #FFFFFF;
    border-radius: 4px;
    .selfTab{
      margin: 24px 0 0 -12px;
      ::v-deep .el-tabs__nav-wrap::after{
        display: none;
      }
      ::v-deep .el-tabs__item{
        height: 30px;
        line-height: 30px;
        padding: 0 12px;
      }
    }
    .clue-box{
      width: 100%;
      justify-content: space-between;
      align-items: normal;
      margin-top: 4px;
      .clue-echarts{
        width: calc(50% - 8px);
      }
      .table-item{
        width: calc(50% - 8px);
        ::v-deep .el-table--border .el-table__cell{
          border-bottom: 0;
        }
      }
    }
    .clue-type{
      width: 100%;
      justify-content: space-between;
      border-top: 1px solid #EEEEEE;
      padding-top: 22px;
      margin-right: -16px;
      margin-left: -16px;
      padding-left: 16px;
      padding-right: 16px;
      .clue-type-item{
        color: #232323;
        cursor: pointer;
        &:hover{
          color: #0081FF;
        }
        &.disab{
          color: rgba(35,35,35,0.4);
        }
        img{
          width: 40px;
          height: 40px;
          margin-right: 8px;
        }
      }
    }
  }
</style>
