import { mapGetters, mapActions } from 'vuex';

export default {
  data() {
    return {
      filters: {},
      selected: {},
      selectedList: [],
      editType: 0,
      dialogEditVisible: false,
    };
  },
  computed: {
    ...mapGetters(['loading', 'campusList']),
  },
  created() {
    let campusPromise = null;
    if (this.campusList && this.campusList.length) {
      campusPromise = new Promise(resolve => resolve());
    } else {
      campusPromise = this.fetchCampusList();
    }
    campusPromise.then(() => {
      if (this.campusId) {
        this.filters.campusId = this.campusId;
      } else if (this.campusList.length === 1) {
        this.filters.campusId = this.campusList[0].oldCampusid;
      }
    });
  },
  methods: {
    ...mapActions(['fetchCampusList']), //权限校区
    fetchList() {},
    searchList() {
      this.changePage(1);
    },
    refreshList() {
      this.changePage(1);
    },
    getFilters() {
      let filters = this.$getFilters(this.filters);
      return filters;
    },
    changePage(index) {
      const filters = this.getFilters();
      this.fetchList({
        ...filters,
        pageNum: index,
      });
    },
    changeSizeHandle(pageSize) {
      const filters = this.getFilters();
      this.fetchList({
        ...filters,
        pageNum: 1,
        pageSize: pageSize,
      });
      this.updatePagination({
        pageNum: 1,
        pageSize: pageSize,
      });
    },
    handleSelectionChange(val) {
      this.selectedList = val;
    },
  },
};
