<template>
  <div class="regionalEconomy">
    <div class="flex-box query-box">
      <div class="flex-box query-params">
        <span class="common-title">主要指标</span>
        <el-form ref="queryForm" :model="queryParams" :inline="true" size="small">
          <el-form-item prop="year">
            <el-select v-model="queryParams.year" filterable class="form-content-width" placeholder="请选择年度">
              <el-option v-for="(item, index) in yearOptions" :key="index" :label="item.year" :value="item.year" />
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <div class="flex-box query-ability">
        <span class="flex-box"><img src="@/assets/images/ability_excel.png">导出EXCEL</span>
      </div>
    </div>
    <div class="content">
      <div class="content-left">
        <div id="echarts"  style="height: 400px"></div>
        <p class="tips">  注：数据均来源于统计公报、统计年鉴，实际披露中由于部分地区最新年度数据不全，导致年份间数据差距较大</p>
      </div>
      <div class="content-right">
        <el-table
          v-loading="tableLoading"
          :data="tableData"
          height="440"
          border
          highlight-current-row
        >
          <el-table-column label="序号" width="60" align="left">
            <template slot-scope="scope">{{ pageIndex * pageSize - pageSize + scope.$index + 1 }}</template>
          </el-table-column>
          <el-table-column label="产业类型" prop="type"></el-table-column>
          <el-table-column label="2022年">
            <el-table-column prop="je" label="金额（亿元）"> </el-table-column>
            <el-table-column prop="zb" label="占比" sortable> </el-table-column>
          </el-table-column>
          <el-table-column label="2021年">
            <el-table-column prop="province" label="金额（亿元）" sortable> </el-table-column>
            <el-table-column prop="province" label="占比" sortable > </el-table-column>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
  import * as echarts from 'echarts';
  import { nationalPage,getYears } from '@/api/macro/macro'
export default {
  name: 'industrialStructure',
  props:{
    dataQuery:{}
  },
  data() {
    return {
      queryParams: {
        year: '',
        address: ''
      },
      yearOptions: [],
      tableData:[
        {
          type:'房建工程',
          je:'29,175.61',
          zb:'26%'
        },
        {
          type:'市政工程',
          je:'29,175.61',
          zb:'26%'
        },
        {
          type:'公路工程',
          je:'29,175.61',
          zb:'26%'
        },
        {
          type:'机电工程',
          je:'29,175.61',
          zb:'26%'
        },
      ],
      tableLoading: false,
      pageIndex: 1,
      pageSize: 10,
      tableDataTotal: 0,
      data:[
        {
          name: '房建工程',
          value: 11
        },
        {
          name: '市政工程',
          value: 22
        },
        {
          name: '公路工程',
          value: 33
        }
      ]
    }
  },
  created() {
    getYears({}).then(res => {
      this.yearOptions=res.data.reverse();
      this.queryParams.year = this.yearOptions[0].year;
    })
    this.$nextTick(()=>{
      this.initChart()
    })
  },
  methods: {
    handleClick() {

    },
    initChart() {
      let myChart = echarts.init(document.getElementById("echarts"))
      let option ={
        label: {
          formatter: function (info) {
            var value = info.value
            var treePathInfo = info.treePathInfo
            var treePath = []
            for (var i = 1; i < treePathInfo.length; i++) {
              treePath.push(treePathInfo[i].name)
            }
            let arr=[treePath[0]]
            arr.push(value)
            return arr.join('\n');
          },
        },
        //鼠标悬停时显示的样式
        tooltip: {
          extraCssText:'width:100px!important;',
          formatter: function (params){
            var result = ''
            result+='<p style="color: rgba(35,35,35,0.8);padding: 0;margin: 0;">'+ params.name +'</p>'
            result+='<p style="color: rgba(35,35,35,0.8);padding: 0;margin: 0;">'+ params.value +'</p>'
            return result
          },
        },
        series: [
          {
            type: 'treemap',
            top:'0',
            left:'0',
            right:'0',
            bottom:'20',
            breadcrumb: {
              show: false // 是否显示下面的面包屑导航
            },
            data: this.data
          }
        ]
      }
      myChart.setOption(option);
    }
  }
}
</script>

<style lang="scss" scoped>
  .regionalEconomy{
    width: 100%;
    background: #ffffff;
    padding: 16px;
    margin-top: 12px;
    border-radius: 4px;
    .el-form{
      margin-left: 24px;
      .el-form-item{
        margin: 0 !important;
        .form-content-width{
          width: 100px;
        }
      }
    }
    .content{
      margin-top: 22px;
      display: flex;
      justify-content: space-between;
      .content-left{
        width: 46%;
        .tips{
          color: rgba(35,35,35,0.4);
          font-size: 14px;
        }
      }
      .content-right{
        width: 50%;
      }
    }
  }
</style>
