<template>
  <el-dialog 
    title="查看详情" 
    v-model="visible"
    :close-on-click-modal="false" 
    draggable
    width="1000px">
    <div v-loading="loading" class="article-container" v-if="detailData">
      <!-- 报纸文章样式 -->
      <div class="article-header">
        <h1 class="article-title">班级总结</h1>
        <div class="article-meta">
          <div class="meta-left">
            <span class="meta-item">学年：{{ detailData.schoolYear || '-' }}</span>
            <span class="meta-item">学期：{{ formatSchoolTerm(detailData.schoolTerm) }}</span>
            <span class="meta-item">班号：{{ detailData.classNo || '-' }}</span>
          </div>
        </div>
      </div>
      
      <!-- 统计信息 -->
      <div class="summary-stats">
        <el-descriptions :column="4" border>
          <el-descriptions-item label="总人数">{{ detailData.totalCnt || 0 }}</el-descriptions-item>
          <el-descriptions-item label="男生人数">{{ detailData.boyCnt || 0 }}</el-descriptions-item>
          <el-descriptions-item label="女生人数">{{ detailData.girlCnt || 0 }}</el-descriptions-item>
          <el-descriptions-item label="状态">
            <span>{{ formatStatus(detailData.status) }}</span>
          </el-descriptions-item>
          <el-descriptions-item label="男(住宿)">{{ detailData.boyDormCnt || 0 }}</el-descriptions-item>
          <el-descriptions-item label="女(住宿)">{{ detailData.girlDormCnt || 0 }}</el-descriptions-item>
          <el-descriptions-item label="留校察看人数">{{ detailData.keepSchoolCnt || 0 }}</el-descriptions-item>
          <el-descriptions-item label="记过人数">{{ detailData.gigCnt || 0 }}</el-descriptions-item>
          <el-descriptions-item label="严重警告人数">{{ detailData.seriousWarningCnt || 0 }}</el-descriptions-item>
          <el-descriptions-item label="警告人数">{{ detailData.warningCnt || 0 }}</el-descriptions-item>
          <el-descriptions-item label="撤销处分人数">{{ detailData.revokeCnt || 0 }}</el-descriptions-item>
          <el-descriptions-item label="退学人数">{{ detailData.dropCnt || 0 }}</el-descriptions-item>
        </el-descriptions>
      </div>
      
      <!-- 总结报告 -->
      <div class="article-content">
        <h3 class="content-title">总结报告</h3>
        <div v-html="detailData.summary || '-'"></div>
      </div>
    </div>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="visible = false">关 闭</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup lang="ts" name="ClassSummaryDetailDialog">
import { ref, onMounted } from 'vue'
import { getDetail } from '/@/api/stuwork/classsummary'
import { getDicts } from '/@/api/admin/dict'

// 定义变量内容
const visible = ref(false)
const loading = ref(false)
const detailData = ref<any>(null)
const schoolTermList = ref<any[]>([])
const statusList = ref<any[]>([])

// 格式化学期
const formatSchoolTerm = (value: string | number) => {
  if (value === null || value === undefined || value === '') {
    return '-'
  }
  const dictItem = schoolTermList.value.find(item => item.value == value)
  return dictItem ? dictItem.label : value
}

// 格式化状态
const formatStatus = (value: string) => {
  if (!value) return '-'
  const item = statusList.value.find((item: any) => item.value === value)
  return item ? item.label : value
}

// 打开弹窗
const openDialog = async (id: string) => {
  visible.value = true
  detailData.value = null
  loading.value = true
  try {
    const res = await getDetail(id)
    if (res.data) {
      detailData.value = res.data
    }
  } catch (err) {
  } finally {
    loading.value = false
  }
}

// 获取学期字典
const getSchoolTermDict = async () => {
  try {
    const res = await getDicts('school_term')
    if (res.data && Array.isArray(res.data)) {
      schoolTermList.value = res.data.map((item: any) => ({
        label: item.label || item.dictLabel || item.name,
        value: item.value || item.dictValue || item.code
      }))
    }
  } catch (err) {
  }
}

// 获取状态字典
const getStatusDict = async () => {
  try {
    const res = await getDicts('status_type')
    if (res.data && Array.isArray(res.data)) {
      statusList.value = res.data.map((item: any) => ({
        label: item.label || item.dictLabel || item.name,
        value: item.value || item.dictValue || item.code
      }))
    }
  } catch (err) {
  }
}

// 初始化
onMounted(() => {
  getSchoolTermDict()
  getStatusDict()
})

// 暴露方法
defineExpose({
  openDialog
})
</script>

<style scoped>
.article-container {
  padding: 20px;
  max-width: 100%;
}

.article-header {
  border-bottom: 2px solid #e4e7ed;
  padding-bottom: 20px;
  margin-bottom: 30px;
}

.article-title {
  font-size: 28px;
  font-weight: bold;
  color: #303133;
  margin: 0 0 15px 0;
  line-height: 1.5;
  text-align: center;
}

.article-meta {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  font-size: 14px;
  color: #909399;
  padding-top: 10px;
  flex-wrap: wrap;
  gap: 10px;
}

.meta-left {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.meta-item {
  font-weight: 500;
}

.summary-stats {
  margin-bottom: 30px;
}

.content-title {
  font-size: 18px;
  font-weight: bold;
  color: #303133;
  margin: 0 0 15px 0;
}

.article-content {
  font-size: 16px;
  line-height: 1.8;
  color: #606266;
  text-align: justify;
  word-wrap: break-word;
  min-height: 200px;
}

.article-content :deep(p) {
  margin: 0 0 15px 0;
}

.article-content :deep(img) {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 20px auto;
}

.article-content :deep(h1),
.article-content :deep(h2),
.article-content :deep(h3),
.article-content :deep(h4),
.article-content :deep(h5),
.article-content :deep(h6) {
  margin: 20px 0 15px 0;
  font-weight: bold;
}

.article-content :deep(ul),
.article-content :deep(ol) {
  margin: 15px 0;
  padding-left: 30px;
}

.article-content :deep(blockquote) {
  border-left: 4px solid #409eff;
  padding-left: 15px;
  margin: 15px 0;
  color: #909399;
  font-style: italic;
}
</style>

