<template>
  <div>
    <p-table-edit-pro 
 :id="$route.meta.menuId+'_99641'" 

      style="padding: 30px"
      :scroll="{ x: 3000 }"
      :columns="columns"
      :data-source="tableData"
      :hasRepairDataSource="true"
      :rowSelectType="false"
      :pagination="pagination"
      @change="paginationChange"
      rowKey="lineid"
    ></p-table-edit-pro>
  </div>
</template>

<script>
import { axios } from '@/utils/request'
export default {
  name: 'tablePagination',
  components: {},
  props: {
    requestConfig: {
      type: Object,
      default() {
        return {}
      }
    },
    columns: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
      pagination: {
        total: 0,
        pageSize: 10, //每页中显示10条数据
        current: 1,
        showSizeChanger: true,
        pageSizeOptions: ['10', '15', '20'], //每页中显示的数据
        showTotal: total => `共有 ${total} 条数据` //分页中显示总的数据
      },
      tableData: []
    }
  },
  created() {},
  mounted() {},
  computed: {},
  watch: {
    requestConfig: {
      handler(val) {
        this.pagination = {...this.pagination, ...this.requestConfig.params}
        this.pageEvent()
      },
      deep: true,
      immediate: true
    }
  },
  methods: {
    pageEvent() {
      let p = {}
      if (this.requestConfig.method == 'get') {
        p = {
          url: this.requestConfig.url,
          method: this.requestConfig.method,
          params: this.pagination
        }
      } else if (this.requestConfig.method == 'post') {
        p = {
          url: this.requestConfig.url,
          method: this.requestConfig.method,
          headers: { 'Content-Type': 'application/json' },
          data: this.pagination
        }
      }
      axios(p).then(res => {
        const list = res.data.list
        this.tableData = list
        this.pagination.total = Number(res.data.totalCount)
        this.pagination.pageSize = res.data.pageSize
        this.pagination.current = res.data.pageNum
      })
    },
    paginationChange(pagination) {
      console.log(pagination)
      this.pagination = pagination
      this.pagination.pageNum = pagination.current
      delete this.pagination.current
      console.log(this.pagination,'this.pagination')
      this.pageEvent()
    }
  }
}
</script>

<style></style>
