import Pannel from '@/components/pannel/index.vue';
import PannelTabs from '@/components/pannel-tabs/index.vue';
import Bar from '@/components/charts/bar/index.vue';
import { analysisOfFixedAssetTypes } 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: '非经营性'
        }
      ],
      data: [],
      tabIndex: '1'
    };
  },
  methods: {
    getData () {
      if (this.year && this.deptId) {
        this.isLoad = false;
        analysisOfFixedAssetTypes(this.deptId, this.year).then(res => {
          if (this.tabIndex == 1) {
            this.data = res.data.jyx
          } else if (this.tabIndex == 2) {
            this.data = res.data.fjyx
          }
          this.isLoad = true;
        })
      }
    },
    tabChange (info) {
      this.tabIndex = info.id
      this.getData()
    }
  }
};
