<template>
  <div class="m-page-container">
    <div class="simple flex justify-end">
      <el-pagination
        background
        small
        @current-change="handleCurrentChange"
        :current-page="currentPageNum"
        :page-size="pageSize"
        :page-sizes="[10, 20, 30]"
        layout="prev,pager,next"
        :total="total"
        :pager-count="5"
      ></el-pagination>
    </div>
    <div class="detail flex mt-3.5 items-center justify-end" v-if="!simple">
      <el-pagination
        background
        small
        @current-change="handleCurrentChange"
        :current-page="currentPageNum"
        :page-size="pageSize"
        layout="total,jumper"
        :total="total"
        :pager-count="5"
      ></el-pagination>
      <div class="confirm">{{ $t('lang.page.confirm') }}</div>
    </div>
  </div>
</template>
<script lang="ts">
import Vue from 'vue'
export default Vue.extend({
  name: 'pages',
  components: {},
  data() {
    return {
      currentPageNum: this.currentPage,
      firstPageBtnDisabled: true,
      lastPageBtnDisabled: false,
    }
  },
  props: {
    currentPage: {
      type: Number,
      default: 1,
    },
    pageSize: {
      type: Number,
      default: 10,
    },
    total: {
      type: Number,
      default: 0,
    },
    simple: {
      type: Boolean,
      default: true,
    },
  },
  watch: {
    currentPage(newVal) {
      this.currentPageNum = newVal
      this.firstPageBtnDisabled = this.currentPageNum === 1 ? true : false
      this.lastPageBtnDisabled =
        this.currentPageNum === this.lastPageNum ? true : false
    },
  },
  computed: {
    lastPageNum(): number {
      return Math.ceil(this.total / this.pageSize)
    },
  },
  methods: {
    handleCurrentChange(page: number) {
      this.firstPageBtnDisabled = page === 1 ? true : false
      this.lastPageBtnDisabled = page === this.lastPageNum ? true : false
      this.currentPageNum = page
      this.$emit('pageChange', page)
    },
    handleSizeChange(size: number) {
      this.$emit('sizeChange', size)
    },
  },
})
</script>
<style lang="scss">
$blue: #dee1e6;
$white: #6368de;

.m-page-container {
  .btn-prev,
  .btn-next {
    margin: 0 !important;
    height: 30px !important;
    min-width: 30px !important;
    background: white !important;
    border: 1px solid #dee1e6;
  }
  .btn-prev {
    border-right: none;
  }

  .el-pagination {
    .el-pager li:not(.disabled).active {
      background-color: $blue;
      color: #6368de;
    }
    .el-pager li {
      background: white;
      line-height: 30px;
      text-align: center;
      min-width: 30px !important;
      height: 30px;
      margin: 0 !important;
      font-weight: 500;
      font-size: 12px;
      border: 1px solid #dee1e6;
      border-right: none;
    }
    .el-pager li {
    }
  }
  .confirm {
    width: 58px;
    height: 30px;
    line-height: 30px;
    background: #2545cb;
    border-radius: 15px;
    padding: 0 5px;
    flex-shrink: 1;
    margin-left: 10px;
    display: inline-block;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #ffffff;
    text-align: center;
    cursor: pointer;
  }
  .el-pagination {
    padding: 0;
  }
  .el-pagination__jump {
    margin-left: 0;
    .el-input__inner {
      font-size: 12px;
    }
  }
  .el-pagination__sizes {
    margin: 0;
    .el-input {
      width: 84px;
      .el-input__inner {
        height: 22px;
        line-height: 22px;
        font-size: 12px;
      }
    }
  }
  .el-pagination__total,
  .el-pagination__jump {
    margin: 0;
    margin-left: 4px;
    font-size: 12px;
    font-family: PingFangSC;
    font-weight: 400;
    line-height: 30px !important;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #8093a7;
    height: 30px !important;
  }

  .el-pagination__editor.el-input {
    width: 65px;
    height: 30px;
    input {
      width: 100%;
      height: 100% !important;
    }
  }

  .first-pager,
  .last-pager {
    background: #f4f4f5;
  }
}
</style>
