<template>
    <div class="app-container">
        <div style="width: 100%;  display: flex; justify-content: center; flex-wrap: nowrap;">
            <!-- <el-button type="primary" plain size="mini" @click="closeCurrentTab">关闭
            </el-button> -->
            <el-button type="primary" plain size="mini" @click="downloadProve">下载
            </el-button>
            <el-button type="primary" plain size="mini" @click="printTable">打印
            </el-button>
        </div>
        <el-card :style="{ width: '850px', height: clientHeight, margin: '0 auto' }">
            <div id="postFormContainer">
                <br /><br />
                <div style="display: block; font-weight: 600; font-size: 35px; text-align: center">学籍证明</div>
                <br />
                <span style="display: block; font-size: 25px; text-indent:50px; line-height: 40px">
                    {{ studentInfo.studentName }}同学，身份证号{{ studentInfo.idCard }} ，性别{{
                        studentInfo.sex
                    }}，{{ studentInfo.birthday }}生，
                    省学籍辅号{{ studentInfo.schoolNo }},全国学籍号{{
                        studentInfo.nationalNumber
                    }},系东营市第二中学{{ studentInfo.enrollmentYear }}级{{ studentInfo.classValue }}班学生，特此证明。
                </span>
                <br /><br /><br />
                <div style="width: 100%; display:flex; justify-content: center; font-size:20px;">
                    <div>
                        <el-image style="width: 160px; height: 200px" :src="url"></el-image>
                        <br />
                        <div style="text-align: center">山东学籍管理</div>
                    </div>
                </div>

                <br /><br /><br />
                <div style="position: relative; background: #1ab394">
                    <div style="position: absolute; right: 30px; font-size: 20px ">
                        <span>东营市第二中学</span>
                        <br /><br />
                        <span> {{ time }}</span>
                    </div>
                </div>
            </div>
        </el-card>
    </div>
</template>


<script>
import printJS from "print-js";
import { closeCurrentTab } from "@/utils/utilLibrary/routerBatch/routerBatch.js";
import { getStudent } from '@/api/smartSchool/teachAffairAdministration/affairStudentManage'

export default {
    name: 'StudentProve',
    data() {
        return {
            clientHeight: document.body.scrollHeight + 'px',
            baseUrl: process.env.VUE_APP_BASE_API,
            studentInfo: {},
            url: '',
            time: " ",
        }
    },
    components: {},
    methods: {
        closeCurrentTab,
        getImage() {
            const studentId = this.$route.query.id;
            getStudent(studentId).then((res) => {
                this.studentInfo = res.data
                if (res.data.sex == 0) {
                    this.studentInfo.sex = "男"
                } else {
                    this.studentInfo.sex = "女"
                }
                if (res.data.birthday.charAt(5) == 0) {
                    if (res.data.birthday.charAt(8) == 0) {
                        this.studentInfo.birthday = res.data.birthday.slice(0, 4) + "年" + res.data.birthday.slice(6, 7) + "月" + res.data.birthday.slice(9, 10) + "日"
                    } else {
                        this.studentInfo.birthday = res.data.birthday.slice(0, 4) + "年" + res.data.birthday.slice(6, 7) + "月" + res.data.birthday.slice(8, 10) + "日"
                    }

                } else {
                    if (res.data.birthday.charAt(8) == 0) {
                        this.studentInfo.birthday = res.data.birthday.slice(0, 4) + "年" + res.data.birthday.slice(5, 7) + "月" + res.data.birthday.slice(9, 10) + "日"
                    } else {
                        this.studentInfo.birthday = res.data.birthday.slice(0, 4) + "年" + res.data.birthday.slice(5, 7) + "月" + res.data.birthday.slice(8, 10) + "日"
                    }
                }
                this.url = this.baseUrl + this.studentInfo.avatar
                console.log(this.url, 107)
            });
        },
        // 打印
        printTable() {
            // 重置表单
            printJS({
                printable: 'postFormContainer',
                targetStyles: ['*'],
                type: "html",
            })
        },
        /**
         * 获取当前时间
         */
        currentTime() {
            var date = new Date();
            var year = date.getFullYear(); //月份从0~11，所以加一
            let month = date.getMonth();
            console.log("month", month);
            var dateArr = [
                date.getMonth() + 1,
                date.getDate(),
            ];
            var strDate =
                year + "年" + dateArr[0] + "月" + dateArr[1] + "日"
            console.log("strDate", strDate);
            return strDate

        },
        downloadProve() {
            this.download(`/school/studentStatus/proofStatus/${this.$route.query.id}`, {}, `${this.studentInfo.studentName}.docx`)
        },

    },
    created() {
        this.getImage()
        this.time = this.currentTime()
    },
    activated() {
        this.getImage()
        this.time = this.currentTime()
    }
}
</script>

<style scoped></style>
