<template>
  <el-dialog
    v-model="dialogVisible"
    title="查看反馈"
    width="800px"
    :before-close="handleClose"
  >
    <div class="feedback-container" v-loading="loading">
      <!-- 反馈列表 -->
      <div class="feedback-list" v-if="currFkListList.length > 0">
        <div
          v-for="(feedback, index) in currFkListList"
          :key="index"
          class="feedback-item"
        >
          <div class="feedback-header">
            <div class="user-info">
              <el-avatar :size="32" :src="feedback.avatar">
                {{ feedback.fkrxm?.charAt(0) || '用' }}
              </el-avatar>
              <span class="username">{{ feedback.fkrxm || '匿名用户' }}</span>
            </div>
            <div class="feedback-time" v-if="feedback.fksj">
              {{ formatTime(feedback.fksj) }}
            </div>
          </div>
          <div class="feedback-content">
            {{ feedback.fknr }}
          </div>
        </div>
      </div>

      <!-- 暂无反馈 -->
      <el-empty
        v-else
        description="暂无反馈信息"
        :image-size="120"
      />
    </div>

    <template #footer>
      <div class="dialog-footer">
        <el-button @click="handleClose">关闭</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { ref, computed } from 'vue'

const dialogVisible = ref(false)
const loading = ref(false)
const currFkListList = ref([])

// // 计算所有反馈列表
// const currFkListList = computed(() => {
//   let allFeedbacks = []

//   if (currFkListList.value && Array.isArray(currFkListList.value)) {
//     currFkListList.value.forEach(item => {
//       if (item.fkList && Array.isArray(item.fkList)) {
//         item.fkList.forEach(feedback => {
//           allFeedbacks.push({
//             ...feedback,
//             // 如果有评论内容，也一并显示
//             plnr: item.plnr
//           })
//         })
//       }
//     })
//   }

//   // 按时间排序（如果有时间字段）
//   return allFeedbacks.sort((a, b) => {
//     if (a.fksj && b.fksj) {
//       return new Date(b.fksj) - new Date(a.fksj)
//     }
//     return 0
//   })
// })

// 打开弹框
const open = (fkList) => {
  currFkListList.value = fkList || []
  dialogVisible.value = true
}

// 关闭弹框
const handleClose = () => {
  dialogVisible.value = false
  currFkListList.value = []
}

// 格式化时间
const formatTime = (timeStr) => {
  if (!timeStr) return ''
  try {
    const date = new Date(timeStr)
    return date.toLocaleString('zh-CN', {
      year: 'numeric',
      month: '2-digit',
      day: '2-digit',
      hour: '2-digit',
      minute: '2-digit'
    })
  } catch (error) {
    return timeStr
  }
}

defineExpose({
  open
})
</script>

<style scoped>
.feedback-container {
  max-height: 500px;
  overflow-y: auto;
}

.feedback-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.feedback-item {
  border: 1px solid #e4e7ed;
  border-radius: 8px;
  padding: 16px;
  background-color: #fafafa;
  transition: all 0.3s ease;
}

.feedback-item:hover {
  border-color: #409eff;
  box-shadow: 0 2px 8px rgba(64, 158, 255, 0.1);
}

.feedback-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.username {
  font-weight: 500;
  color: #303133;
  font-size: 14px;
}

.feedback-time {
  font-size: 12px;
  color: #909399;
}

.feedback-content {
  color: #606266;
  line-height: 1.6;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
}

/* 滚动条样式 */
.feedback-container::-webkit-scrollbar {
  width: 6px;
}

.feedback-container::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

.feedback-container::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

.feedback-container::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}
</style>
