<template>
  <el-dialog
    :title="title"
    :model-value="type === 102"
    width="1100px"
    @close="fnClose"
  >
    <div class="tr">
      <el-button type="primary" @click="fnExport">导出</el-button>
    </div>
    <div class="tc">
      <h3>{{ year }}年度本单位师资管理台账</h3>
    </div>
    <p class="mb">单位名称:{{ name }}</p>
    <layout-table :data="data.list" :show-pagination="false">
      <el-table-column type="index" label="序号" width="60" />
      <el-table-column prop="NAME" label="姓名" />
      <el-table-column prop="WORKYEAR" label="从事本专业工作年限" />
      <el-table-column prop="OCCUPATION" label="专/兼职">
        <span>兼职</span>
      </el-table-column>
      <el-table-column prop="CARD_ID" label="证书编号" />
      <el-table-column prop="ASSESSMENTDEPARTMENT" label="考核部门" />
      <el-table-column prop="ASSESSMENTTIME" label="考核日期" />
      <el-table-column prop="ASSESSMENTRESULT" label="考核结果" />
      <el-table-column prop="DESCR" label="备注" />
    </layout-table>
    <div class="flex mt">
      <div>档案管理人员:</div>
      <div>更新日期:</div>
    </div>
    <template #footer>
      <el-button @click="fnClose">关闭</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import LayoutTable from "@/components/table/index";
import { reactive, watchEffect } from "vue";
import { ElMessageBox } from "element-plus";
import { debounce } from "throttle-debounce";
import {
  getArchivesTeacherList,
  downloadTeacherword,
} from "@/request/training_archive_management.js";

const props = defineProps({
  type: {
    type: Number,
    required: true,
  },
  title: {
    type: String,
    required: true,
  },
  CORPINFO_ID: {
    type: String,
    required: true,
  },
  name: {
    type: String,
    required: true,
  },
  year: {
    type: String,
    required: true,
  },
});
const data = reactive({
  list: [],
});
const emits = defineEmits(["update:type"]);
const fnGetData = async () => {
  const resData = await getArchivesTeacherList({
    TYPE: props.type,
    CORPINFO_ID: props.CORPINFO_ID,
    YEAR: props.year,
  });
  data.list = resData.varList;
};
watchEffect(() => {
  if (props.type === 102) fnGetData();
});
const fnExport = debounce(
  1000,
  async () => {
    await ElMessageBox.confirm("确定要导出吗？", { type: "warning" });
    await downloadTeacherword({
      YEAR: props.year,
      CORPINFO_ID: props.CORPINFO_ID,
      NAME: props.name,
    });
    await ElMessageBox.confirm(
      "导出后请前往档案下载中下载该档案！",
      "温馨提示",
      { type: "info" }
    );
  },
  { atBegin: true }
);
const fnClose = () => {
  emits("update:type", 0);
};
</script>

<style scoped lang="scss">
.flex {
  width: 80%;
  display: flex;
  justify-content: space-between;
}
</style>
