infoList.js 1.7 KB
Newer Older
何秀钢 已提交
1
import { getDict } from '@/utils/dictionary'
2 3
import { formatTimeToStr } from '@/utils/date'

4
export default {
何秀钢 已提交
5 6 7 8 9 10 11 12 13 14
  data() {
    return {
      page: 1,
      total: 10,
      pageSize: 10,
      tableData: [],
      searchInfo: {}
    }
  },
  methods: {
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
    formatBoolean: function(bool) {
      if (bool !== null) {
        return bool ? '' : ''
      } else {
        return ''
      }
    },
    formatDate: function(time) {
      if (time !== null && time !== '') {
        var date = new Date(time)
        return formatTimeToStr(date, 'yyyy-MM-dd hh:mm:ss')
      } else {
        return ''
      }
    },
何秀钢 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
    filterDict(value, type) {
      const rowLabel = this[type + 'Options'] && this[type + 'Options'].filter(item => item.value === value)
      return rowLabel && rowLabel[0] && rowLabel[0].label
    },
    async getDict(type) {
      const dicts = await getDict(type)
      this[type + 'Options'] = dicts
      return dicts
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.getTableData()
    },
    handleCurrentChange(val) {
      this.page = val
      this.getTableData()
46
    },
47 48 49 50 51
    // @params beforeFunc function 请求发起前执行的函数 默认为空函数
    // @params afterFunc function 请求完成后执行的函数 默认为空函数
    async getTableData(beforeFunc = () => {}, afterFunc = () => {}) {
      beforeFunc()
      const table = await this.listApi({ page: this.page, pageSize: this.pageSize, ...this.searchInfo })
何秀钢 已提交
52 53 54 55 56 57
      if (table.code === 0) {
        this.tableData = table.data.list
        this.total = table.data.total
        this.page = table.data.page
        this.pageSize = table.data.pageSize
      }
58
      afterFunc()
59
    }
何秀钢 已提交
60 61
  }
}