<template>
    <div class="bigBox">
        <div class="box_title">
            <span>{{ fromObj.username }}培训档案</span>
        </div>
        <div class="box_gbig">
            <div class="box_left">
                <div class="left_header">
                    <h3 class="bold">个人岗位信息</h3>
                </div>
                <div class="from_list">
                    <div class="da-item">
                        <label class="da-label">人员姓名：</label>
                        <div class="ryxm">{{ fromObj.username }}</div>
                    </div>
                    <div class="da-item">
                        <label class="da-label">所属部门：</label>
                        <div class="ryxm">{{ fromObj.orgname }}</div>
                    </div>
                    <div class="da-item">
                        <label class="da-label">所属单位：</label>
                        <div class="ryxm">{{ fromObj.deptname }}</div>
                    </div>
                    <div class="da-item">
                        <label class="da-label">本年参与培训次数：</label>
                        <div class="ryxm">{{ fromObj.count }}次</div>
                    </div>
                    <div class="da-item">
                        <label class="da-label">参与培训效果：</label>
                        <div class="ryxm">{{ fromObj.avgScore }}</div>
                    </div>
                </div>
                <!-- 累计学时 -->
                <div class="ljxs">
                    <span>{{ listQuery.year }}年度累计学时：{{ fromObj.hour }}学时</span>
                </div>
            </div>
            <!-- 右边 -->
            <div class="box_right">
                <div class="box_tab">
                    <div class="tab_title">
                        <span class="bold">培训记录</span>
                    </div>
                    <section class="eltab3">
                        <MOSTY.Table :table-columns="tableColumn" :tableData="tableData" :tableloading="tableloading"
                            :isSelect="false" style="width: 100%;">
                            <template #type="{ row }">
                                <dict-tag :options="D_TB_YWLX" :value="row.type" :tag="false" />
                            </template>
                            <template #actions="{ row }">
                                <span class="operesee" @click="handleSee(row)">培训记录</span>
                                <span class="operesee" @click="handleSeefile(row)">培训详情</span>
                            </template>
                        </MOSTY.Table>
                    </section>
                    <div class="fenye">
                        <MOSTY.Pages :pageConfiger="pageConfiger" @changeSize="handleSizeChange"
                            @changeNo="handleCurrentChange">
                        </MOSTY.Pages>
                    </div>

                </div>
                <!-- 考试情况 -->
                <div class="box_tab box_bottom">
                    <div style="width: 25%;">
                        <div class="left_header">
                            <h3 class="bold">我的考试情况</h3>
                        </div>
                        <div class="min-heigt">
                            <div class="kszg">最高得分<span>{{ ksqkObj.maxScore }}</span>分</div>
                            <div class="kscs">考试<span>{{ ksqkObj.examCount }}</span>次</div>
                        </div>
                    </div>
                    <div style="width: 33%;">
                        <div class="left_header">
                            <h3 class="bold">我的评价</h3>
                        </div>
                        <ul class="pjlist">
                            <li v-for="item in ksqkObj.piList" :key="ID">
                                <div>{{ item.question }}:</div>
                                <div class="star-container">
                                    <div class="stars" v-for="(item, index) in item.answer" :key="index">
                                        <el-icon style="color: #e1650a;">
                                            <StarFilled />
                                        </el-icon>
                                    </div>
                                </div>
                            </li>
                        </ul>
                    </div>
                    <div style="width: 41%;">
                        <div class="left_header">
                            <h3 class="bold">学习课件</h3>
                            <div v-if='ksqkObj.files'>
                                <MOSTY.Upload width="800px" :limit="3" :nopicer="true" :isImg="false"
                                    :ShowfileList="false" v-model="ksqkObj.files" :delrow="delrow"
                                    :gsgfList="['pdf', 'ofd', 'doc', 'docx', 'xls', 'xlsx', 'wps']"
                                    @filehandleChange="changeFile" :showbut="false">
                                </MOSTY.Upload>
                                <ul>
                                    <li class="skli" v-for="item in kjList" :key="id">
                                        <span style="width: 90%;">{{ item.name }}</span>
                                        <a style="width: 10%;color: #0000FF;  text-decoration: underline;"
                                            @click="handledlon(item)">下载</a>
                                    </li>
                                </ul>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- 详情 -->
        <div v-if="addDiaShowxq" class="dialog-box">
            <pxssxqdia :formData="formObj" :type="types" @changeAddVi="changexqclose" from="profiledetails">
            </pxssxqdia>
        </div>
    </div>
</template>

<script setup>
// 引入
import { reactive, onMounted, ref, getCurrentInstance } from "vue";

import Addpxjhss from "./addpxss.vue";
import { dateFormat, createAndClickLink } from "@/utils/tools";
import { useRouter, useRoute } from 'vue-router';
import { getApi, deleteApi, putApi } from "@/api/tobAcco_api.js";
import { Html2canvasImg } from '@/utils/html2pdf.js';
import pxssxqdia from "../pxssxqdia.vue";
import * as MOSTY from "@/components/MyComponents/index";
import { filterqx } from "@/utils/auth.js";
// import * as html2pdf from 'html2pdf.js'
import { getItem } from "@/utils/storage";
const route = useRoute()
const types = ref(null);
const { proxy } = getCurrentInstance();
const formObj = ref({})
const { D_TB_YWLX } = proxy.$dict("D_TB_YWLX");
const addDiaShowxq = ref(false);
const ksqkObj = ref({
    examCount: 0,
    maxScore: 0,
    piList: [],
})
const tableloading = ref(false);
const listQuery = ref({
    pageCurrent: 1,
    pageSize: 20,
    year: new Date().getFullYear().toString(),
    userid: getItem('USERID')
});
//当前登录部门等级
const orgLevel = ref(JSON.parse(window.localStorage.getItem("deptId")).orgLevel.substring(0, 1))
const total = ref(0)
const emits = defineEmits(["close"]);
const tableData = ref([]);
const fromObj = ref({});
const kjList = ref([]);
const tableColumn = ref([
    {
        title: "培训时间",
        prop: "startDate",
        sortable: true
    },
    {
        title: "培训项目",
        prop: "planName",
        sortable: true
    },
    {
        title: "培训类别",
        prop: "type",
        sortable: true,
        slot: true
    },
    {
        title: "操作",
        prop: "actions",
        slot: true
    }
])
const pageConfiger = reactive({
    pageSize: 20,
    pageCurrent: 1,
    total: 0
})
onMounted(() => {
    if (route.query.userid) {
        listQuery.value.year = route.query.year
        listQuery.value.userid = route.query.userid
    }
    getgwxxdata()
    getListData()
});
//获取岗位信息
function getgwxxdata() {
    let data = {
        userid: listQuery.value.userid,
        year: listQuery.value.year,
    }
    getApi(data, '/mosty-jcgl/training/other/getCheckUser').then((res) => {
        fromObj.value = res
    })
}
//获取培训记录信息
function getListData() {
    getApi(listQuery.value, '/mosty-jcgl/training/other/getTrainingByUserId').then((res) => {
        if (res.records) {
            tableData.value = res.records
            if (tableData.value) {
                tableData.value.forEach(async (item) => {
                    if (item.otherType == '09') {
                        let jbobj = await getsjData(item.id)
                        item.sj = jbobj.sj
                        item.ej = jbobj.ej
                        item.oldejid = jbobj.ejid ? jbobj.ejid : null
                        item.oldsjid = jbobj.sjid ? jbobj.sjid : null
                    }

                })
            }
            pageConfiger.total = res.total
        }
    })
}
//获取三级培训信息
const getsjData = async (id) => {
    return new Promise(ok => {
        getApi({ id, year: listQuery.value.year }, '/mosty-jcgl/training/getSjpxDetail').then((res) => {
            ok(res ? res : [])
        })
    })
}
//培训记录
function handleSee(val) {
    getksqkData(val.id)
}
//我的考试情况-我的评价-学习课件
function getksqkData(trainingId) {
    getApi({ trainingId, userid: listQuery.value.userid }, '/mosty-jcgl/training/other/getMyTrainingInfo').then(res => {
        if (res) {
            res.piList.forEach(item => {
                item.answer = parseInt(item.answer)
            })
            ksqkObj.value = res
        }
    })
}
function handleSeefile(row) {
    var isTrue = false;
    //计划外没有三级培训
    getApi({ id: row.planHostsDeptId }, '/mosty-base/deptFeign/getOrgById').then(res => {
        formObj.value.orgLevel = res.orgLevel
        // 是否是安全部门
        if (filterqx('isaqbm') == '1') {
            if (res.orgLevel.substring(0, 1) == '1') {
                if (orgLevel.value == '1') {
                    isTrue = true
                }
            } else if (res.orgLevel.substring(0, 1) == '2') {
                //当前登录部门orgLevel为1、2能看
                if (orgLevel.value == '1' || orgLevel.value == '2') {
                    isTrue = true
                }
            } else if (res.orgLevel.substring(0, 1) == '3') {
                if (orgLevel.value == '1' || orgLevel.value == '2' || orgLevel.value == '3') {
                    isTrue = true
                }
            }
        } else {
            isTrue = false
        }
        if (isTrue && row.otherType == "09") {
            formObj.value.sjtype = 'yj'
            formObj.value.title = '三级教育培训详情'
        } else {
            if (row.ej && row.otherType == "09") {
                //二级未实施
                formObj.value.sjtype = 'yj'
                formObj.value.title = '三级教育培训详情（一级培训）'
            } else if ((row.sj && row.otherType == "09") || row.oldejid) {
                //二级已实施，三级未实施
                formObj.value.sjtype = 'ej'
                formObj.value.title = '三级教育培训详情（二级培训）'
            } else if (row.oldsjid) {
                //三级已实施
                formObj.value.sjtype = 'sj'
                formObj.value.title = '三级教育培训详情（三级培训）'
            } else {
                formObj.value.sjtype = 'jc'
                formObj.value.title = '培训详情'
            }
        }
        formObj.value.id = row.id;
        formObj.value.state = row.state;
        formObj.value.oldejid = row.oldejid;
        formObj.value.type = row.type;
        addDiaShowxq.value = true
    })


    // row.type == '1'(计划内)
    // router.push({
    //     path: '/pxjhcoms/pxssxq', query
    //         : {
    //         id: row.id,
    //         title: '培训计划详情',
    //         type: row.type
    //     }
    // })
}
function changexqclose() {
    formObj.value.id = null;
    formObj.value.type = null;
    addDiaShowxq.value = false
    getgwxxdata()
    getListData()
}
//接收附件
const changeFile = (data) => {
    kjList.value = data
};
//点击下载文件
function handledlon(val) {
    createAndClickLink(val.url, val.name)
}
/**
 * pageSize 改变触发
 */
const handleSizeChange = (currentSize) => {
    pageConfiger.pageSize = currentSize;
    listQuery.value.pageSize = currentSize;
    getListData();
};

/**
 * 页码改变触发
 */
const handleCurrentChange = (currentPage) => {
    pageConfiger.pageCurrent = currentPage;
    listQuery.value.pageCurrent = currentPage;
    getListData();

};


</script>

<style lang="scss" scoped>
.box_title {
    height: 50px;
    border-bottom: 1px dashed #bbb1b1;
    width: 100%;
    display: flex;
    justify-content: space-between;
    text-align: center;
    background-color: #fff;

    >span {
        font-size: 18px;
        color: #000;
        line-height: 51px;
        margin: 0 auto;
    }

}

.box_gbig {
    width: 100%;
    height: calc(100vh - 173px);
    margin: 20px;
    overflow-y: scroll;
    display: flex;
    justify-content: space-between;

    .box_left {
        width: 25%;
        padding: 7.5px;
        border-radius: 2px;
        background-color: #fff;
        box-shadow: 0 1px 2px 0 rgba(0, 0, 0, .05);
        margin-bottom: 42px;

        .from_list {
            position: relative;
            padding: 10px 0px;
            line-height: 24px;
            height: calc(100vh - 323px);

            .da-item {
                overflow: hidden;
                padding: 10px;

                // display: flex;

                .da-label {
                    color: #000;
                    display: inline-block;
                    text-align: right;
                    padding-right: 10px;
                    width: 37%;
                    min-width: 100px;
                }

                .ryxm {
                    color: #000;
                    font-size: 15px;
                    font-weight: bold;
                    display: inline-block;
                }
            }
        }
    }
}

.left_header {
    position: relative;
    height: 19px;
    line-height: 0px;
    padding: 0 15px;
    border-bottom: 1px solid #f6f6f6;
    color: #333;
    border-radius: 2px 2px 0 0;
}

.bold {
    font-weight: bold;
    font-size: 15px;
}

.btn {
    margin-top: auto 10px;
}

.ljxs {
    height: 3.75rem;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #d9e9ff;
    font-size: 18px;
    color: #006dff;
}

.box_right {
    width: 71%;
    margin-right: 21px;

    .box_tab {
        padding: 0 10px;
        margin-bottom: 15px;
        border-radius: 2px;
        background-color: #fff;
        box-shadow: 0 1px 2px 0 rgba(0, 0, 0, .05);
    }
}

.tab_title {
    display: flex;
    justify-content: space-between;
    position: relative;
    height: 42px;
    line-height: 42px;
    padding: 0 15px;
    border-bottom: 1px solid #f6f6f6;
    color: #333;
    border-radius: 2px 2px 0 0;
    font-size: 14px;

}

.operate {
    height: 22px;
    line-height: 22px;
    padding: 0 5px;
    font-size: 12px;
    border: 1px solid #C9C9C9;
    background-color: #fff;
    color: #555;
    display: inline-block;
    white-space: nowrap;
    text-align: center;
    border-radius: 2px;
    cursor: pointer;
}

.eltab3 {
    height: calc(100vh - 670px);
}

.box_bottom {
    display: flex;
    margin-top: 10px;

    >div {
        border-right: 1px solid #f6f6f6;
    }
}

.min-heigt {
    min-height: 196px;
    text-align: center;
    line-height: 40px;
    position: relative;
    padding: 10px 15px;
    line-height: 40px;
    color: #000;
}

.kscs span {
    font-size: 18px;
    color: #3145ff;
    padding: 0 10px;
    font-weight: bold;
}

.kszg span {
    font-size: 18px;
    color: #1dd809;
    padding: 0 10px;
    font-weight: bold;
}

.pjlist {
    >li {
        padding: 10px;
        display: flex;
        justify-content: space-between;
        color: #000;

        >div {
            line-height: 25px;
        }


    }
}


.star-container {
    position: relative;
    width: 200px;
    display: flex;
}



.skli {
    display: flex;
    border-bottom: dotted 1px #e2e2e2;
    justify-content: space-between;
    padding: 10px 5px;
    line-height: 24px;
}
</style>
