import Pannel from '@/components/pannel/index.vue';
import PieLegend from '@/components/charts/pie-legend/index.vue';
import { debtCategoryAnalysis } from '../../../../api/index.js';
import { mapGetters } from 'vuex';
export default {
  components: {
    PieLegend,
    Pannel
  },
  computed: {
    ...mapGetters(['year', 'deptId'])
  },
  watch: {
    year: {
      handler () {
        this.getData();
      },
      immediate: true, // 立即执行
    },
    deptId: {
      handler () {
        this.getData();
      },
      immediate: true, // 立即执行
    }
  },
  data () {
    return {
      isLoad: false,
      total: 0,
      data: []
    };
  },
  methods: {
    getData () {
      if (this.year, this.deptId) {
        this.total = 0
        this.isLoad = false;
        debtCategoryAnalysis(this.deptId, this.year).then(res => {
          // console.log('debtCategoryAnalysis', res);
          let total = 0
          let data = res.data.list.map(item => {
            total += item.value
            return {
              ...item,
              unit: '万元'
            }
          })
          this.total = total + '万元'
          this.data = data;
          this.isLoad = true;
        })
      }
    }
  }
};
