<template>
  <div class="system">
    <TableHeader>
      <div slot="right" class="flex">
        <el-input
          size="small"
          v-model="searchVal"
          style="width: 200px"
          class="ml10 mr10"
          placeholder="请输入请求地址搜索"
          @keyup.native.enter="handleSearch"
        ></el-input>
        <el-button size="small" type="primary" @click="handleSearch"
          >搜 索</el-button
        >
        <el-button size="small" @click="handleReset">重 置</el-button>
      </div>
    </TableHeader>
    <!-- 表格 -->
    <div class="table-content">
      <el-table
        ref="multipleTable"
        size="small"
        v-loading="loading"
        :data="tableData"
        border
        tooltip-effect="dark"
        style="width: 100%"
        :row-key="(row) => row.id"
      >
        <el-table-column
          type="index"
          label="序号"
          width="55"
          align="center"
          :index="(index) => (current - 1) * size + index + 1"
        >
        </el-table-column>
        <el-table-column label="用户名称" align="center" prop="userName">
        </el-table-column>
        <el-table-column label="登录名称" align="center" prop="loginName">
        </el-table-column>
        <el-table-column label="请求地址" align="center" prop="requestUrl">
        </el-table-column>
        <el-table-column label="操作内容" align="center" prop="content">
        </el-table-column>
        <el-table-column label="操作IP地址" align="center" prop="ip">
        </el-table-column>
        <el-table-column label="操作类型" align="center" prop="operType">
          <template slot-scope="scope">
            <span v-if="scope.row.operType == 0">新增</span>
            <span v-else-if="scope.row.operType == 1">修改</span>
            <span v-else-if="scope.row.operType == 2">删除</span>
          </template>
        </el-table-column>
        <el-table-column label="操作时间" align="center" prop="logDate">
        </el-table-column>
      </el-table>
    </div>
    <Pagination
      :total="total"
      :current="current"
      :size="size"
      @currentChange="changePagination"
      @sizeChange="changeSize"
    ></Pagination>
  </div>
</template>

<script>
import TableHeader from "@/components/TableHeader.vue";
import Pagination from "@/components/Pagination.vue";
import { getlogsList } from "@/api/system";
export default {
  components: {
    TableHeader,
    Pagination,
  },
  data() {
    return {
      searchVal: "",
      tableData: [],
      current: 1,
      size: 10,
      total: 10,
      loading: false,
      selectKeys: [],
      dict: {}, // 字典
    };
  },
  created() {
    this.getlogsList();
  },
  computed: {},
  methods: {
    // 系统事项列表
    async getlogsList() {
      this.loading = true;
      let res = await getlogsList({
        page: this.current,
        size: this.size,
        requestUrl: `%${this.searchVal}%`,
      });
      if (res.data.code == 1) {
        let { data, total, dict } = res.data.data;
        this.dict = dict;
        if (!data.length && this.current > 1) {
          this.current -= 1;
          this.getlogsList();
        }
        this.tableData = data;
        this.total = total;
        this.$refs.multipleTable.bodyWrapper.scrollTop = 0;
      }
      this.loading = false;
    },

    // 搜索
    handleSearch() {
      this.current = 1;
      this.$refs.multipleTable.clearSelection();
      this.getlogsList();
    },
    // 重置
    handleReset() {
      this.searchVal = "";
      this.current = 1;
      this.$refs.multipleTable.clearSelection();
      this.getlogsList();
    },

    // 翻页
    changePagination(cur) {
      this.current = cur;
      this.getlogsList();
    },
    // 改变没有显示数量
    changeSize(size) {
      this.size = size;
      this.getlogsList();
    },
  },
};
</script>

<style lang="less" scoped>
.system {
  width: 100%;
  min-height: 100%;
  .short {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .full-name {
    color: rgb(172, 170, 170);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  :deep(.el-card) {
    height: auto;
  }
  // .table-content {
  //   height: 550px;
  // }
}
</style>
