<template>
  <div class="part-box is-filter">
    <el-form inline>
      <el-form-item label="登录名">
        <el-input
          v-model.trim="searchModel.loginName"
          placeholder="请输入"
          clearable
          style="width: 120px"
        >
        </el-input>
      </el-form-item>
      <el-form-item label="用户类型">
        <el-select
          v-model="searchModel.userType"
          placeholder="请选择"
          clearable
          style="width: 120px"
        >
          <el-option label="请选择" value="" />
          <el-option label="管理员" value="管理员" />
          <el-option label="普通用户" value="普通用户" />
        </el-select>
      </el-form-item>
      <el-form-item label="操作类型">
        <el-select
          v-model="searchModel.operationType"
          placeholder="请选择"
          clearable
          style="width: 120px"
        >
          <el-option
            v-for="(val, key) in LOG_TYPE"
            :key="key"
            :label="val"
            :value="key"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="toPage(1)">查询</el-button>
        <el-button @click="exportData">导出</el-button>
      </el-form-item>
    </el-form>
  </div>
  <div class="part-box">
    <el-table class="page-table" :data="dataList" :loading="loading">
      <el-table-column type="index" label="序号" width="60" />
      <el-table-column property="loginName" label="登录名" min-width="120" />
      <el-table-column property="userType" label="用户类型" width="100" />
      <el-table-column property="operationType" label="操作类型" width="100" />
      <el-table-column property="loginIp" label="登录IP" width="140" />
      <el-table-column property="function" label="功能模块" min-width="200" />
      <el-table-column property="operationTime" label="操作时间" width="180" />
      <el-table-column property="detail" label="详情" width="180" />
    </el-table>
    <el-pagination
      v-model:current-page="pagination.pageNumber"
      v-model:page-size="pagination.pageSize"
      :layout="pagination.layout"
      :total="pagination.total"
      @size-change="pageSizeChange"
      @current-change="toPage"
    />
  </div>
</template>

<script setup lang="ts">
  import { reactive } from 'vue';
  import { getLogList } from '@/api/log';
  import { LogItem, LogListFilter } from '@/api/types/log';
  import useTable from '@/hooks/table';
  import { LOG_TYPE } from '@/constants/enumerate';

  defineOptions({
    name: 'LogManage',
  });

  const searchModel = reactive<LogListFilter>({
    loginName: '',
    userType: '',
    operationType: undefined,
  });

  const { dataList, pagination, loading, toPage, pageSizeChange } =
    useTable<LogItem>(getLogList, searchModel, false);

  function exportData() {
    // TODO: 实现导出功能
  }
</script>
