<template>
  <div class="pa-3 white fill-height d-flex flex-column">
    <page-search @getPageList="getPageList" />
    <page-date :lists="lists" :pagination="pagination" @getPageList="getPageList" />
  </div>
</template>

<script>
import PageSearch from 'components/Page/PageSearch.vue';
import PageDate from 'components/Page/PageDate.vue';
import { getPageList } from 'config/api';

export default {
  name: 'PageManage',
  components: {
    PageSearch,
    PageDate,
  },

  data() {
    return {
      lists: [],
      pagination: { current: 1, pageSize: 10 },
    };
  },

  created() {
    this.getPageList();
  },

  methods: {
    /**
     * 页面列表查询
     * @param { String } pageNum 页码
     * @param { String } pageSize 每页多少条
     * @param { String } titleCode 模块
     */
    async getPageList(condition) {
      try {
        const params = {
          param: {
            pageNum: (condition && condition.current) || 1,
            pageSize: (condition && condition.pageSize) || 10,
            titleCode: (condition && condition.titleCode) || '',
          },
        };
        const res = await getPageList(params);
        const { code, msg, data } = res.data;
        if (code === 200) {
          this.lists = data.list;
          const paper = { ...this.pagination };
          paper.current = data.pageNum;
          paper.total = +data.total;
          paper.pageSize = data.pageSize;
          this.pagination = paper;
        } else {
          throw msg || '获取失败';
        }
      } catch (error) {
        this.$message.error(error);
      }
    },
  },
};
</script>
