import Pannel from '@/components/pannel/index.vue';
import BarSign from '@/components/charts/bar-sign/index.vue';
import PannelTabs from '@/components/pannel-tabs/index.vue';
import { mapGetters } from 'vuex';
import { warninganalysisofnonstandardfund } from '../../../../api/index.js';
export default {
  components: {
    BarSign,
    PannelTabs,
    Pannel
  },
  computed: {
    ...mapGetters(['year', 'deptId'])
  },
  watch: {
    year: {
      handler () {
        this.getData();
      },
      immediate: true, // 立即执行
    },
    deptId: {
      handler () {
        this.getData();
      },
      immediate: true, // 立即执行
    }
  },
  data () {
    return {
      pannelTabsData: [
        {
          id: '1',
          name: '支出'
        },
        {
          id: '2',
          name: '收入'
        }
      ],
      data: [],
      isLoad: false,
      tabIndex: '1'
    };
  },
  methods: {
    getData () {
      if (this.year, this.deptId) {
        this.isLoad = false;
        warninganalysisofnonstandardfund(this.deptId, this.year).then(res => {
          if (this.tabIndex == 1) {
            let arr = res.data.zc.map(item => {
              return {
                name: item.name,
                value: item.value
              }
            })
            this.data = arr
          } else if (this.tabIndex == 2) {
            let arr = res.data.sr.map(item => {
              return {
                name: item.name,
                value: item.value
              }
            })
            this.data = arr
          }
          this.isLoad = true;
        })
      }
    },
    tabChange (info) {
      this.tabIndex = info.id
      this.getData()
    },
    openTable(){
      this.$emit('openTable','不规范')
    }
  }
};
