<template>
  <div>
    <el-dialog
      custom-class="question-preview-dialog question-edit-log-dialog"
      :visible.sync="modalIsShow"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      append-to-body
      @open="openHandle"
    >
      <div class="box-justify" slot="title">
        <h2>修改记录</h2>
        <div>
          <el-button icon="el-icon-back" @click="cancel">返回</el-button>
        </div>
      </div>

      <div class="part-box">
        <el-table element-loading-text="加载中" :data="logList" border>
          <el-table-column label="内容" prop="detail"> </el-table-column>
          <el-table-column label="修改时间" width="180" prop="createTime">
            <template slot-scope="scope">
              {{ scope.row.createTime | timestampFilter }}
            </template>
          </el-table-column>
          <el-table-column label="修改人" prop="loginName" width="200">
            <template slot-scope="scope">
              {{ scope.row.realName }}（{{ scope.row.loginName }}）
            </template>
          </el-table-column>
        </el-table>
        <div class="part-page">
          <el-pagination
            :current-page="currentPage"
            :page-size="pageSize"
            :page-sizes="[10, 20, 50, 100, 200, 300]"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            @current-change="toPage"
            @size-change="handleSizeChange"
          >
          </el-pagination>
        </div>
      </div>

      <div slot="footer"></div>
    </el-dialog>
  </div>
</template>

<script>
import { paperEditLogsApi } from "../api";

export default {
  name: "PaperEditLogDialog",
  props: {
    paperId: {
      type: [String, Number],
      default: "",
    },
  },
  data() {
    return {
      modalIsShow: false,
      logList: [],
      currentPage: 1,
      pageSize: 10,
      total: 0,
    };
  },
  methods: {
    openHandle() {
      this.logList = [];
      this.toPage(1);
    },
    async toPage(page) {
      this.currentPage = page;
      await this.getList();
    },
    async getList() {
      const res = await paperEditLogsApi({
        thirdTableId: this.paperId,
        logType: "PAPER_CHANGE_RECORDS",
        pageNumber: this.currentPage,
        pageSize: this.pageSize,
      });

      this.logList = res.data.content;
      this.total = res.data.totalElements;
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.toPage(1);
    },
    cancel() {
      this.modalIsShow = false;
    },
    open() {
      this.modalIsShow = true;
    },
  },
};
</script>
