<template>
  <div class="view-systemLog">
    <div class="common-box">
      <div class="common-box-button">
        <!-- <el-button type="primary" style="margin-bottom: 10px" @click="clearLog">清空日志</el-button> -->
      </div>
      <div class="common-box-search">
        <el-input placeholder="请输入系统模块/操作用户" v-model="keyword" class="input-with-select" @keyup.enter.native="fetchTableData">
          <el-button size="mini" slot="append" icon="el-icon-search" @click="fetchTableData(1)"></el-button>
        </el-input>
      </div>
    </div>
    <LTable ref="table" :defaultFetch="false" :columns="columns" :dataSource="tableData" :options="options" :fetch="fetchTableData" :pagination="pagination" />
  </div>
</template>

<script>
import { options, columns } from './index'
import { operlogList } from '@/api/system/systemLog'
export default {
  name: 'systemLog',
  components: {},
  data() {
    // 这里存放数据
    return {
      columns: columns(this),
      options,
      tableData: [],
      // 分页
      pagination: {
        total: 0,
        pageIndex: 1,
        pageSize: 10
      },
      keyword: ''
    }
  },
  mounted() {
    this.fetchTableData()
  },
  methods: {
    clearLog() {
      this.$confirm('是否确认清空日志', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.tableData = []
          this.$message({
            type: 'success',
            message: '操作成功!'
          })
        })
        .catch(() => {})
    },

    async fetchTableData(pageIndex) {
      let postData = {
        keyword: this.keyword,
        pageIndex: pageIndex ? pageIndex : this.pagination.pageIndex,
        pageSize: this.pagination.pageSize
      }
      const { code, data } = await operlogList(postData)
      if (code == 200) {
        this.tableData = data.list
        this.pagination.total = data.totalCount
      }
    }
  }
}
</script>

<style lang="scss">
@import './index.scss';
</style>
