import Pannel from '@/components/pannel/index.vue';
import ScrollTable from '@/components/scroll-table/index.vue';
import { mapGetters } from 'vuex';
import { contractExpirationWarning } from '../../../../api/index.js';
export default {
  components: {
    ScrollTable,
    Pannel
  },
  data () {
    return {
      isLoad: false,
      headers: ['合同编码', '合同名称', '合同截止日期', '部门'],
      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;
        contractExpirationWarning(this.deptId, this.year).then(res => {
          // console.log('contractExpirationWarning', res);
          let data = res.data.map(item => {
            return [item.code, item.name, item.endTime, item.deptName]
          })
          this.data = data;
          this.isLoad = true;
        })
      }
    },
  }
};
