<template>
  <div>
    <el-dialog
      v-if="type === 106"
      :model-value="type === 106"
      :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">
            {{ CORP_NAME }} {{ data.taskInfo.post_type_name }}
          </el-text>
        </div>
        <template v-for="(item, index) in data.coursewareList" :key="index">
          <el-descriptions
            :title="`${index + 1}.${item.COURSEWARENAME}`"
            :column="1"
            border
          >
            <el-descriptions-item label="讲师：">
              {{ item.SPEAKER }}
            </el-descriptions-item>
            <el-descriptions-item label="课件类型：">
              {{ item.coutType }}
            </el-descriptions-item>
            <el-descriptions-item label="课件描述：">
              {{ item.COURSEWAREINTRODUCE }}
            </el-descriptions-item>
          </el-descriptions>
        </template>
      </div>
      <template #footer>
        <el-button @click="fnClose">关闭</el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import {
  getAllCoursewareByHandout,
  getStudyTaskInfo,
} from "@/request/archives.js";
import { reactive } from "vue";
import { useVModels } from "@vueuse/core";
import { useUserStore } from "@/pinia/user.js";

const userStore = useUserStore();
const CORP_NAME = userStore.getUserInfo.CORP_NAME;

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: {},
  coursewareList: [],
});

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 fnGetAllCoursewareByHandout = async () => {
  if (studyTaskId && studyTaskId.value && studyTaskId.value.length > 0) {
    const respData = await getAllCoursewareByHandout({
      STUDYTASK_ID: studyTaskId.value,
    });
    if (respData && respData.varList) {
      data.coursewareList = respData.varList;
    }
  }
};
await fnGetAllCoursewareByHandout();
</script>

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