import Pannel from '@/components/pannel/index.vue';
import ScrollTable from '@/components/scroll-table/index.vue';
import PannelTabs from '@/components/pannel-tabs/index.vue';
import { rankinganalysisofcontractquantityandamount } from '../../../../api/index.js'
import { mapGetters } from 'vuex'
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 {
      id: '1',
      isLoad: false,
      data: [],
      headers: ['部门名称', '数量', '排名'],
      pannelTabData: [
        {
          id: '1',
          name: '数量'
        },
        {
          id: '2',
          name: '金额'
        }
      ]
    };
  },
  created () {
  },
  mounted () {
  },
  methods: {
    getData () {
      if (this.year, this.deptId) {
        this.isLoad = false;
        rankinganalysisofcontractquantityandamount(this.deptId, this.year, 100).then(res => {
          if (this.id == 1) {
            let data = res.data.sl.map(item => {
              return [item.name, item.value, item.index]
            })
            this.data = data;
          } else if (this.id == 2) {
            let data = res.data.je.map(item => {
              return [item.name, item.value, item.index]
            })
            this.data = data;
          }
          this.isLoad = true;
        })
      }
    },
    tabChange (info) {
      this.id = info.id
      this.getData()

    }
  }
};
