<template>
  <div>
    <el-dialog
      v-if="type === 105"
      :model-value="type === 105"
      :title="title"
      :before-close="fnClose"
    >
      <el-space wrap>
        <el-button type="primary" v-print="'#printContent'">打印</el-button>
      </el-space>
      <div id="printContent">
        <div style="text-align: center">
          <el-text size="large">
            {{ data.taskInfo.STUDY_NAME }}培训综合考评报告
          </el-text>
        </div>
        <br />
        <el-descriptions :column="2" border>
          <el-descriptions-item label="任务名称">
            {{ data.taskInfo.STUDY_NAME }}
          </el-descriptions-item>
          <el-descriptions-item label="培训组织部门">
            <!-- todo 原项目为空 -->
          </el-descriptions-item>
          <el-descriptions-item label="评估日期">
            {{ data.taskInfo.PEIXUE_END_TIME }}
          </el-descriptions-item>
          <el-descriptions-item label="考核方式">
            <!-- todo 原项目是写死的 -->
            考核
          </el-descriptions-item>
          <el-descriptions-item label="本次工作培训描述" :span="2">
            本次培训的主要内容是:{{ curriculums }}。 共应参加人数为{{
              data.studentList.length
            }}人, 实际参加培训人数为{{ join_student_list.length }}人, 参加率为{{
              (
                (join_student_list.length / data.studentList.length) *
                100
              ).toFixed(2)
            }}%
          </el-descriptions-item>
          <el-descriptions-item label="本次培训考评结论" :span="2">
            本次通过笔试的方式进行了培训效果考核,考核人数为{{
              data.studentList.length
            }}人,考核合格人数为{{ pass_student_list.length }}人, 合格率为{{
              (
                (pass_student_list.length / data.studentList.length) *
                100
              ).toFixed(2)
            }}%
          </el-descriptions-item>
          <el-descriptions-item label="改进意见建议" :span="2">
            <div>1.本次培训的讲师</div>
            <div>讲师的语言表达能力应该更加的生动、清晰、易懂</div>
            <div>非常满意</div>
            <div>2.本次培训的课程</div>
            <div>课程内容应该更加专业,可以对我的工作帮助更大</div>
            <div>非常满意</div>
          </el-descriptions-item>
        </el-descriptions>
      </div>
      <template #footer>
        <el-button @click="fnClose">关闭</el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import {
  getAllCurriculum,
  getStudyTaskInfo,
  getStudentByTaskId,
} from "@/request/archives.js";
import { computed, reactive } from "vue";
import { useVModels } from "@vueuse/core";

const props = defineProps({
  title: {
    type: String,
    required: false,
    default: "",
  },
  year: {
    type: String,
    required: false,
    default: "",
  },
  type: {
    type: Number,
    required: true,
  },
  studyTaskId: {
    type: String,
    required: false,
    default: "",
  },
});
const { title, type, studyTaskId } = useVModels(props);

const data = reactive({
  taskInfo: {},
  curriculumList: [],
  studentList: [],
});

const curriculums = computed(() => {
  if (data.curriculumList && data.curriculumList.length > 0) {
    return data.curriculumList
      .map((item) => {
        return item.CURRICULUMNAME;
      })
      .join(",");
  }
  return "";
});

const pass_student_list = computed(() => {
  const result = [];
  if (data.studentList && data.studentList.length > 0) {
    data.studentList.forEach((item) => {
      if (Number(item.STAGEEXAMSCORE) >= Number(data.taskInfo.PASSSCORE)) {
        result.push(item);
      }
    });
  }
  return result;
});

const join_student_list = computed(() => {
  const result = [];
  if (data.studentList && data.studentList.length > 0) {
    data.studentList.forEach((item) => {
      if (item.COMPLETE_COURSEWARE > 0) {
        result.push(item);
      }
    });
  }
  return result;
});

const emits = defineEmits(["update:visible"]);

const fnClose = () => {
  emits("update:current", undefined);
};

const fnGetStudyTaskInfo = async () => {
  if (studyTaskId && studyTaskId.value && studyTaskId.value.length > 0) {
    const respData = await getStudyTaskInfo({
      STUDYTASK_ID: studyTaskId.value,
    });
    if (respData && respData.pd) {
      data.taskInfo = respData.pd;
    }
  }
};
await fnGetStudyTaskInfo();

const fnGetAllCurriculum = async () => {
  if (studyTaskId && studyTaskId.value && studyTaskId.value.length > 0) {
    const respData = await getAllCurriculum({
      STUDYTASK_ID: studyTaskId.value,
    });
    if (respData && respData.varList) {
      data.curriculumList = respData.varList;
    }
  }
};
await fnGetAllCurriculum();

const fnGetStudentByTaskId = async () => {
  if (studyTaskId && studyTaskId.value && studyTaskId.value.length > 0) {
    const respData = await getStudentByTaskId({
      STUDYTASK_ID: studyTaskId.value,
    });
    if (respData && respData.varList) {
      data.studentList = respData.varList;
    }
  }
};
await fnGetStudentByTaskId();
</script>

<style scoped lang="scss"></style>