<template>
  <div id="page">
    <van-pagination v-model="currentPage" @change="changePage" :total-items="total" :items-per-page="limit" :show-page-size="5" force-ellipses />
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
export default {
  name: 'page',
  props: {
    total: { type: Number },
    limit: { type: Number, default: () => 5 },
  },
  components: {},
  data: function() {
    return {
      currentPage: 1,
    };
  },
  created() {},
  methods: {
    changePage(page) {
      this.$emit('search', { skip: (page - 1) * this.limit });
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    total: {
      deep: true,
      immediate: true,
      handler(val) {
        // 查询条件，重置页码
        if (val) this.$set(this, `currentPage`, 1);
      },
    },
  },
};
</script>

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