<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="apiName">
        <el-input v-model="form.apiName"></el-input>
      </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="apiName"
          label="操作名称"
        >
        </el-table-column>

        <el-table-column
          prop="time"
          label="耗时（ms）"
        >
        </el-table-column>

        <!-- <el-table-column
          prop="name"
          label="字段名称"
        >
        </el-table-column>

        <el-table-column
          min-width="100"
          prop="old_value"
          label="原值"
        >
        </el-table-column>
        <el-table-column
          prop="new_value"
          label="新值"
        >
        </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 { getWebLog } from '@/api/systemSetting/webLog'
import { getAccountList } from '@/api/systemSetting/account'
import moment from 'moment'

export default {
  data () {
    return {
      ticketTypeList: [],
      form: {
        createTimeStart: new Date(moment().startOf('day').subtract(7, 'day').format('YYYY-MM-DD HH:mm:ss')),
        createTimeEnd: new Date(moment().endOf('day').format('YYYY-MM-DD HH:mm:ss')),
        adminId: '',
        apiName: '',
        pageNum: 1,
        pageSize: 10
      },
      accountList: [],
      tableData: [],
      total: 0,
      loading: false
    }
  },
  async 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
      if (this.form.createTimeStart) {
        this.form.createTimeStart = moment(this.form.createTimeStart).format('YYYY-MM-DD HH:mm:ss')
      }
      if (this.form.createTimeEnd) {
        this.form.createTimeEnd = moment(this.form.createTimeEnd).format('YYYY-MM-DD HH:mm:ss')
      }
      goFirst && (this.form.pageNum = 1)
      getWebLog(this.form).then(res => {
        this.total = res.data.total
        this.tableData = res.data.records
      }).finally(() => {
        this.loading = false
      })
    }
  }
}
</script>

<style scoped>

</style>
