<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">
      <y-table
        :max-height="650"
        :data="tableData"
        :column="columns"
        border
        :loading="loading"
        ref="multipleTable"
      >
        <template slot="operType" 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>
      </y-table>
    </div>
    <y-pagination
      :total="total"
      :page.sync="page"
      :pageSize.sync="size"
      @change="getlogsList"
    ></y-pagination>
  </div>
</template>

<script>
import TableHeader from "@/components/TableHeader.vue";
import { getlogsList } from "@/api/system";
export default {
  components: {
    TableHeader,
  },
  data() {
    return {
      searchVal: "",
      tableData: [],
      page: 1,
      size: 10,
      total: 10,
      loading: false,
      selectKeys: [],
      dict: {}, // 字典
      columns: [
        {
          label: "全选",
          type: "selection",
          width: "55",
          align: "center",
          reserveSelection: true,
        },
        {
          label: "序号",
          type: "index",
          width: "55",
          align: "center",
          index: (index) => {
            return (this.page - 1) * this.size + index + 1;
          },
        },
        {
          label: "用户名称",
          prop: "userName",
          align: "center",
        },
        {
          label: "登录名称",
          prop: "loginName",
          align: "center",
        },
        {
          label: "请求地址",
          prop: "requestUrl",
          align: "center",
        },
        {
          label: "操作内容",
          slot: true,
          prop: "content",
          align: "center",
        },
        {
          label: "操作IP地址",
          prop: "ip",
          align: "center",
        },
        {
          label: "操作类型",
          slot: true,
          prop: "operType",
          align: "center",
        },

        {
          label: "操作时间",
          prop: "logDate",
          align: "center",
        },
      ],
    };
  },
  created() {
    this.getlogsList();
  },
  computed: {},
  methods: {
    // 系统事项列表
    async getlogsList() {
      this.loading = true;
      let res = await getlogsList({
        page: this.page,
        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.page > 1) {
          this.page -= 1;
          this.getlogsList();
        }
        this.tableData = data;
        this.total = total;
      }
      this.loading = false;
    },

    // 搜索
    handleSearch() {
      this.page = 1;
      this.$refs.multipleTable.clearSelection();
      this.getlogsList();
    },
    // 重置
    handleReset() {
      this.searchVal = "";
      this.page = 1;
      this.$refs.multipleTable.clearSelection();
      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>
