<template>
  <el-card header="经营数据">
    <statistic :col="5" class="statistic" :cols="0">
      <statistic-item v-for="(item, key) in items" :key="key" :class="{active: active === key}" @click="active = key">
        <span>
          {{item.title}}
          <el-tooltip v-if="item.desc" :content="item.desc" :open-delay=".3" placement="top">
            <i style="margin-left: 5px;cursor: pointer;" class="el-icon-warning-outline"/>
          </el-tooltip>
        </span>
        <span>
          <count-to :endVal="item.percent"/>
        </span>
      </statistic-item>
    </statistic>
    <ve-line :settings="{
      area: true,
    }" :data="chartData" height="350px" :data-empty="dataEmpty"/>
  </el-card>
</template>
<script>
import countTo from 'vue-count-to'
import veLine from 'v-charts/lib/line.common'
export default {
  props: ['data'],
  components: {
    've-line': veLine,
    'count-to': countTo
  },
  computed: {
    items() {
      return {
        SHOULD_INCOME_MONEY: this.data['SHOULD_INCOME_MONEY'] || {},
        ANTICIPATED_INCOME_MONEY: this.data['ANTICIPATED_INCOME_MONEY'] || {},
        SHOULD_EXPEND_MONEY: this.data['SHOULD_EXPEND_MONEY'] || {},
        ANTICIPATED_EXPEND_MONEY: this.data['ANTICIPATED_EXPEND_MONEY'] || {},
        REVENUE_MONEY: this.data['REVENUE_MONEY'] || {},
      }
    },
    chartData() {
      const data = this.data[this.active] || {}
      const values = Object.values(this.items)
      const months = {}
      for (const item of values) {
        for (const row of (item.indexMonthData || [])) {
          const key = this.$helpers.dayjs(row.month).month() + 1 + '月'
          if (!months[key]) {
            months[key] = {
              '月份': key,
            }
          }
          months[key][item.title] = row.percent
        }
      }
      return {
        columns: ['月份', ...values.map(item => item.title)],
        rows: Object.values(months)
      }
    },
    dataEmpty() {
      return !this.chartData.rows.length
    },
  },
  data () {
    return {
      active: 'SHOULD_INCOME_MONEY',
    }
  },
}
</script>
<style lang="less" scoped>
  // .statistic{
  //   /deep/ .statistic-content{
  //     cursor: pointer;
  //     &.active > span{
  //       color: #14928a !important;
  //     }
  //   }
  // }
</style>
