<template>
  <Dialog v-model="dialogVisible" title="供应商评价详情" width="100%" fullscreen class="mobile-eval-detail-dialog">
    <div v-loading="loading" class="mobile-detail-wrapper">
      <!-- 基本信息 -->
      <div class="mobile-detail-section">
        <div class="mobile-detail-section__title">基本信息</div>
        <div class="mobile-detail-row">
          <span class="mobile-detail-label">供应商</span>
          <span class="mobile-detail-value">{{ evaluationData.supplierName }}</span>
        </div>
        <div class="mobile-detail-row">
          <span class="mobile-detail-label">采购订单号</span>
          <span class="mobile-detail-value">{{ evaluationData.orderNo }}</span>
        </div>
        <div class="mobile-detail-row">
          <span class="mobile-detail-label">评价时间</span>
          <span class="mobile-detail-value">{{ formatDate(evaluationData.createTime) }}</span>
        </div>
        <div class="mobile-detail-row">
          <span class="mobile-detail-label">评价人</span>
          <span class="mobile-detail-value">{{ evaluationData.creatorName }}</span>
        </div>
      </div>

      <!-- 评分详情 -->
      <div class="mobile-detail-section">
        <div class="mobile-detail-section__title">评分详情</div>
        <div class="mobile-score-item">
          <div class="mobile-score-item__header">
            <span class="mobile-score-item__name">质量评分</span>
            <el-tag :type="getScoreTagType(evaluationData.qualityScore)" size="small">
              {{ evaluationData.qualityScore }}分 · {{ getScoreLevel(evaluationData.qualityScore) }}
            </el-tag>
          </div>
          <div class="mobile-score-item__desc">产品质量、规格符合度、缺陷率等</div>
        </div>
        <div class="mobile-score-item">
          <div class="mobile-score-item__header">
            <span class="mobile-score-item__name">服务评分</span>
            <el-tag :type="getScoreTagType(evaluationData.serviceScore)" size="small">
              {{ evaluationData.serviceScore }}分 · {{ getScoreLevel(evaluationData.serviceScore) }}
            </el-tag>
          </div>
          <div class="mobile-score-item__desc">售前售后服务、响应速度、专业程度等</div>
        </div>
        <div class="mobile-score-item">
          <div class="mobile-score-item__header">
            <span class="mobile-score-item__name">价格评分</span>
            <el-tag :type="getScoreTagType(evaluationData.priceScore)" size="small">
              {{ evaluationData.priceScore }}分 · {{ getScoreLevel(evaluationData.priceScore) }}
            </el-tag>
          </div>
          <div class="mobile-score-item__desc">价格合理性、性价比、优惠政策等</div>
        </div>
        <div class="mobile-score-item">
          <div class="mobile-score-item__header">
            <span class="mobile-score-item__name">交付评分</span>
            <el-tag :type="getScoreTagType(evaluationData.deliveryScore)" size="small">
              {{ evaluationData.deliveryScore }}分 · {{ getScoreLevel(evaluationData.deliveryScore) }}
            </el-tag>
          </div>
          <div class="mobile-score-item__desc">交付及时性、包装质量、物流配送等</div>
        </div>
      </div>

      <!-- 综合评分 -->
      <div class="mobile-detail-section">
        <div class="mobile-detail-section__title">综合评分</div>
        <div class="mobile-total-score">
          <el-progress
            type="circle"
            :percentage="(evaluationData.totalScore / 10) * 100"
            :color="getProgressColor(evaluationData.totalScore)"
            :width="90"
          >
            <template #default>
              <span class="mobile-total-score__value">{{ evaluationData.totalScore }}</span>
              <span class="mobile-total-score__label">/ 10分</span>
            </template>
          </el-progress>
          <div class="mobile-total-score__info">
            <div class="mobile-total-score__big">{{ evaluationData.totalScore }}分</div>
            <el-tag :type="getScoreTagType(evaluationData.totalScore)" size="large">
              {{ getScoreLevel(evaluationData.totalScore) }}
            </el-tag>
          </div>
        </div>
      </div>

      <!-- 评价备注 -->
      <div v-if="evaluationData.remark" class="mobile-detail-section">
        <div class="mobile-detail-section__title">评价备注</div>
        <div class="mobile-remark">{{ evaluationData.remark }}</div>
      </div>
    </div>

    <template #footer>
      <el-button @click="dialogVisible = false" style="width:100%">关闭</el-button>
    </template>
  </Dialog>
</template>

<script setup lang="ts">
import { SupplierEvaluationVO } from '@/api/erp/purchase/supplierEvaluation'
import { formatDate } from '@/utils/formatTime'

const dialogVisible = ref(false)
const loading = ref(false)
const evaluationData = ref<SupplierEvaluationVO>({} as SupplierEvaluationVO)

// 打开详情弹窗
const open = (data: SupplierEvaluationVO) => {
  dialogVisible.value = true
  evaluationData.value = { ...data }
}

// 获取评分标签类型
const getScoreTagType = (score: number) => {
  if (score >= 9) return 'success'
  if (score >= 8) return ''
  if (score >= 7) return 'warning'
  if (score >= 6) return 'info'
  return 'danger'
}

// 获取评分等级
const getScoreLevel = (score: number) => {
  if (score >= 9) return '优秀'
  if (score >= 8) return '良好'
  if (score >= 7) return '一般'
  if (score >= 6) return '及格'
  return '不及格'
}

// 获取进度条颜色
const getProgressColor = (score: number) => {
  if (score >= 9) return '#67c23a'
  if (score >= 8) return '#409eff'
  if (score >= 7) return '#e6a23c'
  if (score >= 6) return '#909399'
  return '#f56c6c'
}

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

<style lang="scss" scoped>
.mobile-detail-wrapper {
  padding: 0 4px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.mobile-detail-section {
  background: #fff;
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  &__title {
    font-size: 15px;
    font-weight: 600;
    color: #303133;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #f0f0f0;
  }
}
.mobile-detail-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
}
.mobile-detail-label {
  color: #909399;
  flex-shrink: 0;
  margin-right: 12px;
}
.mobile-detail-value {
  color: #303133;
  text-align: right;
}
.mobile-score-item {
  padding: 10px 0;
  border-bottom: 1px solid #f5f5f5;
  &:last-child { border-bottom: none; }
  &__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
  }
  &__name {
    font-weight: 500;
    color: #303133;
    font-size: 14px;
  }
  &__desc {
    font-size: 12px;
    color: #909399;
  }
}
.mobile-total-score {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 0;
  justify-content: center;
  &__value {
    font-size: 20px;
    font-weight: bold;
    color: #409eff;
  }
  &__label {
    font-size: 12px;
    color: #909399;
    display: block;
    margin-top: -4px;
  }
  &__info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
  }
  &__big {
    font-size: 28px;
    font-weight: bold;
    color: #409eff;
  }
}
.mobile-remark {
  padding: 12px;
  background-color: #fafafa;
  border-radius: 6px;
  border-left: 4px solid #409eff;
  line-height: 1.6;
  color: #606266;
  font-size: 13px;
}
:deep(.mobile-eval-detail-dialog .el-dialog__body) {
  padding: 12px;
  background: #f5f5f5;
}
:deep(.el-progress-circle__text) {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
</style>
