<template>
  <div class="container">
    <!-- 查询配置 -->
    <div >
      <div ref="lxHeader">
        <LxHeader icon="md-apps" text="系统日志" style="margin-bottom: 10px; border: 0px; margin-top: 15px">
          <div slot="content"></div>
          <slot>
          </slot>
        </LxHeader>
      </div>

      <div class="table-tree">
        <el-table :data="tableData" class="v-table" :height="tableHeight" border style="width: 100%">
          <el-table-column type="index" align="center">
          </el-table-column>
          <el-table-column prop="name" label="内容">
          </el-table-column>
          <el-table-column prop="username" label="操作人"  align="center" width="180">
           <template slot-scope="scope">
             {{scope.row.admin?scope.row.admin.name:""}}
           </template>
          </el-table-column>
          <el-table-column prop="admin" label="操作人部门" align="center" width="180">
            <template slot-scope="scope">
              {{scope.row.department?scope.row.department.name:""}}
            </template>
          </el-table-column>
          <el-table-column prop="created_at" label="操作时间" align="center" width="180">
          </el-table-column>
          <el-table-column prop="ip" label="ip" width="180" align="center">
          </el-table-column>
        </el-table>

        <div class="pagination">
          <el-pagination @current-change="handleCurrentChange" :current-page="paginations.page"
            :page-size="paginations.page_size" background layout="prev, pager, next" :total="paginations.total">
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import LxHeader from "@/components/LxHeader/index.vue";
  import {
    listlog
  } from "../../api/system/log.js";

  export default {
    components: {
      LxHeader
    },
    created() {
      this.initLoad();
      var that = this;
      that.load();
    },
    mounted() {},
    data() {

      return {
        paginations: {
          page: 1,
          page_size: 15,
          total: 0
        },
        tableHeight: 0,
        //查询条件字段
        searchFields: {
          keyword: ""
        },
        tableData: []
      }
    },
    methods: {
      initLoad() {
        var that = this;
        var clientHeight = document.documentElement.clientHeight
        var lxHeader_height = 96.5; //查询 头部
        var paginationHeight = 37; //分页的高度
        var topHeight = 50; //页面 头部
        let tableHeight = clientHeight - lxHeader_height - topHeight - paginationHeight - 20;
        that.tableHeight = tableHeight;

      },
      handleCurrentChange(page) {
        this.paginations.page = page;
        this.load();
      },
      load() {
        var that = this;
        listlog({
          page: that.paginations.page,
          ...this.searchFields
        }).then(response => {
          var data = response.data;
          this.paginations.total = response.total;
          that.tableData = data;
        }).catch(error => {
          console.log(error)
          //reject(error)
        })
      }

    }
  };
</script>

<style>
</style>
