<template>
  <div>
      <div class="d-flex search-box jc-end">
        <el-select v-model="selectType" size="mini" @change="getRevenueYear">
            <el-option
                v-for="item in typeList"
                :key="item"
                :label="item"
                :value="item">
            </el-option>
        </el-select>
        <el-select v-model="selectYear" size="mini"  @change="getRevenue('')">
            <el-option
                v-for="item in yearList"
                :key="item"
                :label="item"
                :value="item">
            </el-option>
            </el-select>
        </div>
        <barChart @downData="downData" :message="dataList" idstr="revenueStatistics" class="heightCut68"></barChart>
  </div>
</template>

<script>
import barChart from '@/components/echarts/barChart' // 营收统计 柱图
import * as API_OPERATION from '@/api/con.operation'
export default {
  components: { barChart },
  data () {
    return {
      selectId: '',
      selectType: '合同收入',
      typeList: ['合同收入', '项目收入', '切分收入'],
      selectYear: '',
      yearList: [],
      dataList: {}
    }
  },
  mounted () {
    this.getRevenueYear()
  },
  methods: {
    async getRevenueYear () {
      const _data = await API_OPERATION.getRevenueYear({ type: this.selectType })
      this.yearList = _data.data
      this.selectYear = this.yearList[0]
      this.getRevenue()
    },
    async getRevenue (param, isLeaf) {
      this.selectId = param || null
      const _data = await API_OPERATION.getRevenue({ center: this.selectId, type: this.selectType, date: this.selectYear })
      this.dataList = {
        parentId: param || '',
        isLeaf: isLeaf,
        xAxis: _data.data.xAxis,
        idxs: _data.data.idxs,
        data: _data.data.data
      }
    },
    downData (item) {
      console.log('传来的值:', item)
      if (!item) {
        this.getRevenue('', false)
      } else {
        this.getRevenue(item, true)
      }
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
