<template>
  <div class="app-container">
    <div class="top-bar">
      <!-- <SearchBar :config="searchConfig" @search="search" @reset="reset" /> -->
    </div>
    <TablePage
      :data="list.records"
      :tableTitle="tableTitle"
    >
    </TablePage>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="Number(list.current)"
      :page-sizes="[10, 20, 40, 50]"
      :page-size="Number(list.size)"
      layout="total, sizes, prev, pager, next, jumper"
      :total="Number(list.total)"
      class="pagination"
    >
    </el-pagination>
  </div>
</template>

<script>
import TablePage from "@/components/Table/TablePage.vue";
import TableOperation from "@/components/Table/TableOperation.vue";
import { title  } from "./config";
import { getLogList } from "@/api/log";

import SearchBar from "@/components/SearchBar";

export default {
  components: {
    TablePage,
    TableOperation,
    SearchBar,
  },
  data() {
    return {
      list: {
        records: [],
        size: 10,
        current: 1,
        total: 0,
      },
      searchForm: {
        name: "",
        status: "",
      },
      searchConfig: [
        {
          prop: "name",
          type: "input",
          label: "文献名称",
        },
        {
          prop: "authors",
          type: "input",
          label: "作者",
        },
        {
          prop: "status",
          type: "select",
          label: "状态",
          selectOptions: [
            {
              label: "已上架",
              value: "1",
            },
            {
              label: "已下架",
              value: "0",
            },
          ],
        },
      ],
    };
  },

  computed: {
    tableTitle() {
      return title;
    },
    tableOperations() {
      return operations;
    },
    getStatusTitle(status) {
      return (status) => {
        if (Number(status)) {
          return "是否确定要下架？";
        } else {
          return "是否确定要上架？";
        }
      };
    },
  },
  mounted() {
    this.loadData();
  },
  methods: {
    async search(form) {
      var params = {
        page: this.list.current,
        limit: this.list.size,
        ...form,
      };
      if (params.status == "") {
        delete params.status;
      }
      console.log("params", params);
      let res = await getLogList(params);
      if (res.code == 0) {
        this.list = res.data;
      }
    },

    reset() {
      this.loadData();
    },

    //   加载表格数据
    async loadData() {
      var params = {
        page: this.list.current,
        limit: this.list.size,
      };
      let res = await getLogList(params);
      if (res.code == 0) {
        this.list = res.data;
      }
    },

    // 改变页容量
    handleSizeChange(value) {
      this.list.size = value;
      this.loadData();
    },

    // 改变当前显示页
    handleCurrentChange(value) {
      this.list.current = value;
      this.loadData();
    },
  },
};
</script>

<style lang="scss" scoped>
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.pagination {
  margin: 16px;
}
</style>