import Pannel from '@/components/pannel/index.vue';
import Bar from '@/components/charts/bar/index.vue';
import PannelTabs from '@/components/pannel-tabs/index.vue';
import { mapGetters } from 'vuex';
import { analysisSensitiveWarningForFundTransactions } from '../../../../api/index.js';
export default {
  components: {
    PannelTabs,
    Bar,
    Pannel
  },
  data () {
    return {
      isLoad: false,
      tabIndex: '1',
      pannelTabsData: [
        {
          id: '1',
          name: '支出'
        },
        {
          id: '2',
          name: '收入'
        }
      ],
      data: []
    };
  },
  computed: {
    ...mapGetters(['year', 'deptId'])
  },
  watch: {
    year: {
      handler () {
        this.getData();
      },
      immediate: true, // 立即执行
    },
    deptId: {
      handler () {
        this.getData();
      },
      immediate: true, // 立即执行
    }
  },
  methods: {
    // 获取数据
    getData () {
      if (this.year || this.deptId) {
        this.isLoad = false;
        analysisSensitiveWarningForFundTransactions( this.deptId, this.year).then(res => {
          if (this.tabIndex == 1) {
            this.data = res.data.zc
          } else if (this.tabIndex == 2) {
            this.data = res.data.sr
          }
          this.isLoad = true;
        })

      }
    },
    tabChange (info) {
      this.tabIndex = info.id
      this.getData()
    },
    openTable(){
      this.$emit('openTable','敏感')
    }
  }
};
