const tableMixins = {
  data() {
    return {
      labelCol: { span: 4 }, // label宽
      wrapperCol: { span: 20 }, // item宽
      tableData: [], // table数据
      tableLoading: false, // 是否加载中
      sortOrder: 'descend', // 排序
      pagination: { // 分页
        current: 1, // 当前页码
        pageSize: 10, // 每页条数
        total: 0, // 总数
        showTotal: total => `共有${total}条数据`, // 显示总数
        pageSizeOptions: [10, 20, 50, 100], // 分页选项
        layout: 'total, sizes, prev, pager, next, jumper'
      }
    }
  },
  mounted() {
    this.initData()
  },
  methods: {
    getFilterParams() {
      const params = {
        pageNum: this.pagination.current,
        pageSize: this.pagination.pageSize,
        data: { ...this.transformFilterForm() }
      }
      return params
    },
    transformFilterForm() {
      return {}
    },
    setDataList(data) {
      this.pagination.total = data.total || 0
      this.tableData = data.list || []
    },
    handleSizeChange(current, size) {
      this.getTableList()
    },
    async resetFilterFormParams() {
      this.form = {}
      this.clearPageParams()
      await this.getTableList()
    },
    clearPageParams() {
      this.sortOrder = 'descend'
      this.pagination.current = 1
      this.pagination.pageSize = 10
    },
    onTableChange(pagination, filters, sorter) {
      this.sortOrder = sorter.order === 'descend' ? 'descend' : 'ascend'
      this.pagination = pagination
      this.tableChange(pagination, filters, sorter)
      this.getTableList()
    },
    tableChange(pagination, filters, sorter) {}
  }
}

export default tableMixins
