import Pannel from '@/components/pannel/index.vue';
import PannelTabs from '@/components/pannel-tabs/index.vue';
import Bar from '@/components/charts/bar/index.vue';
import { resourceTypeAnalysis } from '../../../../api/index.js'
import { mapGetters } from 'vuex';
export default {
  components: {
    Bar,
    PannelTabs,
    Pannel
  },
  computed: {
    ...mapGetters(['year', 'deptId'])
  },
  watch: {
    year: {
      handler () {
        this.getData();
      },
      immediate: true, // 立即执行
    },
    deptId: {
      handler () {
        this.getData();
      },
      immediate: true, // 立即执行
    }
  },
  data () {
    return {
      isLoad: false,
      pannelTabData: [
        {
          id: '1',
          name: '农用地'
        },
        {
          id: '2',
          name: '建设用地'
        },
        {
          id: '3',
          name: '未利用地'
        }
      ],
      data: [],
      tabIndex: '1'
    };
  },
  methods: {
    getData () {
      if (this.year, this.deptId) {
        this.isLoad = false;
        resourceTypeAnalysis(this.deptId, this.year).then(res => {
          if (this.tabIndex == 1) {
            this.data = res.data.nyd

          } else if (this.tabIndex == 2) {
            this.data = res.data.jsyd

          } else if (this.tabIndex == 3) {
            this.data = res.data.wlydjlm
          }
          this.isLoad = true;
        })
      }
    },
    tabChange (info) {
      this.tabIndex = info.id
      this.getData();
    }
  }
};
