import Pannel from '@/components/pannel/index.vue';
import PannelTabs from '@/components/pannel-tabs/index.vue';
import Bar from '@/components/charts/bar/index.vue';
import { resourceOutsourcingAnalysis } from '../../../../api/index.js'
import { mapGetters } from 'vuex'
import PopWindow from '@/components/pop-window/index.vue';
import MyTable from './my-table/index.vue';

export default {
  components: {
    MyTable,
    PopWindow,
    Bar,
    PannelTabs,
    Pannel
  },
  computed: {
    ...mapGetters(['year', 'deptId'])
  },
  watch: {
    year: {
      handler () {
        this.getData();
      },
      immediate: true, // 立即执行
    },
    deptId: {
      handler () {
        this.getData();
      },
      immediate: true, // 立即执行
    }
  },
  data () {
    return {
      popIsOpen: false,
      isLoad: false,
      pannelTabData: [
        {
          id: '1',
          name: '闲置'
        },
        {
          id: '2',
          name: '出租'
        }
      ],
      tabIndex: '1',
      barData:[]
    };
  },
  created () {
  },
  mounted () {
  },
  methods: {
    closePop () {
      this.popIsOpen = false
    },
    titleCilck () {
      this.popIsOpen = true
    },
    /**
     * 打开弹窗
     */
    openPop () {

    },
    getData () {
      if (this.year, this.deptId) {
        this.isLoad = false;
        resourceOutsourcingAnalysis(this.deptId, this.year).then(res => {
          if (this.tabIndex == 1) {
            this.barData = res.data.xz

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

          }
          this.isLoad = true;
        })
      }
    },
    tabChange (info) {
      this.tabIndex = info.id
      this.getData()
    }
  }
};
