/* ------列表方法---------*/
import { formatDateTimeByType } from '@/utils/index.js';

// 分页
export const page = {
  methods: {
    refresh() {
      this.listParams.currentPage = 1;
      this.getTableList();
    },
    handleSizeChange(val) {
      this.listParams.pageSize = val;
      this.getTableList();
    },
    handleCurrentChange(val) {
      this.listParams.currentPage = val;
      this.getTableList();
    }
  }
};

export const formate = {
  methods: {
    // 处理dateTime，传入指定的key修改this.listParams
    // yyyy-MM-dd-HH-mm-ss
    formatterTimeFunc(sdate = 'startTime', edate = 'endTime', type = 'yyyy-MM-dd', dateTime = 'dateTime') {
      if (!this[dateTime]) {
        this.listParams[sdate] = this.listParams[edate] = '';
      } else {
        this.listParams[sdate] = formatDateTimeByType(this[dateTime][0], type);
        this.listParams[edate] = formatDateTimeByType(this[dateTime][1], type);
      }
    }
  }
};

export const getMainHeight = {
  methods: {
    mainHeight(offset = 0) { // offset是页面除去表格和分页的高度后其他部分的高度
      return this.$store.state.mainHeight - 52 - offset; // 52是分页占得高度
    }
  }
};
