<template>
  <!-- 用户操作日志 -->
  <div class="leakage-cable">
    <div class="leakage-top">
      <div style="color: #666666"></div>
      <div class="operate-btn">
        <el-button type="primary" @click="getTableData">刷新</el-button>
        <el-button type="primary" @click="isQuery = !isQuery">查询</el-button>
        <el-button type="primary" @click="exportLog">导出</el-button>
      </div>
    </div>
    <div v-if="isQuery">
      <search @search="getTableData" />
    </div>
    <el-table
      :data="tableData"
      style="width: 100%"
      class="statistics-table"
      :row-class-name="tableRowClassName"
      :row-style="{ height: '50px' }"
      :header-cell-style="{ background: '#EAF1FE', color: '#666666' }"
    >
      <el-table-column prop="userName" label="用户名" align="center" />
      <el-table-column prop="operateTypeValue" label="操作类别" align="center" />
      <el-table-column prop="operateObj" label="操作对象" align="center" />
      <el-table-column prop="objectName" label="对象名称" align="center" />
      <el-table-column
        prop="operateContent"
        label="操作内容"
        align="center"
      />
      <el-table-column prop="operateResultValue" label="操作结果" align="center" />
      <el-table-column prop="creationTime" label="操作时间" align="center" />
    </el-table>
    <Pagination
      :limit="params.pageSize"
      :page="params.pageNum"
      :total="total"
      class="pagination"
      @pagination="handlePageChange"
    />
  </div>

</template>
<script>
import { exportLog, logList } from '../api'
import search from './components/search.vue'
export default {
  data() {
    return {
      params: {
        pageNum: 1,
        pageSize: 10,
      },
      total: 10,
      tableData: [],
      isQuery: false
    };
  },
  components: {
    search
  },
  computed: {},
  methods: {
    handlePageChange(pageData) {
      this.params.pageSize = pageData.size;
      this.params.pageNum = pageData.page;
      this.getTableData()
    },
    getTableData(option) {
      let params = {
        current: this.params.pageNum,
        size: this.params.pageSize,
        ...option
      }
      logList(params).then(res => {
        let list = res.records || []
        this.tableData = list
        this.total = res.total
      })
    },
    tableRowClassName({ row, rowIndex }) {
      return rowIndex % 2 === 0 ? '' : 'single-row'
    },
    exportLog() {
      let params = {
        current: this.params.pageNum,
        size: this.params.pageSize
      }
      exportLog(params).then(res => {})
    }
  },
  mounted() { this.getTableData() },
};
</script>
<style lang="scss" scoped>
.leakage-cable {
  .leakage-top {
    margin-bottom: 20px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
  }
  & ::v-deep .cell {
    color: #333333;
  }
  .page {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 20px 0;
    .pageNum {
      margin: 0 20px;
    }
  }
}
</style>
<style lang="scss">
.statistics-table {
  .single-row {
    background: #f1f6ff;
  }
  td {
    padding: 5px !important;
  }
}
</style>