<template>
  <el-dialog
    class="database-sync-log-dialog"
    :visible.sync="modalIsShow"
    width="1000px"
    title="同步日志"
    top="10vh"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    append-to-body
    destroy-on-close
    @opened="visibleChange"
  >
    <el-table ref="TableList" :data="dataList">
      <el-table-column prop="dataType" label="同步数据类型"></el-table-column>
      <el-table-column prop="startTime" label="同步开始时间" width="170">
        <span slot-scope="scope">{{
          scope.row.startTime | timestampFilter
        }}</span>
      </el-table-column>
      <el-table-column prop="endTime" label="同步结束时间" width="170">
        <span slot-scope="scope">{{
          scope.row.endTime | timestampFilter
        }}</span>
      </el-table-column>
      <el-table-column prop="count" label="同步数量" width="90">
      </el-table-column>
      <el-table-column prop="errorMsg" label="失败原因"></el-table-column>
    </el-table>
    <div class="part-page">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :pager-count="5"
        :current-page="current"
        :total="total"
        :page-size="size"
        @current-change="toPage"
        @size-change="pageSizeChange"
      >
      </el-pagination>
    </div>

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

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

export default {
  name: "database-sync-log-dialog",
  props: {
    rowData: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  data() {
    return {
      modalIsShow: false,
      dataList: [],
      current: 1,
      size: this.GLOBAL.pageSize,
      total: 0,
    };
  },
  methods: {
    visibleChange() {
      this.toPage(1);
    },
    cancel() {
      this.modalIsShow = false;
    },
    open() {
      this.modalIsShow = true;
    },
    async getList() {
      const datas = {
        schoolId: this.rowData.schoolId,
        examId: this.rowData.examId,
        pageNumber: this.current,
        pageSize: this.size,
      };
      const data = await schoolSetDatabaseSyncLogList(datas);
      this.dataList = data.records;
      this.total = data.total;
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
  },
};
</script>
