<template>
  <div class="page_info">
    <div class="search_pannel">
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
        @submit.native.prevent
      >
        <el-form-item label="用户名">
          <el-input
            v-model="dataForm.creatorName"
            :placeholder="$t('logLogin.creatorName')"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="状态">
          <el-select
            v-model="dataForm.status"
            :placeholder="$t('logLogin.status')"
            clearable
          >
            <el-option :label="$t('logLogin.status0')" :value="0"></el-option>
            <el-option :label="$t('logLogin.status1')" :value="1"></el-option>
            <el-option :label="$t('logLogin.status2')" :value="2"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div class="search_btn">
        <el-button type="primary" @click="getDataList()">{{
          $t("query")
        }}</el-button>
        <el-button plain @click="clear()">重置</el-button>
      </div>
    </div>
    <div class="card_info">
      <div class="info_list">
        <el-table
          v-loading="dataListLoading"
          :data="dataList"
          stripe
          :header-cell-style="{ background: '#e6e7ea', color: '#0C1935' }"
          @sort-change="dataListSortChangeHandle"
          style="width: 100%"
          :height="screenHeight"
        >
          <el-table-column
            prop="creatorName"
            label="用户名"
            header-align="center"
            align="center"
            width="100"
          ></el-table-column>
          <el-table-column
            prop="operation"
            label="操作类型"
            header-align="center"
            align="center"
            width="120"
          >
            <template slot-scope="scope">
              {{
                scope.row.operation === 0
                  ? $t("logLogin.operation0")
                  : $t("logLogin.operation1")
              }}
            </template>
          </el-table-column>
          <el-table-column
            prop="status"
            label="状态"
            header-align="center"
            align="center"
            width="80"
          >
            <template slot-scope="scope">
              <el-tag
                v-if="scope.row.status === 0"
                size="small"
                type="danger"
                >{{ $t("logLogin.status0") }}</el-tag
              >
              <el-tag
                v-else-if="scope.row.status === 1"
                size="small"
                type="success"
                >{{ $t("logLogin.status1") }}</el-tag
              >
              <el-tag v-else size="small" type="warning">{{
                $t("logLogin.status2")
              }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            prop="userAgent"
            label="User-Agent'"
            header-align="center"
            align="center"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column
            prop="ip"
            label="IP地址"
            header-align="center"
            align="center"
            width="130"
          ></el-table-column>
          <el-table-column
            prop="createDate"
            label="创建时间"
            header-align="center"
            align="center"
            width="150"
          ></el-table-column>
        </el-table>
      </div>
      <template v-if="total > 0">
        <el-pagination
          :current-page="page"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="limit"
          :total="total"
          background
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="pageSizeChangeHandle"
          @current-change="pageCurrentChangeHandle"
        >
        </el-pagination>
      </template>
    </div>
  </div>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      screenHeight: "564px",
      mixinViewModuleOptions: {
        getDataListURL: "/sys/log/login/page",
        getDataListIsPage: true,
        exportURL: "/sys/log/login/export",
      },
      dataForm: {
        creatorName: "",
        status: "",
      },
    };
  },
  mounted() {
    this.setTableHeight();
    // 页面创建完成后添加监听
    window.addEventListener("resize", this.setTableHeight);
  },
  methods: {
    setTableHeight() {
      setTimeout(() => {
        const fontSize = getComputedStyle(window.document.documentElement)[
          "font-size"
        ].replace("px", "");
        this.screenHeight =
          getComputedStyle(document.querySelector(".info_list")).height.replace(
            "px",
            ""
          ) -
          0.25 * fontSize +
          "px";
      }, 1000);
    },
    clear() {
      this.dataForm.creatorName = "";
      this.dataForm.status = "";
    },
  },
  destroyed() {
    window.removeEventListener("resize", this.setTableHeight);
  },
};
</script>
<style lang="scss" scoped>
.info_list {
  padding: 0.25rem 0 0 0 !important;
  height: calc(100% - 0.85rem) !important;
}
</style>
