<template>
  <div class="user-history-container">
    <el-table
      v-loading="listLoading"
      border
      :data="list"
      :height="tableConfig.height"
    >
      <el-table-column
        align="center"
        :label="__('房间编号')"
        prop="uh_id"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('直播名称')"
        prop="uh_name"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('直播封面')"
        prop="uh_poster"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <el-image
            v-show="scope.row.uh_poster"
            :preview-src-list="[scope.row.uh_poster]"
            :src="scope.row.uh_poster"
            style="width: 35px; height: 35px"
          />
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="__('用户编号')"
        prop="user_id"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('直播编号')"
        prop="room_id"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('禁止状态')"
        prop="uh_enable"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('直播时间')"
        prop="uh_stime"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('结束时间')"
        prop="uh_etime"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('直播视频')"
        prop="uh_video"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="__('关联商品')"
        prop="item_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/history'

  export default {
    name: 'History',

    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,
          title: '',
        },
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      __,

      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>
