import Pannel from '@/components/pannel/index.vue';
import ScrollTable from '@/components/scroll-table/index.vue';
import PannelTabs from '@/components/pannel-tabs/index.vue';
import { rankingOfNonStandardFundTransactionsWarning } from '../../../../api/index.js';
import { mapGetters } from 'vuex';
export default {
  components: {
    PannelTabs,
    ScrollTable,
    Pannel
  },
  computed: {
    ...mapGetters(['year', 'deptId', 'deptLength'])
  },
  watch: {
    year: {
      handler () {
        this.getData();
      },
      immediate: true, // 立即执行
    },
    deptId: {
      handler () {
        this.getData();
      },
      immediate: true, // 立即执行
    }
  },
  data () {
    return {
      data: [],
      type: 'zc',
      pannelTabsData: [
        {
          id: '1',
          type: 'zc',
          name: '支出'
        },
        {
          id: '2',
          type: 'sr',
          name: '收入'
        }
      ],
      tabIndex: '1',
      isLoad: false,
      headers: ['部门名称', '支出金额', '排名']
    };
  },
  created () {
  },
  mounted () {
  },
  methods: {
    getData () {
      if (this.year, this.deptId) {
        this.isLoad = false;
        rankingOfNonStandardFundTransactionsWarning(this.deptId, this.year, this.type).then(res => {
          if (this.deptLength == 3){
            this.headers = ['摘要', '金额'];
            this.data = res.rows.map(item => {
              return [item.name, item.value]
            })
          }else{
            this.headers = ['部门名称', this.type == 'zc' ? '支出金额' : '收入金额', '排名']
            this.data = res.rows.map(item => {
              return [item.name, item.value, item.index]
            })
          }
          this.isLoad = true;
        })
      }
    },
    tabChange (info) {
      this.type = info.type;
      this.tabIndex = info.id
      this.headers = ['部门名称', info.type == 'zc' ? '支出金额' : '收入金额', '排名']
      this.getData()
    }
  }
};
