<template>
  <div class="form-wrap">
    <el-form
      class="search-box"
      ref="form"
      :model="form"
      :inline="true"
    >
      <div class="block-title">
        查询条件
      </div>
      <el-form-item
        label="登录人"
        prop="adminId">
        <el-select v-model="form.adminId">
          <el-option
            label="全部"
            value=""></el-option>
          <el-option
            v-for="item in accountList"
            :key="item.id"
            :label="item.loginName"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item
        label="手机号"
        prop="keyWords2">
        <el-input v-model="form.keyWords2"></el-input>
      </el-form-item>
      <el-form-item
        label="类型"
        prop="keyWords3"
      >
        <el-select
          v-model="form.keyWords3"
          placeholder="请选择">
          <el-option
            value=""
            label="全部">
          </el-option>
          <el-option
            :value="0"
            label="登录">
          </el-option>
          <el-option
            :value="1"
            label="登出">
          </el-option>
        </el-select>
      </el-form-item> -->

      <el-form-item
        label="起始时间"
        prop="createTimeStart"
      >
        <el-date-picker
          v-model="form.createTimeStart"
          type="datetime"
          placeholder="选择日期时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item
        label="截止时间"
        prop="createTimeEnd"
      >
        <el-date-picker
          default-time="23:59:59"
          v-model="form.createTimeEnd"
          type="datetime"
          placeholder="选择日期时间"
        >
        </el-date-picker>
      </el-form-item>

      <div class="btn-wrap">
        <el-button
          @click="reset"
        >
          重置
        </el-button>
        <el-button
          :disabled="loading"
          type="primary"
          @click="getList(true)"
        >
          搜索
        </el-button>
      </div>
    </el-form>

    <div class="table-box">
      <!-- <div class="block-title">
        统计信息
      </div> -->
      <el-table
        border
        stripe
        v-loading="loading"
        :data="tableData">
        <el-table-column
          prop="adminName"
          label="操作人"
        >
        </el-table-column>

        <el-table-column
          prop="ip"
          label="IP地址"
        >
        </el-table-column>

        <!-- <el-table-column
          prop="type"
          label="类型"
        >
          <template slot-scope="scope">
            <el-tag :type="scope.row.type ===0?'success':'warning'">
              {{ scope.row.type ===0?'登录':'登出' }}
            </el-tag>
          </template>
        </el-table-column> -->
        <el-table-column
          prop="createTime"
          label="操作时间"
        >
          <template slot-scope="scope">
            {{ scope.row.createTime | formatTime }}
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        :current-page.sync="form.pageNum"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="form.pageSize"
        @size-change="handleSizeChange"
        @current-change="getList()"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { getLoginLog } from '@/api/systemSetting/webLog'
import { getAccountList } from '@/api/systemSetting/account'

export default {
  data () {
    return {
      form: {
        createTimeStart: '',
        createTimeEnd: '',
        adminId: '',
        keyWords2: '',
        keyWords3: '',
        pageNum: 1,
        pageSize: 10
      },
      accountList: [],
      tableData: [],
      total: 0,
      loading: false
    }
  },
  created () {
    this.getList()
    getAccountList({ pageSize: -1, pageNum: 1 }).then(res => {
      this.accountList = res.data.records || []
    })
  },
  methods: {
    reset () {
      this.$refs.form.resetFields()
    },
    handleSizeChange (size) {
      this.form.pageSize = size
      this.getList()
    },
    getList (goFirst) {
      this.loading = true
      goFirst && (this.form.pageNum = 1)
      getLoginLog(this.form).then(res => {
        this.total = res.data.total
        this.tableData = res.data.records
      }).finally(() => {
        this.loading = false
      })
    }
  }
}
</script>

<style scoped>

</style>
