<template>
  <div class="app-container clue-container">
    <div class="common-title">商机线索</div>
    <el-tabs v-model="activeName" @tab-click="handleClick" class="tabpane selfTab">
      <el-tab-pane label="按金额" name="first"></el-tab-pane>
      <el-tab-pane label="按项目" name="second"></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="activeName=='first'?viewData:projectData"
          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="数量">
            <template slot-scope="scope">
              <div style="text-align: right">{{ scope.row.value }}</div>
            </template>
          </el-table-column>
          <el-table-column
            prop="percent"
            label="占比">
            <template slot-scope="scope">
              <div style="text-align: right">{{ scope.row.percent }}</div>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="flex-box clue-type">
      <div class="flex-box clue-type-item" :class="typeName==index&&!item.disabled?'on':item.disabled?'disab':''" v-for="(item, index) in typeList" :key="index" @click="handleType(item, index)"><img :src="item.disabled?item.dis_ico:item.ico">{{item.name}}</div>
    </div>
  </div>
</template>

<script>
import * as echarts from 'echarts'
export default {
  name: 'Busclue',
  data() {
    return {
      viewData:[
        {
          name:'7亿~12亿',
          value:'12',
          percent: '12%'
        },
        {
          name:'4亿~6亿',
          value:'2',
          percent: '12%'
        },
        {
          name:'1亿~3亿',
          value:'42',
          percent: '12%'
        },
        {
          name:'5000万~1亿',
          value:'2',
          percent: '12%'
        },
        {
          name:'5000万以下',
          value:'2',
          percent: '12%'
        },
      ],
      projectData:[
        {
          name:'公路工程',
          value:'22',
          percent: '12%'
        },
        {
          name:'房建工程',
          value:'12',
          percent: '12%'
        },
        {
          name:'水利工程',
          value:'32',
          percent: '12%'
        },
        {
          name:'铁路工程',
          value:'16',
          percent: '12%'
        },
        {
          name:'市政工程',
          value:'8',
          percent: '12%'
        },
      ],
      activeName:'first',
      typeName: 0,
      typeList:[
        {name: '土地交易', ico: require("@/assets/images/detail/overview/clue_ico1.png"), disabled: false, dis_ico: require("@/assets/images/detail/overview/clue_dis_ico1.png")},
        {name: '拟建项目', ico: require("@/assets/images/detail/overview/clue_ico2.png"), disabled: false, dis_ico: require("@/assets/images/detail/overview/clue_dis_ico2.png")},
        {name: '专项债项目', ico: require("@//assets/images/detail/overview/clue_ico3.png"), disabled: true, dis_ico: require("@/assets/images/detail/overview/clue_dis_ico3.png")},
        {name: '招标计划', ico: require("@/assets/images/detail/overview/clue_ico4.png"), disabled: false, dis_ico: require("@/assets/images/detail/overview/clue_dis_ico4.png")},
        {name: '招标公告', ico: require("@/assets/images/detail/overview/clue_ico5.png"), disabled: true, dis_ico: require("@/assets/images/detail/overview/clue_dis_ico5.png")},
        {name: '标讯Pro', ico: require("@/assets/images/detail/overview/clue_ico6.png"), disabled: false, dis_ico: require("@/assets/images/detail/overview/clue_dis_ico6.png")},
        {name: '行政许可', ico: require("@/assets/images/detail/overview/clue_ico7.png"), disabled: false, dis_ico: require("@/assets/images/detail/overview/clue_dis_ico7.png")},
      ]
    }
  },
  created() {
  },
  mounted() {
    this.$nextTick(()=>{
      this.getDT()
    })
  },
  methods: {
    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)
    },
    handleClick(){
      if(this.activeName=='first'){
        this.getDT(this.viewData)
      }else{
        this.getDT(this.projectData)
      }
    },
    handleType(it, idx){
      if(!it.disabled){
        this.typeName = idx
      }
    }
  }
}
</script>

<style lang="scss" scoped>
  .clue-container{
    margin: 0;
    padding: 24px 16px;
    background: #FFFFFF;
    .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;
        &.on{
          color: #0081FF;
        }
        &.disable{
          color: rgba(35,35,35,0.4);
        }
        img{
          width: 40px;
          height: 40px;
          margin-right: 8px;
        }
      }
    }
  }
</style>
