<template>
  <div class="apass_list-container">
    <div class="apass_breadcrumb">
      <slot name="breadcrumb"></slot>
    </div>
    <div class="main-container">
      <div class="header-container" v-if="!hideHeader">
        <div class="header-left apass_button">
          <slot name="header-left"></slot>
        </div>
        <div class="header-center">
          <slot name="header-center"></slot>
        </div>
        <div class="header-right">
          <el-input
            v-model="searchFilter"
            prefix-icon="el-icon-search"
            :placeholder="searchPlaceholder"
            style="width:240px;"
            @input="searchAction"
          ></el-input>
        </div>
      </div>
      <div class="cross_line" v-if="!hideHeader"></div>
      <div class="list-container appas_table">
        <slot name="list"></slot>
      </div>
      <list-pagination
        :total="listTotal"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        :current-page="currentPage"
        @size-change="changePageSize"
        @current-change="changeCurrentPage"
      ></list-pagination>
    </div>
  </div>
</template>

<script>
import ListPagination from "@/components/comments-pagination";

export default {
  components: {
    ListPagination,
  },
  props: {
    listTotal: {
      type: Number,
      default: 0,
    },
    hideHeader: {
      type: Boolean,
      default: false,
    },
    searchPlaceholder: {
      type: String,
      default: "请输入关键字"
    }
  },
  data: () => ({
    searchFilter: "",
    pageSize: 10,
    currentPage: 1,
    timer: null,
    pageSizes: [10, 50, 100],
  }),
  methods: {
    searchAction(value) {
      this.listAction();
    },
    changePageSize(value) {
      this.pageSize = value;
      this.currentPage = 1;
      this.listAction();
    },
    changeCurrentPage(value) {
      this.currentPage = value;
      this.listAction();
    },
    listAction() {
      if (this.timer) {
        clearTimeout(this.timer);
      }

      this.timer = setTimeout(() => {
        this.$emit("list-action", {
          filter: this.searchFilter,
          pageSize: this.pageSize,
          currentPage: this.currentPage,
        });
      }, 200);
    },
  },
};
</script>

<style scoped>
.apass_list-container {
  padding: 0 20px;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  overflow: auto;
}
.main-container {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  padding: 0 20px 15px;
  background-color: #fff;
  border-radius: 10px;
  margin-bottom: 40px;
}
.header-container {
  padding-top: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.header-container .el-button + .el-button {
  margin-left: 25px;
}
.cross_line {
  border-top: 1px solid #e3e5ef;
  margin: 20px -20px 0;
}
.list-container {
  flex-grow: 1;
}
</style>
