import Pannel from '@/components/pannel/index.vue';
import ScrollTable from '@/components/scroll-table/index.vue';
import { mapGetters } from 'vuex';
import { longTermIdleResourceWarning } from '../../../../api/index.js';
export default {
  components: {
    ScrollTable,
    Pannel
  },
  computed: {
    ...mapGetters(['year', 'deptId'])
  },
  watch: {
    year: {
      handler () {
        this.getData();
      },
      immediate: true, // 立即执行
    },
    deptId: {
      handler () {
        this.getData();
      },
      immediate: true, // 立即执行
    }
  },
  data () {
    return {
      isLoad: false,
      headers: ['资源名称', '类别', '面积（亩）', '部门'],
      data: [
        ['资源名称', '类别', '面积（亩）', '部门']
      ]
    };
  },
  methods: {
    getData () {
      if (this.year, this.deptId) {
        this.isLoad = false;
        longTermIdleResourceWarning(this.deptId, this.year).then(res => {
          let data = res.data.map(item => {
            return [item.name, item.resourceSort, item.totalArea, item.deptName]
          })
          this.data = data;
          this.isLoad = true;
        })
      }
    },
  }

};
