<template>
  <div class="form-wrap">
    <el-form
      class="searchBox"
      ref="form"
      :model="form"
      :inline="true"
      label-width="70px">
      <div class="block-title">
        查询条件
      </div>
      <el-form-item
        label="昵称"
        prop="keyWords1">
        <el-input v-model="form.keyWords1"></el-input>
      </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="startDate"
      >
        <el-date-picker
          v-model="form.startDate"
          type="datetime"
          placeholder="选择日期时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item
        label="截止时间"
        prop="endDate"
      >
        <el-date-picker
          default-time="23:59:59"
          v-model="form.endDate"
          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="tableBox">
      <div class="block-title">
        统计信息
      </div>
      <el-table
        border
        stripe
        v-loading="loading"
        :data="tableData">
        <el-table-column
          prop="manager_name"
          label="操作人"
        >
        </el-table-column>

        <el-table-column
          prop="manager_nick_name"
          label="操作人昵称"
        >
        </el-table-column>

        <el-table-column
          prop="phone"
          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="create_time"
          label="操作时间"
        >
          <template slot-scope="scope">
            {{ scope.row.create_time | formatTime }}
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        :current-page.sync="form.pageNum"
        @current-change="getList()"
        layout="total, prev, pager, next"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { getLoginLog } from '@/api/systemSetting/webLog.js'

export default {
  data () {
    return {
      form: {
        startDate: '',
        endDate: '',
        keyWords1: '',
        keyWords2: '',
        keyWords3: '',
        pageNum: 1,
        pageSize: 10
      },
      accountList: [],
      tableData: [],
      total: 0,
      loading: false
    }
  },
  async created () {
    this.getList()
  },
  methods: {
    reset () {
      this.$refs.form.resetFields()
    },
    getList (goFirst) {
      this.loading = true
      goFirst && (this.form.pageNum = 1)
      getLoginLog(this.form).then(res => {
        this.total = res.total
        this.tableData = res.list
      }).finally(() => {
        this.loading = false
      })
    }
  }
}
</script>

<style scoped>

</style>
