<template>
  <div class="app-container live-page">
        <div class="live-page__header">
      <h2 class="live-page__title">反馈日志</h2>
    </div>

<div class="live-panel" v-show="showSearch">
<el-form class="live-search-form" :model="queryParams" ref="queryForm" :inline="true">
      <el-form-item label="主播名称" prop="streamerName">
        <el-input
          v-model="queryParams.streamerName"
          placeholder="请输入主播名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="反馈类型" prop="typeId">
        <el-select v-model="queryParams.typeId" placeholder="请选择反馈类型" clearable size="small">
          <el-option
            v-for="item in typeOptions"
            :key="item.id"
            :label="item.typeName"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    </div>

    <div class="live-panel live-panel--table">
<el-table
      v-loading="loading"
      :data="logList"
      border
     class="live-table">
      <el-table-column label="ID" align="center" prop="id"/>
      <el-table-column label="主播ID" align="center" prop="streamerId"/>
      <el-table-column label="主播名称" align="center" prop="streamerName"/>
      <el-table-column label="反馈类型" align="center" prop="typeList" width="500">
        <template slot-scope="scope">
          <el-tag v-for="item in scope.row.typeList" :key="item">{{ item }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="反馈内容" align="center" prop="content" :show-overflow-tooltip="true"  width="500"/>
      <el-table-column label="反馈时间" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{ formatDateTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
    </el-table>
    </div>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listLiveFeedbackLog } from "@/api/live/liveFeedbackLog";
import { listLiveFeedbackType } from "@/api/live/liveFeedbackType";

export default {
  name: "LiveFeedbackLog",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 主播反馈日志表格数据
      logList: [],
      // 反馈类型选项
      typeOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示查看弹出层
      viewOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        streamerName: null,
        typeId: null
      },
    };
  },
  created() {
    this.getList();
    this.getTypeOptions();
  },
  methods: {
    /** 查询主播反馈日志列表 */
    getList() {
      this.loading = true;
      listLiveFeedbackLog(this.queryParams).then(response => {
        this.logList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 获取反馈类型选项
    getTypeOptions() {
      listLiveFeedbackType({}).then(response => {
        this.typeOptions = response.rows || [];
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 格式化日期时间
    formatDateTime(dateTime) {
      if (!dateTime) return '-';
      try {
        const date = new Date(dateTime);
        const year = date.getFullYear();
        const month = String(date.getMonth() + 1).padStart(2, '0');
        const day = String(date.getDate()).padStart(2, '0');
        const hours = String(date.getHours()).padStart(2, '0');
        const minutes = String(date.getMinutes()).padStart(2, '0');
        const seconds = String(date.getSeconds()).padStart(2, '0');
        return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
      } catch (e) {
        console.error('日期格式化错误:', e);
        return dateTime; // 如果解析失败，返回原始值
      }
    },
  }
};
</script>

<style scoped>

</style>
