import Pannel from '@/components/pannel/index.vue';
import ScrollTable from '@/components/scroll-table/index.vue';
import PannelTabs from '@/components/pannel-tabs/index.vue';
import { mapGetters } from 'vuex';
import { analysisOfAmountRanking } from '../../../../api/index.js';
export default {
  components: {
    PannelTabs,
    ScrollTable,
    Pannel
  },
  computed: {
    ...mapGetters(['year', 'deptId'])
  },
  watch: {
    year: {
      handler () {
        this.getData();
      },
      immediate: true, // 立即执行
    },
    deptId: {
      handler () {
        this.getData();
      },
      immediate: true, // 立即执行
    }
  },
  data () {
    return {
      tabIndex: '1',
      isLoad: false,
      headers: ['部门名称', '数量', '排名'],
      pannelTabData: [
        {
          id: '1',
          name: '数量'
        },
        {
          id: '2',
          name: '金额'
        }
      ],
      data: []
    };
  },
  methods: {
    getData () {
      if (this.year, this.deptId) {
        this.isLoad = false;
        analysisOfAmountRanking(this.deptId, this.year, 100).then(res => {
          if (this.tabIndex == 1) {
            this.headers = ['部门名称', '数量(个)', '排名'];
            let data = res.data.sl.map(item => {
              return [item.name, item.value, item.index]
            })
            this.data = data
          } else if (this.tabIndex == 2) {
            this.headers = ['部门名称', '金额(万元)', '排名'];
            let data = res.data.je.map(item => {
              return [item.name, item.value, item.index]
            })
            this.data = data
          }
          this.isLoad = true;
        })
      }
    },
    tabChange (info) {
      this.tabIndex = info.id;
      this.getData();
    }
  }
};
