<template>
    <div class="commonCvList">
        <!-- 个人简历弹出框 -->
      

        <p style="color: #aaa; margin: 0 0 0px 0px" v-if="cvitaTable1 && cvitaTable1.length == 0">No data</p>

       
        <div style="margin: 0 0 0 0px">
            <div v-for="(item, index) in cvitaTable1" style="height: 30px;">
                <span style="color: #888;">{{ index + 1 }}.</span>
                <img src="../../assets/img/icon_0.png" alt="" class="icon_img" style="vertical-align: middle; margin-left: 10px" />
                <span style="margin-left: 20px; color: #888; font-size: 13px">
                    <i class="el-icon-paperclip"></i>
                    {{ formatDate(item.ctime) }}
                </span>
                <a :href="mediaUrl + 'reviewer/' + item.cv" target="_blank" class="txt_pdf">
                    <i class="el-icon-download"></i>
                </a>
                <i v-if="isEdit"
                    class="el-icon-delete"
                    @click="deletCVita(item)"
                    style="color: #f12424; cursor: pointer; font-weight: bold; margin: 0 0 0 15px"
                ></i>
            </div>
        </div>
        <div v-if="isEdit">
            <p style="margin: 20px 0"></p>
        <el-upload style="position: relative"
            class="upload-demo"
            :action="baseUrl + 'api/Ucenter/up_cv_file'"
            :on-success="handleFileSuccess1"
            name="reviewerCV"
            type="reviewerCV"
            :on-error="handleFileError"
            :on-preview="handlePreview"
            :on-remove="handleRemove"
            :before-remove="beforeRemove"
            :on-change="handleChange1"
            accept=".pdf"
            :on-exceed="handleExceed"
            ref="uploadRef1"
        >
            <el-button type="text" style="font-weight: bolder">
                <b class="el-icon-lx-top" style="font-weight: bolder"></b>upload
            </el-button>
            <div class="el-upload__tip" slot="tip">
                Only PDF and compressed files can be uploaded (file format: .pdf).
                <div style="font-size: 12px; color: #888; line-height: 14px">If you want to update your resume, please upload it.</div>
            </div>
        </el-upload>   
        </div>
      
    </div>
</template>

<script>
import Schart from 'vue-schart';
import bus from '../common/bus';
export default {
    name: 'dashboard',
    props:{
        isEdit: {
            type: Boolean,
            default:true
        },
    },
    data() {
        return {
            user_id: '',
            baseUrl: this.Common.baseUrl,
            mediaUrl: this.Common.mediaUrl,
            cvitaTable1: [],
            cvitaForm: {},
            fileL_pdf1: []
        };
    },
    created: function () {},

    components: {
        Schart,
        'el-image-viewer': () => import('element-ui/packages/image/src/image-viewer')
    },
    computed: {},
    methods: {
        init(list) {
            this.user_id = localStorage.getItem('U_id');
            this.cvitaForm.user_id = this.user_id;
            console.log('this.user_id at line 75:', this.user_id);
            this.cvitaTable1=[...list]
            // this.getCVitaData();
        },
        // 获取简历列表
        getCVitaData() {
            this.$api
                .post('api/Ucenter/getUserInfo', {
                    user_id: this.user_id
                })
                .then((res) => {
                    if (res.code == 0) {
                        this.cvitaTable1 = res.data.cvs;
                        this.$emit('cvitaTable', this.cvitaTable1);
                    } else {
                        this.$message.error(res.msg);
                    }
                })
                .catch((err) => {
                    this.$message.error(err);
                });
        },

        // 删除简历
        deletCVita(e) {
            // 二次确认删除
            this.$confirm('Are you sure you want to delete the CV.?', 'Tip', {
                type: 'warning'
            })
                .then(() => {
                    this.$api
                        .post('api/Ucenter/delUserCv', e)
                        .then((res) => {
                            if (res.code == 0) {
                                this.$message.success('Delete successful!');
                                this.getCVitaData();
                            } else {
                                this.$message.error(res.msg);
                            }
                        })
                        .catch((err) => {
                            this.$message.error(err);
                        });
                })
                .catch(() => {});
        },

        // 星级弹出层

        // 上传文件
        handleChange1(file, fileList) {
            if (fileList.length > 0) {
                this.fileL_pdf1 = [fileList[fileList.length - 1]];
            }
        },
        handleFileSuccess1(res, file) {
            this.$refs.uploadRef1.clearFiles();
            if (res.code == 0) {
                this.cvitaForm.cv = res.upurl;
                this.$api
                    .post('api/Ucenter/addUserCv', this.cvitaForm)
                    .then((res) => {
                        if (res.code == 0) {
                            this.$message.success('Upload succeeded!');
                            this.getCVitaData();
                        } else {
                            this.$message.error(res.msg);
                        }
                    })
                    .catch((err) => {
                        this.$message.error(err);
                    });
            } else {
                this.$message.error(res.msg);
            }
        },
        beforeRemove(file, fileList) {
            return this.$confirm(`Remove ${file.name}？`);
        },
        handleFileError(res, file) {},

        handleRemove(file, fileList) {},
        handlePreview(file) {
            window.open(file.url);
        },
        handleExceed(files, fileList) {
            this.$message.warning('The current limit is 1 file. Please delete the current file first！');
        },

        // 时间格式
        formatDate(timestamp) {
            var date = new Date(timestamp * 1000); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
            var Y = date.getFullYear() + '-';
            var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
            var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
            var h = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
            var m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
            var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
            return Y + M + D;
        },

        formatYear(timestamp) {
            var date = new Date(timestamp * 1000); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
            var Y = date.getFullYear() + ' . ';
            var M = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
            return Y + M;
        }
    }
};
</script>

<style scoped>
.el-image-viewer__wrapper {
    z-index: 5000 !important;
    padding: 50px 0;
}

.el-image-viewer__wrapper .el-icon-circle-close {
    color: #fff !important;
}

.txt_pdf {
    margin: 0 0 20px 10px;
    display: inline-block;
    color: #333;
}

.txt_pdf > i {
    color: #66a9f0;
    font-weight: bold;
    margin-left: 10px;
}
.commonCvList .el-upload__tip {
    position: absolute;
    top: -14px;
    left: 70px;
    color: #333;
    font-size: 12px;
}
</style>
