<template>
  <div class="user-level-log-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_id"
              clearable
              :placeholder="__('请输入用户编号')"
            />
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="primary" @click="fetchData">
              {{ __('查询') }}
            </el-button>
            <el-button icon="el-icon-refresh" type="primary" @click="fetchData">
              {{ __('刷新') }}
            </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="user_level_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_level_id"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('上个等级')"
        prop="user_level_pre_id"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :formatter="formatTime"
        :label="__('操作时间')"
        prop="ull_time"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('操作备注')"
        prop="ull_note"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('操作人')"
        prop="admin_id"
        show-overflow-tooltip
      />
    </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/user/level/log'
  import { renderTime } from '@/utils/date'

  export default {
    name: 'UserLevelLog',
    components: {},
    data() {
      return {
        tableConfig: {
          height: window.innerHeight - 220 - 90,
        },
        list: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        selectRows: '',
        queryForm: {
          pageNum: 1,
          pageSize: 20,
          user_id: '',
        },
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      __,
      formatTime(row) {
        const ull_time = row.ull_time
        return ull_time ? renderTime(ull_time) : ''
      },

      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNum = val
        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>
