<template>
    <div class="performanceanalysis-all" element-loading-text="AI生成耗时较长请耐心等待"
        v-loading.fullscreen.lock="performanLoading">
        <el-dialog width="900px" title="AI绩效分析" :visible.sync="AIVisible">
            <div id="pdfDom">
                <div style="margin-bottom: 40px;" v-html="marktext" class="markdownyangshi markdown-body"></div>
                <el-table style="font-size:12px" v-if="bumensb=='市场部'" :data="SCgridData" border>
                    <el-table-column prop="rowNumber" label="序号" width="60">
                    </el-table-column>
                    <el-table-column prop="teamName" label="团组名">
                    </el-table-column>
                    <el-table-column prop="groupSales" label="营业额" width="150">
                        <template slot-scope="scope">¥&nbsp;{{ scope.row.groupSales | townum }}</template>
                    </el-table-column>
                    <el-table-column prop="visitDate" label="出访日期" width="120">
                        <template slot-scope="scope">{{ scope.row.visitDate | getvisitDate }}</template>
                    </el-table-column>
                    <el-table-column prop="visitPNumber" label="人数" width="50">
                    </el-table-column>
                    <el-table-column prop="collectionDays" label="收款日期" width="110">
                        <template slot-scope="scope">{{ scope.row.collectionDays | getvisitDate }}</template>
                    </el-table-column>
                </el-table>
                <div style="margin-top: 40px;" v-html="marktexts" class="markdownyangshi markdown-body"></div>
            </div>
            <!-- <div style="text-align: right;margin-top: 15px;">
                <el-button size="small" type="primary" @click="exportToPDF">导出为PDF</el-button>
            </div> -->
        </el-dialog>
        <div style="display: flex;justify-content: space-between;align-items: center;margin-bottom: 10px;">
            <div class="performanceanalysis-haed">
                <div class="performanceanalysis-haed-li">

                    <label>时间范围:</label>
                    <!-- <el-date-picker @change="AiPerformanceAnalysis_UserList" style="width:250px" size="small" v-model="months" type="month" placeholder="选择月">
                    </el-date-picker> -->
                    <el-date-picker @change="AiPerformanceAnalysis_UserList" style="width:250px" size="mini" v-model="months" type="daterange" align="right"
                        unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
                        :picker-options="pickerOptions">
                    </el-date-picker>
                </div>
                <div class="performanceanalysis-haed-li">
                    <label>公司/岗位/用户:</label>
                    <el-input style="width:200px" size="mini" placeholder="请输入内容" v-model="value" clearable></el-input>
                </div>
                <div class="performanceanalysis-haed-li">
                    <el-button @click="sousuoccc" size="mini" type="primary">搜索</el-button>
                </div>
            </div>
            <div>
                <!-- <el-button size="small" type="primary">导出全年分析</el-button> -->
            </div>
        </div>
        <div class="performanceanalysis-table">
            <el-table :data="tableData" border style="width: 100%">
                <el-table-column prop="userName" label="员工姓名" width="100">
                </el-table-column>
                <el-table-column prop="sex" label="性别" width="100">
                </el-table-column>
                <el-table-column prop="companyName" label="所属公司">
                </el-table-column>
                <el-table-column prop="jobName" label="岗位">
                </el-table-column>
                <el-table-column prop="eDate" label="入职时间" width="180">
                </el-table-column>
                <el-table-column prop="workYears" label="工龄" width="100">
                </el-table-column>
                <el-table-column label="操作" width="350">
                    <template slot-scope="scope">
                        <el-button type="primary" @click="AiPerformanceAnalysis_GroupStatistics(scope.row,'生成')"
                            size="mini">生成AI分析</el-button>
                        <el-button v-if="scope.row.hasPerformanceData" type="success" @click="AiPerformanceAnalysis_GroupStatistics(scope.row,'查看')" size="mini">查看分析</el-button>
                        <el-button v-else type="primary" @click="AiPerformanceAnalysis_GroupStatistics(scope.row,'查看')" size="mini">查看分析</el-button>
                        <el-button type="primary" @click="FileDownAi(scope.row)" size="mini">下载</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="block">
                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                    :current-page="currentPage" :page-sizes="[10, 15, 20, 100]" :page-size="pagesize"
                    layout="total, sizes, prev, pager, next, jumper" :total="total">
                </el-pagination>
            </div>
        </div>
        <!-- <div v-html="marktext" class="markdownyangshi markdown-body"></div> -->
    </div>
</template>
<script>
import html2canvas from 'html2canvas';
import { jsPDF } from 'jspdf';
import "github-markdown-css"
export default {
    data () {
        return {
            userId:'',
            texehr:'\n\n---\n',
            text:'根据您提供的陈小龙2025年9月外出打卡数据，现进行绩效分析如下：\n\n### 一、基础数据统计\n**总打卡次数**：16次  \n**覆盖日期**：9月2日-9月29日（共28天）  \n**有效工作日**：22天（扣除周末）\n\n### 二、客户拜访量分析\n1. **实际拜访客户数**：9个\n   - 重庆商务职业学院（2次）\n   - 重庆市南岸区商务委员会（2次）\n   - 重庆市城投金卡信息产业(集团)股份有限公司（2次）\n   - 玉马路\n   - 重庆市南岸区人民政府外事办公室\n   - 重庆经济技术开发区\n   - 中共南岸区委党校\n   - 重庆市南岸区社会主义学院教学楼\n   - 重庆建筑工程职业学院(东站校区)\n   - 中德职业教育西部中职示范基地\n   - 重庆市璧山区人民政府\n\n2. **与标准对比**：\n   - 目标拜访量：20个客户/月\n   - 完成率：45%（9/20）\n   - **结论：未达到合格标准**\n\n### 三、工作模式分析\n**优势**：\n1. 区域集中度较高：主要活跃在南岸区茶园片区（11次打卡）\n2. 重要客户重复拜访：3个重点客户有2次以上跟进记录\n3. 单日效率突出：9月26日完成4个点位拜访\n\n**待改进点**：\n1. 出勤稳定性不足：28天中仅16天有外出记录\n2. 单日拜访密度低：日均拜访0.57个客户\n3. 时间利用不均衡：多个工作日上午无外出记录\n\n### 四、改进建议\n1. **提升拜访频率**：\n   - 建议将日均拜访量提升至1-1.5个客户\n   - 合理安排行程，减少单点停留时间\n\n2. **优化区域规划**：\n   - 继续保持南岸区的集中开发\n   - 沙坪坝区（大学城）客户可集中安排单日拜访\n\n3. **加强过程管理**：\n   - 建立每日拜访计划\n   - 重要客户保持每月2-3次跟进频率\n\n### 五、综合评级：不合格\n按现行标准（20个客户/月），完成率仅45%。建议结合以下因素综合评估：\n- 客户质量（政府机构/职业院校占比高）\n- 单次拜访实效（需结合业务成果）\n- 区域开发难度\n\n是否需要调整考核标准或提供专项支持，建议直属领导进行面谈沟通。\n\n---\n**数据说明**：本分析仅基于打卡位置去重计算，实际客户数量可能需要结合业务系统数据进一步确认。'
            ,marktext:'',
            text2:"赖红燕 2025年9月考勤分析报告\n\n## 考勤概览\n分析周期 2025年9月1日至9月30日\n应出勤天数 22天\n实际打卡记录 28条\n异常打卡情况 存在迟到和缺卡记录\n\n## 详细打卡记录\n\n### 正常出勤日\n9月4日 上班0858 下班1909\n9月5日 上班0853 下班1836\n9月11日 上班0859 下班1827\n9月12日 上班0852 下班1847\n9月15日 上班0855 下班1847\n9月16日 上班0859 下班1815\n9月17日 上班0859 下班1905\n9月18日 上班0858 下班2007\n9月23日 上班0849 下班1902\n9月24日 上班0855 下班1906\n9月25日 上班0856 下班2042\n9月26日 上班0855 下班1816\n9月28日 上班0858 下班1836\n\n### 迟到记录\n9月1日 上班0902 迟到2分钟\n9月2日 上班0902 迟到2分钟\n9月3日 上班0903 迟到3分钟\n9月8日 上班0902 迟到2分钟\n9月19日 上班0901 迟到1分钟\n\n### 缺卡记录\n9月29日 全天未打卡\n9月30日 全天未打卡\n\n### 特殊考勤情况\n9月9日 上班1052 下班1824 上午迟到\n9月10日 上班0846 下班1211 下午早退\n9月22日 上班0902 下班1901 无排班记录\n\n## 考勤分析总结\n\n出勤表现 大部分时间能按时出勤，工作态度较为积极\n迟到情况 本月共5次迟到，均为1-3分钟的轻微迟到\n缺勤情况 月末29-30日连续两天未打卡，需关注原因\n加班情况 多日存在加班记录，最晚工作至2042\n考勤异常 9月9-10日及22日考勤异常，可能存在特殊工作安排\n\n建议 加强考勤纪律，减少迟到现象，对连续缺卡情况需要了解具体原因\n",
            marktexts:'',
            pickerOptions: {
                shortcuts: [{
                    text: '最近一周',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近十五天',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 15);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            },
            datevalue:null,
            companyName:'',
            companyNameArr:[],
            value:'',
            tableData:[],
            currentPage:1,
            pagesize:10,
            total:0,
            AIVisible:false,
            SCgridData:[],
            performanLoading:false,
            months:'',
            bumensb:'',
            // position:'',
            // positionArr:[],
            // employeeName:'',
            // employeeNameArr:[],
        }
    },
    filters: {
        getvisitDate(val) {
            return val.split(' ')[0];
        },
        townum(val){
            return val.toFixed(2)
        },
    },
    methods:{
        handleSizeChange(val) {
            this.currentPage=1;
            this.pagesize=val;
            this.AiPerformanceAnalysis_UserList();
        },
        handleCurrentChange(val) {
            this.currentPage=val;
            this.AiPerformanceAnalysis_UserList();
        },
        sousuoccc(){
            this.currentPage=1;
            this.AiPerformanceAnalysis_UserList();
        },
        //获取renyuan详情
        AiPerformanceAnalysis_UserList(){
            // var new_year = this.months.getFullYear()
            // var month = this.months.getMonth();
            // var new_month = month + 1;
            var url = "/api/PersonnelModule/AiPerformanceAnalysis_UserList"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer '
                },
                data: {
                    portType:1,
                    pageIndex:that.currentPage,
                    pageSize:that.pagesize,
                    screeningCriteria:that.value,
                    startDate:that.datetime(that.months[0])+ ' 00:00:00',
                    endDate:that.datetime(that.months[1])+ ' 00:00:00',
                    userId:that.userId
                }
            }).then(function (res) {
                if(res.data.code==200){
                    that.total=res.data.count;
                    that.tableData=res.data.data;
                }else{
                    that.$message.error(res.data.msg);
                }
            })
        },
        //处理日期
        datetime(val){
            var date=new Date(val);
            var y=date.getFullYear();
            var m=date.getMonth()+1>=10?date.getMonth()+1:'0'+(date.getMonth()+1).toString();
            var d=date.getDate()>=10?date.getDate():'0'+(date.getDate()).toString();
            return y+'-'+m+'-'+d
        },
        //市场不al分析接口
        //下面是整月逻辑
        // var new_year = this.months.getFullYear()
        // var month = this.months.getMonth();
        // var new_month = month + 1;
        // var firstDay = new Date(new_year, new_month - 1, 1); 
        // var lastDay = new Date(new_year, new_month, 0).getDate();
        // var mon = (new_month < 10 ? '0' : '') + new_month;
        // var startDateDay = ('0' + firstDay.getDate()).slice(-2);
        // var startDate = new_year + '-' + mon + '-' + startDateDay;
        // var endDate = new_year + '-' + mon + '-' + lastDay; 
         AiPerformanceAnalysis_JobMarketing(val){
            
            var url = "/api/PersonnelModule/AiPerformanceAnalysis_JobMarketing?userId="+val.id+"&start="+this.datetime(this.months[0])+"&end="+this.datetime(this.months[1])+"&createUserId="+this.userId
            var that = this
            this.$axios({
                method: 'get',
                url: url,
                headers: {
                    Authorization: 'Bearer '
                }
            }).then(function (res) {
                if(res.data.code==200){
                    that.performanLoading=false;
                    that.AIVisible=true;
                    if (that.$marked && typeof that.$marked === 'function') {
                        that.marktext = that.$marked(res.data.data.answer+that.texehr);
                        that.marktexts = that.$marked(that.texehr + res.data.data.kaoqinAnswer);
                    }
                    that.AiPerformanceAnalysis_UserList();
                }else{
                    that.performanLoading=false;
                    that.$message.error('AI绩效分析生成失败，请稍后重试！');
                }
            })
        },
        //市场部绩效下载接口
        AiPerformanceAnalysis_JobMarketingFileDown(new_year,new_month,val){
            var url = "/api/PersonnelModule/AiPerformanceAnalysis_JobMarketingFileDown?start="+new_year+"&end="+new_month+"&userId="+val.id
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer '
                }
            }).then(function (res) {
                if(res.data.code==200){
                    that.$message({
                        message: res.data.msg,
                        type: 'success',
                    });
                    window.open(res.data.data.url);
                }else{
                    that.$message.error(res.data.msg);
                }
            })
        },
        //国交部绩效下载接口
        AiPerformanceAnalysis_GuojiaoFileDown(new_year,new_month,val){
            var url = "/api/PersonnelModule/AiPerformanceAnalysis_GuojiaoFileDown?start="+new_year+"&end="+new_month+"&userId="+val.id
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer '
                }
            }).then(function (res) {
                if(res.data.code==200){
                    that.$message({
                        message: res.data.msg,
                        type: 'success',
                    });
                    window.open(res.data.data.url);
                }else{
                    that.$message.error(res.data.msg);
                }
            })
        },
        //下载
        FileDownAi(val){
            if(this.months==''){
                this.$message.error('请选择月份！');
                return
            }
            //下面是整月逻辑
            // var new_year = this.months.getFullYear()
            // var month = this.months.getMonth();
            // var new_month = month + 1;
            if (val.depName=='市场部') {
                this.AiPerformanceAnalysis_JobMarketingFileDown(this.datetime(this.months[0]),this.datetime(this.months[1]),val);
                // this.AiPerformanceAnalysis_JobMarketingFileDown(new_year,new_month,val);
            }else if(val.depName=='国交部'||val.depName=='信息部'){
                this.AiPerformanceAnalysis_GuojiaoFileDown(this.datetime(this.months[0]),this.datetime(this.months[1]),val);
                // this.AiPerformanceAnalysis_GuojiaoFileDown(new_year,new_month,val);
            }
        },
        //查看
        AiPerformanceAnalysis_Query(val){
            if(this.months==''){
                this.$message.error('请选择月份！');
                return
            }
            //下面是整月逻辑
            // var new_year = this.months.getFullYear()
            // var month = this.months.getMonth();
            // var new_month = month + 1;
            var url = "/api/PersonnelModule/AiPerformanceAnalysis_Query?start="+this.datetime(this.months[0])+"&end="+this.datetime(this.months[1])+"&userId="+val.id
            var that = this
            this.$axios({
                method: 'get',
                url: url,
                headers: {
                    Authorization: 'Bearer '
                }
            }).then(function (res) {
                if(res.data.code==200){
                    that.performanLoading=false;
                    that.AIVisible=true;
                    let inif= JSON.parse(res.data.data.jsonResult)
                    if (that.$marked && typeof that.$marked === 'function') {
                        that.marktext = that.$marked(inif.Answer+that.texehr);
                        that.marktexts = that.$marked(that.texehr + inif.KaoqinAnswer);
                    }
                }else{
                    that.performanLoading=false;
                    that.$message.error('查看失败，请稍后重试！');
                }
            })
        },
        //生成机票绩效
        AiPerformanceAnalysis_AirTicket(val){
            //下面是整月逻辑
            // var new_year = this.months.getFullYear()
            // var month = this.months.getMonth();
            // var new_month = month + 1;
            // var firstDay = new Date(new_year, new_month - 1, 1); 
            // var lastDay = new Date(new_year, new_month, 0).getDate();
            // var mon = (new_month < 10 ? '0' : '') + new_month;
            // var startDateDay = ('0' + firstDay.getDate()).slice(-2);
            // var startDate = new_year + '-' + mon + '-' + startDateDay;
            // var endDate = new_year + '-' + mon + '-' + lastDay; 
            var url = "/api/PersonnelModule/AiPerformanceAnalysis_AirTicket?userId="+val.id+"&start="+this.datetime(this.months[0])+"&end="+this.datetime(this.months[1])+"&createUserId="+this.userId
            var that = this
            this.$axios({
                method: 'get',
                url: url,
                headers: {
                    Authorization: 'Bearer '
                }
            }).then(function (res) {
                if(res.data.code==200){
                    that.performanLoading=false;
                    that.AIVisible=true;
                    if (that.$marked && typeof that.$marked === 'function') {
                        that.marktext = that.$marked(res.data.data.answer+that.texehr);
                        that.marktexts = that.$marked(res.data.data.kaoqinAnswer);
                    }
                    that.AiPerformanceAnalysis_UserList();
                }else{
                    that.performanLoading=false;
                    that.$message.error('AI绩效分析生成失败，请稍后重试！');
                }
            })
        },
        //生成酒店绩效
        AiPerformanceAnalysis_Hotel(val){
            //下面是整月逻辑
            // var new_year = this.months.getFullYear()
            // var month = this.months.getMonth();
            // var new_month = month + 1;
            // var firstDay = new Date(new_year, new_month - 1, 1); 
            // var lastDay = new Date(new_year, new_month, 0).getDate();
            // var mon = (new_month < 10 ? '0' : '') + new_month;
            // var startDateDay = ('0' + firstDay.getDate()).slice(-2);
            // var startDate = new_year + '-' + mon + '-' + startDateDay;
            // var endDate = new_year + '-' + mon + '-' + lastDay; 
            var url = "/api/PersonnelModule/AiPerformanceAnalysis_Hotel?userId="+val.id+"&start="+this.datetime(this.months[0])+"&end="+this.datetime(this.months[1])+"&createUserId="+this.userId
            var that = this
            this.$axios({
                method: 'get',
                url: url,
                headers: {
                    Authorization: 'Bearer '
                }
            }).then(function (res) {
                if(res.data.code==200){
                    that.performanLoading=false;
                    that.AIVisible=true;
                    if (that.$marked && typeof that.$marked === 'function') {
                        that.marktext = that.$marked(res.data.data.answer+that.texehr);
                        that.marktexts = that.$marked(res.data.data.kaoqinAnswer);
                    }
                    that.AiPerformanceAnalysis_UserList();
                }else{
                    that.performanLoading=false;
                    that.$message.error('AI绩效分析生成失败，请稍后重试！');
                }
            })
        },
        //生成签证绩效
        AiPerformanceAnalysis_Visa(val){
            //下面是整月逻辑
            // var new_year = this.months.getFullYear()
            // var month = this.months.getMonth();
            // var new_month = month + 1;
            // var firstDay = new Date(new_year, new_month - 1, 1); 
            // var lastDay = new Date(new_year, new_month, 0).getDate();
            // var mon = (new_month < 10 ? '0' : '') + new_month;
            // var startDateDay = ('0' + firstDay.getDate()).slice(-2);
            // var startDate = new_year + '-' + mon + '-' + startDateDay;
            // var endDate = new_year + '-' + mon + '-' + lastDay; 
            var url = "/api/PersonnelModule/AiPerformanceAnalysis_Visa?userId="+val.id+"&start="+this.datetime(this.months[0])+"&end="+this.datetime(this.months[1])+"&createUserId="+this.userId
            var that = this
            this.$axios({
                method: 'get',
                url: url,
                headers: {
                    Authorization: 'Bearer '
                }
            }).then(function (res) {
                if(res.data.code==200){
                    that.performanLoading=false;
                    that.AIVisible=true;
                    if (that.$marked && typeof that.$marked === 'function') {
                        that.marktext = that.$marked(res.data.data.answer+that.texehr);
                        that.marktexts = that.$marked(res.data.data.kaoqinAnswer);
                    }
                    that.AiPerformanceAnalysis_UserList();
                }else{
                    that.performanLoading=false;
                    that.$message.error('AI绩效分析生成失败，请稍后重试！');
                }
            })
        },
        //生成OP绩效
        AiPerformanceAnalysis_OP(val){
            //下面是整月逻辑
            // var new_year = this.months.getFullYear()
            // var month = this.months.getMonth();
            // var new_month = month + 1;
            // var firstDay = new Date(new_year, new_month - 1, 1); 
            // var lastDay = new Date(new_year, new_month, 0).getDate();
            // var mon = (new_month < 10 ? '0' : '') + new_month;
            // var startDateDay = ('0' + firstDay.getDate()).slice(-2);
            // var startDate = new_year + '-' + mon + '-' + startDateDay;
            // var endDate = new_year + '-' + mon + '-' + lastDay; 
            var url = "/api/PersonnelModule/AiPerformanceAnalysis_OP?userId="+val.id+"&start="+this.datetime(this.months[0])+"&end="+this.datetime(this.months[1])+"&createUserId="+this.userId
            var that = this
            this.$axios({
                method: 'get',
                url: url,
                headers: {
                    Authorization: 'Bearer '
                }
            }).then(function (res) {
                if(res.data.code==200){
                    that.performanLoading=false;
                    that.AIVisible=true;
                    if (that.$marked && typeof that.$marked === 'function') {
                        that.marktext = that.$marked(res.data.data.answer+that.texehr);
                        that.marktexts = that.$marked(res.data.data.kaoqinAnswer);
                    }
                    that.AiPerformanceAnalysis_UserList();
                }else{
                    that.performanLoading=false;
                    that.$message.error('AI绩效分析生成失败，请稍后重试！');
                }
            })
        },
         //生成信息部绩效
        AiPerformanceAnalysis_InformationDepartment(val){
            var url = "/api/PersonnelModule/AiPerformanceAnalysis_InformationDepartment?userId="+val.id+"&start="+this.datetime(this.months[0])+"&end="+this.datetime(this.months[1])+"&createUserId="+this.userId
            var that = this
            this.$axios({
                method: 'get',
                url: url,
                headers: {
                    Authorization: 'Bearer '
                }
            }).then(function (res) {
                if(res.data.code==200){
                    that.performanLoading=false;
                    that.AIVisible=true;
                    if (that.$marked && typeof that.$marked === 'function') {
                        that.marktext = that.$marked(res.data.data.answer+that.texehr);
                        that.marktexts = that.$marked(res.data.data.kaoqinAnswer);
                    }
                    that.AiPerformanceAnalysis_UserList();
                }else{
                    that.performanLoading=false;
                    that.$message.error('AI绩效分析生成失败，请稍后重试！');
                }
            })
        },
        //生成市场部绩效
        MarketingDepartment(val,text){
            var new_year = this.months[0].getFullYear()
            var month = this.months[0].getMonth();
            var new_month = month + 1;
            var firstDay = new Date(new_year, new_month - 1, 1); 
            var lastDay = new Date(new_year, new_month, 0).getDate();
            var mon = (new_month < 10 ? '0' : '') + new_month;
            var startDateDay = ('0' + firstDay.getDate()).slice(-2);
            // var startDate = new_year + '-' + mon + '-' + startDateDay;
            // var endDate = new_year + '-' + mon + '-' + lastDay; 
            var startDate = new_year + '-01-01';
            var endDate = new_year + '-12-31'; 
            var url = "/api/PersonnelModule/AiPerformanceAnalysis_GroupStatistics?userId="+val.id+"&start="+startDate+"&end="+endDate
            var that = this
            this.$axios({
                method: 'get',
                url: url,
                headers: {
                    Authorization: 'Bearer '
                }
            }).then(function (res) {
                that.SCgridData=[];
                if(res.data.code==200){
                    that.SCgridData=res.data.data;
                    if (val.depName == '市场部') {
                        if(text=='查看'){
                            if (val.hasPerformanceData==false) {
                                that.performanLoading=false;
                                that.$message.error('该用户尚未生成AI绩效分析，请先生成！');
                                return
                            }
                            that.AiPerformanceAnalysis_Query(val)
                        }else{
                            that.AiPerformanceAnalysis_JobMarketing(val);
                        }
                    } else {
                        that.performanLoading=false;
                        that.$message.error('当前仅支持市场部员工生成AI分析，其他部门正在开发中！');
                        return
                    }
                }else{
                    that.performanLoading=false;
                    that.$message.error(res.data.msg);
                }
            })
        },
        //获取chutuan
        AiPerformanceAnalysis_GroupStatistics(val,text){
            this.bumensb=val.depName;
            if(this.months==''){
                this.$message.error('请选择月份！');
                return
            }
            if (val.depName=='市场部') {
                this.performanLoading=true;
                this.MarketingDepartment(val,text);
                return
            }
            if (val.jobName=='机票') {
                this.performanLoading=true;
                if(text=='查看'){
                    if (val.hasPerformanceData==false) {
                        this.performanLoading=false;
                        this.$message.error('该用户尚未生成AI绩效分析，请先生成！');
                        return
                    }
                    this.AiPerformanceAnalysis_Query(val)
                }else{
                    this.AiPerformanceAnalysis_AirTicket(val);
                }
                return
            }
            if (val.jobName=='酒店') {
                this.performanLoading=true;
                if(text=='查看'){
                    if (val.hasPerformanceData==false) {
                        this.performanLoading=false;
                        this.$message.error('该用户尚未生成AI绩效分析，请先生成！');
                        return
                    }
                    this.AiPerformanceAnalysis_Query(val)
                }else{
                    this.AiPerformanceAnalysis_Hotel(val);
                }
                return
            }
            if (val.jobName=='签证') {
                this.performanLoading=true;
                if(text=='查看'){
                    if (val.hasPerformanceData==false) {
                        this.performanLoading=false;
                        this.$message.error('该用户尚未生成AI绩效分析，请先生成！');
                        return
                    }
                    this.AiPerformanceAnalysis_Query(val)
                }else{
                    this.AiPerformanceAnalysis_Visa(val);
                }
                return
            }
            if (val.jobName=='OP') {
                this.performanLoading=true;
                if(text=='查看'){
                    if (val.hasPerformanceData==false) {
                        this.performanLoading=false;
                        this.$message.error('该用户尚未生成AI绩效分析，请先生成！');
                        return
                    }
                    this.AiPerformanceAnalysis_Query(val)
                }else{
                    this.AiPerformanceAnalysis_OP(val);
                }
                return
            }
            if (val.depName=='信息部') {
                this.performanLoading=true;
                if(text=='查看'){
                    if (val.hasPerformanceData==false) {
                        this.performanLoading=false;
                        this.$message.error('该用户尚未生成AI绩效分析，请先生成！');
                        return
                    }
                    this.AiPerformanceAnalysis_Query(val)
                }else{
                    this.AiPerformanceAnalysis_InformationDepartment(val);
                }
                return
            }
            this.$message.error('正在开发中！');
        },
        async exportToPDF() {
            try {
                const element = document.getElementById('pdfDom');
                const canvas = await html2canvas(element, {
                    useCORS: true,
                    scale: 4,
                    // 可以尝试设置宽度和高度，确保捕获全部内容
                    width: element.scrollWidth,
                    height: element.scrollHeight
                });

                const imgData = canvas.toDataURL('image/jpeg', 1.0);
                const pdf = new jsPDF('p', 'mm', 'a4');
                const pageWidth = pdf.internal.pageSize.getWidth();
                const pageHeight = pdf.internal.pageSize.getHeight();

                const imgWidth = pageWidth;
                const imgHeight = (canvas.height * imgWidth) / canvas.width;

                // 计算需要多少页
                const totalPages = Math.ceil(imgHeight / pageHeight);

                // 第一页
                pdf.addImage(imgData, 'JPEG', 0, 0, imgWidth, imgHeight);

                // 如果需要多页
                for (let i = 1; i < totalPages; i++) {
                    pdf.addPage();
                    // 计算每一页的y坐标（负值表示向上移动）
                    const yPosition = -(i * pageHeight);
                    pdf.addImage(imgData, 'JPEG', 0, yPosition, imgWidth, imgHeight);
                }

                pdf.save('导出的页面.pdf');
            } catch (error) {
                console.error('生成PDF失败:', error);
            }
        }
    },
    mounted(){
        this.months=new Date();
        this.userId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId;
        // this.AiPerformanceAnalysis_UserList();
    }
}
</script>
<style>
    /* 确保PDF内容区域样式正确 */
    #pdfDom {
        box-sizing: border-box;
        width: 100%;
        background: white;
        padding: 20px;
    }

    /* 避免使用可能导致截断的样式 */
    #pdfDom * {
        box-sizing: border-box;
        page-break-inside: avoid;
    }

    /* 确保文本不会超出容器 */
    #pdfDom p,
    #pdfDom div,
    #pdfDom span {
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    /* 表格样式优化 */
    #pdfDom table {
        width: 100%;
        border-collapse: collapse;
    }

    #pdfDom td,
    #pdfDom th {
        padding: 8px;
        border: 1px solid #ddd;
    }

    .performanceanalysis-all{
        background-color: #fff;
        padding: 10px;
        box-shadow: 0 0 5px #0005;
        border-radius: 10px;
        min-height: 800px;
    }
    .performanceanalysis-all .markdownyangshi{
        font-size:12px ;
    }
    .performanceanalysis-haed{
        display: flex;
        align-items: center;
    }
    .performanceanalysis-haed-li{
        margin-right: 10px;
        display: flex;
        align-items: center;
    }
    .performanceanalysis-haed-li label{
        margin-right: 5px;
    }
    .performanceanalysis-haed .el-range-editor.el-input__inner{
        margin-bottom: 0;
    }
    .performanceanalysis-table{
        margin-top: 20px;
    }
    .performanceanalysis-table .block{
        text-align: center;
        margin-top: 15px;
    }
</style>