import Pannel from '@/components/pannel/index.vue';
import HorizontalBar from '@/components/charts/horizontal-bar/index.vue';
import { resourceOverviewAnalysis } from '../../../../api/index.js'
import { mapGetters } from 'vuex';
export default {
  components: {
    HorizontalBar,
    Pannel
  },
  computed: {
    ...mapGetters(['year', 'deptId'])
  },
  watch: {
    year: {
      handler () {
        this.getData();
      },
      immediate: true, // 立即执行
    },
    deptId: {
      handler () {
        this.getData();
      },
      immediate: true, // 立即执行
    }
  },
  data () {
    return {
      isLoad: false,
      data: [
        {
          name: '农用地',
          value: '500',
          unit: '亩'
        },
        {
          name: '建设用地',
          value: '500',
          unit: '亩'
        },
        {
          name: '未利用地及林木',
          value: '500',
          unit: '亩'
        }
      ],
      barData: []
    };
  },
  methods: {
    getData () {
      if (this.year, this.deptId) {
        this.isLoad = false;
        resourceOverviewAnalysis(this.deptId, this.year).then(res => {
          this.data[0].value = res.data.nyd
          this.data[1].value = res.data.jsyd
          this.data[2].value = res.data.wlydjlm

          let barData = [
            {
              name: '闲置',
              value: res.data.xz
            },
            {
              name: '出租/出借',
              value: res.data.czcj
            }
          ]
          this.barData = barData;
          this.isLoad = true;
        })
      }
    }
  }
};
