<template>
  <div class="pagination" v-if="total">
    <el-pagination
      :background="background"
      :layout="layout"
      :pager-count="5"
      :total="total"
      :current-page="current"
      :page-size="PageSize"
      :page-sizes="pageSizes"
      v-bind="$attrs"
      @current-change="changePagination"
      @size-change="changeSize"
      v-on="$listeners"
    >
    </el-pagination>
  </div>
</template>

<script>
import { pageSizeOptions } from "@/config";
export default {
  name: "YPagination",
  props: {
    total: {
      required: true,
      type: Number,
      default: 0,
    },
    pageSize: {
      required: true,
      type: Number,
      default: 10,
    },
    page: {
      required: true,
      type: Number,
      default: 1,
    },
    layout: {
      type: String,
      default: "total,prev,pager,next,sizes,jumper",
    },
    pageSizes: {
      type: Array,
      default: () => pageSizeOptions,
    },
    background: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {};
  },
  computed: {
    PageSize: {
      get() {
        return this.pageSize;
      },
      set(value) {
        this.$emit("update:pageSize", value);
      },
    },
    current: {
      get() {
        return this.page;
      },
      set(value) {
        this.$emit("update:page", value);
      },
    },
  },
  methods: {
    changePagination(cur) {
      this.current = cur;
      if (this.$listeners.change) {
        this.$listeners.change();
      }
      this.$emit("currentChange", cur);
    },
    changeSize(size) {
      this.PageSize = size;
      if (this.$listeners.change) {
        this.$listeners.change();
      }
      this.$emit("sizeChange", size);
    },
  },
};
</script>

<style lang="less" scoped></style>
