<script setup lang="ts">
import type { ExperimentRecord } from '../types'
import { Document } from '@element-plus/icons-vue'

const detail = $ref<ExperimentRecord>(inject('detail'))

const score = $computed<number>(() => {
  const result =
    ((detail.score_details.operate || 0) + (detail.score_details.result || 0) + (detail.score_details.file || 0)) / 3
  return parseFloat(result.toFixed(2))
})
</script>

<template>
  <el-dialog title="实验成绩详情" width="600px" :close-on-click-modal="false">
    <el-form label-width="120px" label-suffix="：" v-if="detail">
      <el-form-item label="实验名称">{{ detail.experiment.name }}</el-form-item>
      <el-form-item label="实验课程名称">{{ detail.course.name }}</el-form-item>
      <el-row>
        <el-col :span="12">
          <el-form-item label="学生姓名">{{ detail.student.name }}</el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="学生学号">{{ detail.student.sno_number }}</el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="所属专业">{{ detail.student.specialty.name }}</el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="所属班级">{{ detail.student.specialty.name }}</el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="实验报告文件">
        <div v-if="detail.file">
          <a :href="detail.file.url" target="_blank" class="file-item">
            <el-icon><Document /></el-icon>{{ detail.file.name }}
          </a>
        </div>
      </el-form-item>
      <el-form-item label="实验成绩" class="form-item-score">
        <el-form ref="formRef" hide-required-asterisk inline label-position="top" style="padding: 5px 0 20px">
          <el-form-item label="实验操作">
            <el-input-number :controls="false" disabled v-model="detail.score_details.operate" />
          </el-form-item>
          <el-form-item label="实验结果">
            <el-input-number :controls="false" disabled v-model="detail.score_details.result" />
          </el-form-item>
          <el-form-item label="实验报告">
            <el-input-number :controls="false" disabled v-model="detail.score_details.file" />
          </el-form-item>
          <el-form-item label="综合实验成绩" style="width: 364px">
            <el-input-number :controls="false" disabled v-model="score" style="width: 100%" />
          </el-form-item>
        </el-form>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<style lang="scss" scoped>
.file-item {
  display: flex;
  align-items: center;
  color: var(--main-color);
  .el-icon {
    margin-right: 5px;
  }
}
.picture-list {
  width: 100%;
  li {
    display: flex;
    justify-content: space-between;
  }
  a {
    color: var(--main-color);
  }
  .t1 {
    flex: 1;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }
}
.form-item-score {
  :deep(.el-form-item__label) {
    text-align: center;
  }
  .el-input-number {
    width: 100px;
  }
}
</style>
