<template>
  <div class="log-action-container">
    <vab-query-form>
      <vab-query-form-right-panel :span="24">
        <el-form :inline="true" :model="queryForm" @submit.native.prevent>
          <el-form-item>
            <el-input
              v-model.trim="queryForm.user_account"
              clearable
              :placeholder="__('请输入用户账号')"
            />
          </el-form-item>
          <el-form-item>
            <el-input
              v-model.trim="queryForm.log_url"
              clearable
              :placeholder="__('请输入请求地址')"
            />
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="primary" @click="queryData">
              {{ __('查询') }}
            </el-button>
            <el-button icon="el-icon-refresh" type="primary" @click="queryData">
              {{ __('刷新') }}
            </el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-right-panel>
    </vab-query-form>

    <el-table
      v-loading="listLoading"
      border
      :data="list"
      :height="tableConfig.height"
    >
      <el-table-column
        align="center"
        :label="__('日志编号')"
        prop="log_id"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('玩家编号')"
        prop="user_id"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('角色账户')"
        prop="user_account"
        show-overflow-tooltip
        width="140"
      />
      <el-table-column
        align="center"
        :label="__('角色名称')"
        prop="user_name"
        show-overflow-tooltip
        width="140"
      />
      <!--      <el-table-column
              align="center"
              :label="__('行为id')"
              prop="action_id"
              show-overflow-tooltip
            />
            <el-table-column
              align="center"
              :label="__('操作类型编号')"
              prop="action_type_id"
              show-overflow-tooltip
            />-->
      <el-table-column
        align="center"
        :label="__('请求的地址')"
        prop="log_url"
        show-overflow-tooltip
        width="300"
      />
      <el-table-column
        align="center"
        :label="__('请求的参数')"
        prop="log_param"
        show-overflow-tooltip
        width="300"
      />
      <el-table-column
        align="center"
        :label="__('日志IP')"
        prop="log_ip"
        show-overflow-tooltip
        width="140"
      />
      <el-table-column
        v-if="false"
        align="center"
        :formatter="formatDate"
        :label="__('日志日期')"
        prop="log_date"
        show-overflow-tooltip
        width="140"
      />
      <el-table-column
        align="center"
        :formatter="formatTime"
        :label="__('记录时间')"
        prop="log_time"
        show-overflow-tooltip
        width="160"
      />
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.pageNum"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
  </div>
</template>

<script>
  import { translateTitle as __ } from '@/utils/i18n'
  import { getList } from '@/api/log/action'
  import { renderTime } from '@/utils/date'

  export default {
    name: 'Action',
    components: {},
    data() {
      return {
        tableConfig: {
          height: window.innerHeight - 220 - 90,
        },
        list: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        queryForm: {
          pageNum: 1,
          pageSize: 20,
          user_account: '',
          log_url: '',
        },
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      formatDate(row) {
        const log_date = row.log_date
        return log_date ? renderTime(log_date) : ''
      },
      formatTime(row) {
        const log_time = row.log_time
        return log_time ? renderTime(log_time) : ''
      },
      __,
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNum = val
        this.fetchData()
      },
      queryData() {
        this.queryForm.pageNum = 1
        this.fetchData()
      },
      async fetchData() {
        this.listLoading = true
        const { data } = await getList(this.queryForm)
        this.list = data.items
        this.total = data.records
        this.listLoading = false
      },
    },
  }
</script>
