<template>
    <div class="PerformanceT-all">
        <el-dialog width="830px" class="settings-dialog" title="设置" :visible.sync="dialogTableVisible" :close-on-click-modal="false">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                <div class="settings-form">
                    <!-- <el-form-item label="考核项目">
                        <el-select value-key="id" @change="itemchange" v-model="ruleForm.id" placeholder="请选择活动区域">
                            <el-option v-for="(item,index) in tablelist" :key="index" :label="item.name" :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="考核细则">
                        <el-select v-model="ruleForm.parentId" placeholder="请选择活动区域">
                            <el-option v-for="(item,index) in Assessmentrules" :key="index" :label="item.name" :value="item.id"></el-option>
                        </el-select>
                    </el-form-item> -->
                    <el-form-item label="上级菜单">
                        <el-select filterable clearable v-model="ruleForm.parentId" placeholder="请选择上级菜单">
                            <el-option v-for="(item,index) in parentmenuarr" :key="index" :label="item.name"
                                :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="名称" prop="name">
                        <el-input v-model="ruleForm.name"></el-input>
                    </el-form-item>
                    <el-form-item label="评估比例" prop="assessmentProportion">
                        <el-input v-model="ruleForm.assessmentProportion"></el-input>
                    </el-form-item>
                    <el-form-item style="width:100%;" label="评估标准">
                        <el-input type="textarea" :rows="6" v-model="ruleForm.assessmentStandard"></el-input>
                    </el-form-item>
                    <el-form-item style="width:100%;" label="备注">
                        <el-input type="textarea" :rows="2" v-model="ruleForm.remark"></el-input>
                    </el-form-item>
                </div>
                <!-- <el-form-item label="关键绩效指标(KPI)">
                    <el-select v-model="ruleForm.parentId" placeholder="请选择活动区域">
                        <el-option v-for="(item,index) in Assessmentrules" :key="index" :label="item.name" :value="item.id"></el-option>
                    </el-select>
                </el-form-item> -->
                <el-form-item style="text-align: right;width:100%;">
                    <el-button type="primary" @click="submitForm('ruleForm')">立即设置</el-button>
                    <el-button @click="resetForm('ruleForm')">重置</el-button>
                    <el-button @click="dialogTableVisible=false">取消</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
        <el-dialog width="830px" class="allocation-dialog" title="分配设置" :visible.sync="allocationVisible" :close-on-click-modal="false">
            <el-form :model="allocationArgument" :rules="allocationrules" ref="allocationArgument" label-width="100px"
                class="demo-ruleForm">
                <div class="allocation-form">
                    <el-form-item prop="assessmentSettingId" label="分配菜单">
                        <el-select filterable clearable @change="caidanchange" v-model="allocationArgument.assessmentSettingId"
                            placeholder="请选择分配菜单">
                            <el-option v-for="(item,index) in parentmenuarr" :key="index" :label="item.name"
                                :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="占比" prop="assessmentProportionChi">
                        <el-input v-model="allocationArgument.assessmentProportionChi"></el-input>
                    </el-form-item>
                    <el-form-item label="目标值" prop="targetValue">
                        <el-input v-model="allocationArgument.targetValue"></el-input>
                    </el-form-item>
                    <el-form-item prop="fixed" label="是否固定">
                        <el-radio-group v-model="allocationArgument.fixed">
                            <el-radio label="是"></el-radio>
                            <el-radio label="否"></el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item label="所属公司" prop="Corporation">
                        <el-select v-model="allocationArgument.Corporation" value-key="id" @change="changeCorporation"
                            placeholder="请选择所属公司">
                            <el-option v-for="item in CorporationOption" :key="item.companyId" :label="item.companyName"
                                :value="item.companyId">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="所属部门" prop="Division">
                        <el-select v-model="allocationArgument.Division" value-key="id" @change="changeDivision"
                            placeholder="请选择所属部门">
                            <el-option v-for="item in DivisionOption" :key="item.depId" :label="item.depName"
                                :value="item.depId">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="职位" prop="jobId">
                        <el-select @change="QueryUserList" v-model="allocationArgument.jobId" placeholder="请选择职位">
                            <el-option v-for="item in PostsOption" :key="item.jobId" :label="item.jobName"
                                :value="item.jobId">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="人员" prop="userId">
                        <el-select v-model="allocationArgument.userId" placeholder="请选择职位">
                            <el-option v-for="item in userinfoarr" :key="item.id" :label="item.cnName" :value="item.id">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <!-- <el-form-item prop="assessmentStandard" style="width:100%;" label="评估标准">
                        <el-input type="textarea" :rows="2" v-model="allocationArgument.assessmentStandard"></el-input>
                    </el-form-item> -->
                    <el-form-item style="width:100%;" label="备注">
                        <el-input type="textarea" :rows="2" v-model="allocationArgument.remark"></el-input>
                    </el-form-item>
                </div>
                <el-form-item style="text-align: right;width:100%;">
                    <el-button type="primary" @click="submitFormallocation('allocationArgument')">立即分配</el-button>
                    <el-button @click="resetFormallocation('allocationArgument')">重置</el-button>
                    <el-button @click="allocationVisible=false">取消</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
        <el-dialog width="400px" class="allocation-dialog" title="删除设置项" :visible.sync="deleteVisible" :close-on-click-modal="false">
            <div class="deleteXM">
                <label>项目名称:</label>
                <el-select filterable clearable v-model="deleteXMid"
                    placeholder="请选择项目名称">
                    <el-option v-for="(item,index) in parentmenuarr" :key="index" :label="item.name"
                        :value="item.id"></el-option>
                </el-select>
            </div>
            <div style="text-align: right;margin-top: 20px;">
                <el-button size="mini" @click="deleteXMbtn" type="danger">删除</el-button>
                <el-button size="mini" @click="deleteVisible=false">取消</el-button>
            </div>
        </el-dialog>
        <div class="PerformanceT-hade">
            <div>
                <el-select @change="userchange" style="width:200px;" v-model="value" filterable placeholder="请选择">
                    <el-option v-for="item in options" :key="item.id" :label="item.cnName" :value="item.id">
                    </el-option>
                </el-select>
                <el-date-picker
                v-model="monthdate"
                type="month"
                style="width:200px;"
                placeholder="选择月">
                </el-date-picker>
            </div>
            <div>
                <el-button @click="ondialog" type="primary">设 置</el-button>
                <el-button @click="dlexmclick" type="primary">删除设置项</el-button>
                <el-button @click="onallocation" type="primary">分配绩效</el-button>
                <el-button @click="saveclick" type="primary">保 存</el-button>
            </div>
        </div>
        <div class="PerformanceT-title">
            <div :style="title.width" v-for="(title,indext) in tabletitle" :key="indext">
                {{ title.name }}
            </div>
        </div>
        <div class="pf-table">
            <div class="PerformanceT-table-box" :ref="'tbox'+indexs" v-for="(tables,indexs) in tablelist" :key="indexs">
                <div @click="itemclick(tables)" style="width:90px;text-align: center;">
                    <div>{{tables.name}}</div>
                    <div>{{'('+tables.assessmentProportion_Percentage+'%)'}}</div>
                </div>
                <div class="calibrate-box">
                    <div class="second-box" v-for="(item,indexss) in tables.children" :key="indexss">
                        <div style="display: -webkit-box;">
                            <div @click="itemclick(item)" class="pf-onename">
                                <div>{{item.name}}</div>
                                <div>{{'('+item.assessmentProportion_Percentage+'%)'}}</div>
                            </div>
                            <div class="calibrate-box">
                                <div class="pf-twoname" v-for="(itemchildren,indexsss) in item.children"
                                    :key="indexsss">
                                    <div @click="itemclick(itemchildren)" style="width: 150px;border-right: 1px solid #ebeef5;">
                                        <div>{{itemchildren.name}}</div>
                                        <div>{{'('+itemchildren.assessmentProportion_Percentage+'%)'}}</div>
                                    </div>
                                    <div @click="goalclick(itemchildren)" class="pf-zb">{{ itemchildren.assessmentProportionChi*100+"%" }}</div>
                                    <div @click="goalclick(itemchildren)" style="width: 100px;border-right: 1px solid #ebeef5;">
                                        {{itemchildren.targetValue}}</div>
                                    <div @click="itemclick(itemchildren)" style="width: 380px;padding: 10px;border-right: 1px solid #ebeef5;">{{
                                        itemchildren.assessmentStandard }}</div>
                                    <div style="width: 250px;border-right: 1px solid #ebeef5;">
                                        <el-input style="width:98%" type="textarea" :rows="4" placeholder="请输入内容" v-model="itemchildren.status">
                                        </el-input>
                                    </div>
                                    <div style="width: 80px;border-right: 1px solid #ebeef5;">
                                        <el-input-number  style="width: 50px;" size="mini" :controls="false"
                                            v-model="itemchildren.selfAssessment"></el-input-number>
                                    </div>
                                    <div style="width: 80px;border-right: 1px solid #ebeef5;">
                                        <el-input-number :disabled="!isLeader" style="width: 50px;" size="mini" :controls="false"
                                            v-model="itemchildren.higherUpAssessment"></el-input-number>
                                    </div>
                                    <div style="width: 80px;border-right: 1px solid #ebeef5;">
                                        <el-input-number disabled style="width: 50px;" size="mini" :controls="false"
                                            v-model="itemchildren.score"></el-input-number>
                                    </div>
                                    <div style="width: 80px;border-right: 1px solid #ebeef5;">
                                        <el-input-number disabled style="width: 50px;" size="mini" :controls="false"
                                            v-model="itemchildren.scoreTotal"></el-input-number>
                                    </div>
                                    <div style="width: 74px;">
                                        <el-button @click="deletecontent(itemchildren)" size="mini" icon="el-icon-delete" type="danger"></el-button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
export default {
    data() {
        return {
            CorporationOption:[],//公司
            DivisionOption:[],//部门
            PostsOption:[],//职位
            token:'',
            monthdate:'',
            userId:'',
            isLeader:false,//是否为上级
            tablelist:[],
            tabletitle:[
                {
                    width:'width:90px',
                    name:'考核项目'
                },
                {
                    width:'width:150px',
                    name:'考核细则'
                },
                {
                    width:'width:150px',
                    name:'关键绩效指标(KPI)'
                },
                {
                    width:'width:50px',
                    name:'占比'
                },
                {
                    width:'width:100px',
                    name:'目标值'
                },
                {
                    width:'width:400px',
                    name:'评价标准'
                },
                {
                    width:'width:250px',
                    name:'达成情况'
                },
                {
                    width:'width:80px',
                    name:'自评'
                },
                {
                    width:'width:80px',
                    name:'上级评分'
                },
                {
                    width:'width:80px',
                    name:'该项得分'
                },
                {
                    width:'width:80px',
                    name:'绩效分'
                },
                {
                    width:'width:74px',
                    name:'操作'
                },
            ],
            tboxheight:0,
            immobilizationarr:[
                {
                    id: 788,
                    name: "行为管理",
                    assessmentProportion: 0.4,
                    assessmentStandard: "",
                    parentId: 0,
                    assessmentSettingId: 0,
                    assessmentProportionChi: 0,
                    targetValue: "",
                    jobId: 0,
                    userId: 0,
                    fixed: 0,
                    children: [
                        {
                            id: 2,
                            name: "考勤管理",
                            assessmentProportion: 0.6,
                            assessmentStandard: "",
                            parentId: 1,
                            assessmentSettingId: 0,
                            assessmentProportionChi: 0,
                            targetValue: "",
                            jobId: 0,
                            userId: 0,
                            fixed: 0,
                            children: [
                                {
                                    id: 3,
                                    name: "出勤及请假",
                                    assessmentProportion: 1,
                                    assessmentStandard: "出勤情况：迟到、事假、年假，调休，请假类型和天数扣分①【90-100】优秀：每月迟到次数为0；调休不超过1天；请假为0；年假为0。②【80-89】良好：每月迟到次数不超过1次，且迟到时间不超过5分钟；调休不超过2天；请假不超过1天；年假为0。③【60-79】一般：每月迟到次数不超过3次，每次迟到时间不超过10分钟。调休不超过3天；请假不超过2天；年假为1。④【0-59】较差：每月迟到次数超过3次，或有单次迟到时间超过30分钟。调休超过5天；请假超过3天；年假超过2天。",
                                    parentId: 2,
                                    assessmentSettingId: 3,
                                    assessmentProportionChi: 1,
                                    targetValue: "50万",
                                    jobId: 21,
                                    userId: 302,
                                    fixed: 0,
                                    children: [
                                    ],
                                    assessmentProportion_Percentage: 100,
                                    yearMonth: "2024-10-17 00:00:00",
                                    status: 1,
                                    selfAssessment: 95,
                                    higherUpAssessment: 95,
                                    score: 0,
                                    scoreTotal: 0,
                                    higherUpConfig: 0,
                                    higherUpUserId: 235
                                },
                            ],
                            assessmentProportion_Percentage: 60,
                            yearMonth: "0001-01-01 00:00:00",
                            status: 0,
                            selfAssessment: 0,
                            higherUpAssessment: 0,
                            score: 0,
                            scoreTotal: 0,
                            higherUpConfig: 0,
                            higherUpUserId: 0
                        },
                        {
                            id: 8,
                            name: "仪容仪表",
                            assessmentProportion: 0.2,
                            assessmentStandard: "",
                            parentId: 1,
                            assessmentSettingId: 0,
                            assessmentProportionChi: 0,
                            targetValue: "",
                            jobId: 0,
                            userId: 0,
                            fixed: 0,
                            children: [
                                {
                                    id: 9,
                                    name: "装容及着装",
                                    assessmentProportion: 1,
                                    assessmentStandard: "①【90-100】优秀：每天保持装容、着装职业装或工装每天坚持为优秀。②【80-89】良好：月度出现4次内的，未保持装容、未着装职业装或工装。③【60-79】一般：月度出现5次以上的，未保持装容、未着装职业装或工装。④【0-59】较差：月度出现5次以下的，未保持装容、未着装职业装或工装。",
                                    parentId: 8,
                                    assessmentSettingId: 9,
                                    assessmentProportionChi: 0.2,
                                    targetValue: "10人",
                                    jobId: 21,
                                    userId: 302,
                                    fixed: 0,
                                    children: [

                                    ],
                                    assessmentProportion_Percentage: 100,
                                    yearMonth: "0001-01-01 00:00:00",
                                    status: 0,
                                    selfAssessment: 0,
                                    higherUpAssessment: 0,
                                    score: 0,
                                    scoreTotal: 0,
                                    higherUpConfig: 0,
                                    higherUpUserId: 0
                                }
                            ],
                            assessmentProportion_Percentage: 20,
                            yearMonth: "0001-01-01 00:00:00",
                            status: 0,
                            selfAssessment: 0,
                            higherUpAssessment: 0,
                            score: 0,
                            scoreTotal: 0,
                            higherUpConfig: 0,
                            higherUpUserId: 0
                        },
                        {
                            id: 9,
                            name: "工作失误",
                            assessmentProportion: 0.2,
                            assessmentStandard: "",
                            parentId: 1,
                            assessmentSettingId: 0,
                            assessmentProportionChi: 0,
                            targetValue: "",
                            jobId: 0,
                            userId: 0,
                            fixed: 0,
                            children: [
                                {
                                    id: 9,
                                    name: "日常工作失误",
                                    assessmentProportion: 1,
                                    assessmentStandard: "①错误次数：文件错误、操作失误等,每次错误根据严重程度扣分，重复错误加倍扣分（10-100分）②错误影响：对项目、团队、客户的影响，根据影响范围和程度扣分，重大失误额外扣分（0-100分）③改进措施：错误后的补救和预防措施，采取有效措施得部分分数，无改进或效果不佳扣分（0-100分）",
                                    parentId: 8,
                                    assessmentSettingId: 9,
                                    assessmentProportionChi: 0.2,
                                    targetValue: "10人",
                                    jobId: 21,
                                    userId: 302,
                                    fixed: 0,
                                    children: [

                                    ],
                                    assessmentProportion_Percentage: 100,
                                    yearMonth: "0001-01-01 00:00:00",
                                    status: 0,
                                    selfAssessment: 0,
                                    higherUpAssessment: 0,
                                    score: 0,
                                    scoreTotal: 0,
                                    higherUpConfig: 0,
                                    higherUpUserId: 0
                                }
                            ],
                            assessmentProportion_Percentage: 20,
                            yearMonth: "0001-01-01 00:00:00",
                            status: 0,
                            selfAssessment: 0,
                            higherUpAssessment: 0,
                            score: 0,
                            scoreTotal: 0,
                            higherUpConfig: 0,
                            higherUpUserId: 0
                        }
                    ],
                    assessmentProportion_Percentage: 40,
                    yearMonth: "0001-01-01 00:00:00",
                    status: 0,
                    selfAssessment: 0,
                    higherUpAssessment: 0,
                    score: 0,
                    scoreTotal: 0,
                    higherUpConfig: 0,
                    higherUpUserId: 0
                },
                {
                    id: 666,
                    name: "工作态度",
                    assessmentProportion: 0.4,
                    assessmentStandard: "",
                    parentId: 0,
                    assessmentSettingId: 0,
                    assessmentProportionChi: 0,
                    targetValue: "",
                    jobId: 0,
                    userId: 0,
                    fixed: 0,
                    children: [
                        {
                            id: 2,
                            name: "工作态度",
                            assessmentProportion: 0.6,
                            assessmentStandard: "",
                            parentId: 1,
                            assessmentSettingId: 0,
                            assessmentProportionChi: 0,
                            targetValue: "",
                            jobId: 0,
                            userId: 0,
                            fixed: 0,
                            children: [
                                {
                                    id: 3,
                                    name: "主动性及责任心",
                                    assessmentProportion: 1,
                                    assessmentStandard: "①【101-120】表现出高度的主动性和责任感，能够自发规划并优秀地完成工作；愿意承担并成功处理紧急和重要的任务。②【80-100】积极主动，按时完成分配任务，不推卸责任；愿意接受临时紧急任务，对自己的职责负责。③【60-79】工作不够主动，常拖延且有时推卸任务，需频繁督导，偶尔未能按时完成工作。仅限于工作时间履行职责，对紧急和临时任务常找借口回避。④【0-59】工作态度消极，频繁怠工，即使多次督促也未能按时完成工作，且常有逃避任务和推卸责任的行为",
                                    parentId: 2,
                                    assessmentSettingId: 3,
                                    assessmentProportionChi: 1,
                                    targetValue: "50万",
                                    jobId: 21,
                                    userId: 302,
                                    fixed: 0,
                                    children: [
                                    ],
                                    assessmentProportion_Percentage: 100,
                                    yearMonth: "2024-10-17 00:00:00",
                                    status: 1,
                                    selfAssessment: 95,
                                    higherUpAssessment: 95,
                                    score: 0,
                                    scoreTotal: 0,
                                    higherUpConfig: 0,
                                    higherUpUserId: 235
                                },
                                {
                                    id: 3,
                                    name: "团队合作及精神面貌",
                                    assessmentProportion: 1,
                                    assessmentStandard: "①【101-120】积极协助同事，乐于助人且不影响个人工作；日常表现充满活力和热情，传递正能量；严格遵守公司规章制度，是同事的榜样。②【80-100】与团队合作融洽，愿意帮助他人；态度积极，对工作和客户保持正面态度；遵守公司规定，表现合规。③【60-79】在他人请求帮助时愿意提供有限协助；整体精神面貌和着装符合要求，偶尔会有抱怨，但经提醒能迅速调整；有时会离开工位，但提醒后能迅速回到岗位。④【0-59】仅专注于个人任务，不愿与同事和客户沟通，拒绝帮助他人。工作态度消极，缺乏热情，常散发负能量，频繁离岗，对团队产生负面影响，即使被提醒也未能有效改善。",
                                    parentId: 2,
                                    assessmentSettingId: 3,
                                    assessmentProportionChi: 1,
                                    targetValue: "50万",
                                    jobId: 21,
                                    userId: 302,
                                    fixed: 0,
                                    children: [
                                    ],
                                    assessmentProportion_Percentage: 100,
                                    yearMonth: "2024-10-17 00:00:00",
                                    status: 1,
                                    selfAssessment: 95,
                                    higherUpAssessment: 95,
                                    score: 0,
                                    scoreTotal: 0,
                                    higherUpConfig: 0,
                                    higherUpUserId: 235
                                },
                            ],
                            assessmentProportion_Percentage: 60,
                            yearMonth: "0001-01-01 00:00:00",
                            status: 0,
                            selfAssessment: 0,
                            higherUpAssessment: 0,
                            score: 0,
                            scoreTotal: 0,
                            higherUpConfig: 0,
                            higherUpUserId: 0
                        }
                    ],
                    assessmentProportion_Percentage: 40,
                    yearMonth: "0001-01-01 00:00:00",
                    status: 0,
                    selfAssessment: 0,
                    higherUpAssessment: 0,
                    score: 0,
                    scoreTotal: 0,
                    higherUpConfig: 0,
                    higherUpUserId: 0
                },
            ],

            deleteVisible:false,
            userinfoarr:[],
            options: [],
            value: '',
            dialogTableVisible:false,
            allocationVisible:false,
            Assessmentrules:[],
            parentmenuarr:[],
            ruleForm: {
                name: '',
                assessmentProportion: '',
                assessmentStandard: '',
                parentId: '',
                parentmenu:'',
                id:'',
                createId: '',
                remark: '',
            },
            //分配参数
            allocationArgument:{
                id:'',
                Corporation:'',
                Division:'',
                createUserId:'',
                assessmentSettingId:'',
                assessmentProportionChi:'',//占比
                targetValue:'',//目标值
                jobId:'',//岗位id
                userId:'',//员工id
                fixed:'',//固定标识 (1 是固定 2 是灵活)
                remark:'',//备注
            },
            deleteXMid:'',
            rules: {
                name: [
                    { required: true, message: '请输入', trigger: 'blur' },
                ],
                assessmentProportion: [
                    { required: true, message: '请输入', trigger: 'blur' }
                ],
            },
            allocationrules:{
                assessmentSettingId: [
                    { required: true, message: '请选择', trigger: 'change' }
                ],
                assessmentProportionChi: [
                    { required: true, message: '请输入', trigger: 'blur' }
                ],
                targetValue: [
                    { required: true, message: '请输入', trigger: 'blur' }
                ],
                Corporation: [
                    { required: true, message: '请选择', trigger: 'change' }
                ],
                Division: [
                    { required: true, message: '请选择', trigger: 'change' }
                ],
                jobId: [
                    { required: true, message: '请选择', trigger: 'change' }
                ],
                userId: [
                    { required: true, message: '请选择', trigger: 'change' }
                ],
                fixed: [
                    { required: true, message: '请选择', trigger: 'change' }
                ],
                assessmentStandard: [
                    { required: true, message: '请填写', trigger: 'blur' }
                ],
            }
        }
    },
    methods:{
        //处理日期
        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
        },
        //获取公司
        daraSource(){
            var url = "/api/register/daraSource"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                }
            }).then(function (res) {
                if(res.data.code==200){
                    that.CorporationOption=res.data.data;
                }else{
                    that.$message({
                        message: '加载失败！原因：'+res.data.msg,
                        type: 'warning'
                    });
                }
            })
        },
        dlexmclick(){
            this.deleteXMid='';
            this.deleteVisible=true;
        },
        deleteXMbtn(){
            this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.DeleteAssessmentSetting(this.deleteXMid)
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '操作已取消！'
                });
            });
        },
        deletecontent(val){
            this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.DeleteAssessmentContentSetting(val.contentId)
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '操作已取消！'
                });
            });
        },
        //删除内容
        DeleteAssessmentContentSetting(val){
            var url = "/api/PersonnelModule/DeleteAssessmentContentSetting"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer '
                },
                data:{
                    idArr:[val],
                    userId:that.userId
                }
            }).then(function (res) {
                if(res.data.code==200){
                    that.$message({
                        type: 'success',
                        message: res.data.msg
                    });
                    that.GetPerformanceList();
                }else{
                    that.$message({
                        message: '加载失败！原因：'+res.data.msg,
                        type: 'warning'
                    });
                }
            })
        },
        //删除项
        DeleteAssessmentSetting(val){
            var url = "/api/PersonnelModule/DeleteAssessmentSetting"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer '
                },
                data:{
                    idArr:[val],
                    userId:that.userId
                }
            }).then(function (res) {
                if(res.data.code==200){
                    that.deleteVisible=false;
                    that.$message({
                        type: 'success',
                        message: res.data.msg
                    });
                    that.QueryAssessmentSettingListOffset();
                }else{
                    that.deleteVisible=false;
                    that.$message({
                        message: '加载失败！原因：'+res.data.msg,
                        type: 'warning'
                    });
                }
            })
        },
        //获取员工
        QueryUserList(num){
            if (num!=0) {
                this.allocationArgument.userId = '';
            }
            var url = "/api/System/QueryUserList"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                },
                data:{
                    CompanyId:that.allocationArgument.Corporation,
                    DepId:that.allocationArgument.Division,
                    JobPostId:that.allocationArgument.jobId,
                    PortType:1,
                }
            }).then(function (res) {
                if(res.data.code==200){
                    that.userinfoarr=res.data.data;
                }else{
                    that.$message({
                        message: '加载失败！原因：'+res.data.msg,
                        type: 'warning'
                    });
                }
            })
        },
        //切换公司
        changeCorporation(item,num) {
            console.log(item);
            if (num!=0) {
                this.allocationArgument.Division = '';
                this.allocationArgument.jobId = '';
                this.allocationArgument.userId = '';
            }
            for (let i = 0; i < this.CorporationOption.length; i++) {
                if (this.CorporationOption[i].companyId == item) {
                    this.DivisionOption = this.CorporationOption[i].subDep
                }
            }
        },
        //切换部门
        changeDivision(item,num) {
            if (num!=0) {
                this.allocationArgument.jobId = '';
                this.allocationArgument.userId = '';
            }
            for (let j = 0; j < this.DivisionOption.length; j++) {
                if (this.DivisionOption[j].depId == item) {
                    this.PostsOption = this.DivisionOption[j].subJob
                }
            }
        },
        //项目名点击
        itemclick(val){
            console.log(val);
            this.dialogTableVisible=true;
            this.ruleForm.parentId=val.parentId==0?'':val.parentId;
            this.ruleForm.name=val.name;
            this.ruleForm.id=val.id;
            this.ruleForm.assessmentProportion=val.assessmentProportion;
            this.ruleForm.assessmentStandard=val.assessmentStandard;
            this.ruleForm.remark=val.assessmentStandard;
        },
        //细则名点击
        // thinclick(val){
        //     console.log(val);
        //     this.dialogTableVisible=true;
        //     this.ruleForm.parentId=val.parentId==0?'':val.parentId;
        //     this.ruleForm.name=val.name;
        //     this.ruleForm.id=val.id;
        //     this.ruleForm.assessmentProportion=val.assessmentProportion;
        //     this.ruleForm.assessmentStandard=val.assessmentStandard;
        //     this.ruleForm.remark=val.assessmentStandard;
        // },
        //细则名点击
        // KPIclick(val){
        //     console.log(val);
        //     this.dialogTableVisible=true;
        //     this.ruleForm.parentId=val.parentId==0?'':val.parentId;
        //     this.ruleForm.name=val.name;
        //     this.ruleForm.id=val.id;
        //     this.ruleForm.assessmentProportion=val.assessmentProportion;
        //     this.ruleForm.assessmentStandard=val.assessmentStandard;
        //     this.ruleForm.remark=val.assessmentStandard;
        // },
        //目标
        goalclick(val){
            console.log(val);
            
            this.onallocation()
            for (let b = 0; b < this.CorporationOption.length; b++) {
                for (let g = 0; g < this.CorporationOption[b].subDep.length; g++) {
                    for (let m = 0; m < this.CorporationOption[b].subDep[g].subJob.length; m++) {
                        if (val.jobId==this.CorporationOption[b].subDep[g].subJob[m].jobId) {
                            this.allocationArgument.Corporation=this.CorporationOption[b].companyId;
                            this.allocationArgument.Division=this.CorporationOption[b].subDep[g].depId;
                        }
                    }
                }
            }
           this.allocationArgument.id=val.contentId;
           this.allocationArgument.assessmentProportionChi=val.assessmentProportionChi;
           this.allocationArgument.assessmentSettingId=val.id;
           this.allocationArgument.targetValue=val.targetValue;
           this.allocationArgument.jobId=val.jobId;
           this.allocationArgument.userId=val.userId;
           this.allocationArgument.fixed=val.fixed==1?'是':'否';
           this.changeCorporation(this.allocationArgument.Corporation,0);
           this.changeDivision(this.allocationArgument.Division,0);
           this.QueryUserList(0);
        },
        //获取基础数据
        GetWageSheetBasicsDataSource(){
            var url = "/api/PersonnelModule/GetWageSheetBasicsDataSource"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer '
                },
            }).then(function (res) {
                if (res.data.code == 200) {
                    that.options=res.data.data.userNames;
                    that.value=that.options[0].id;
                    that.GetPerformanceList();
                } else {
                    that.$message.error(res.data.msg);
                }
            }).catch(function (error) {
                that.$message.error("出错！，请联系信息部。");
            });
        },
        //获取数据
        QueryAssessmentSettingListOffset(){
            var url = "/api/PersonnelModule/QueryAssessmentSettingListOffset"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer '
                },
                data:{
                    pageIndex:1,
                    pageSize:9999,
                    searchValue:'',
                }
            }).then(function (res) {
                if (res.data.code == 200) {
                    that.parentmenuarr=res.data.data.list;
                } else {
                    that.$message.error(res.data.msg);
                }
            }).catch(function (error) {
                that.$message.error("出错！，请联系信息部。");
            });
        },
        //获取数据
        GetPerformanceList(){
            var url = "/api/PersonnelModule/GetPerformanceList?userid="+this.value+"&date="+this.datetime(this.monthdate)+"&loginUser="+this.userId
            var that = this
            this.$axios({
                method: 'get',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                },
            }).then(function (res) {
                if (res.data.code == 200) {
                    that.tablelist=res.data.data.root;
                    that.isLeader=res.data.data.isLeader;
                    // for(let i=0;i<that.immobilizationarr.length;i++){
                    //     that.tablelist.push(that.immobilizationarr[i])
                    // }
                } else {
                    that.$message.error(res.data.msg);
                }
            }).catch(function (error) {
                that.$message.error("网络错误，请稍后重试");
            });
        },
        //人员切换
        userchange(){
            this.GetPerformanceList();
        },
        objectSpanMethod({ row, column, rowIndex, columnIndex }) {
            const fields = ['name']
            if (fields.includes(column.property)) {
                const cellValue = row['lngitemid']
                if (cellValue && fields.includes(column.property)) {
                const prevRow = this.tableData[rowIndex - 1]
                let nextRow = this.tableData[rowIndex + 1]
                if (prevRow && prevRow['lngitemid'] === cellValue) {
                    return { rowspan: 0, colspan: 0 }
                } else {
                    // return { rowspan: row.rowspan, colspan: 1 }
                    let countRowspan = 1
                    while (nextRow && nextRow['lngitemid'] === cellValue) {
                    nextRow = this.tableData[++countRowspan + rowIndex]
                    }
                    if (countRowspan > 1) {
                    return { rowspan: countRowspan, colspan: 1 }
                    }
                }
                }
            }
        },
        //获取赋值高
        getheight(){
            // this.tboxheight=this.$refs.tbox.offsetHeight+'px'
            let ref = this.$refs.tbox0
            console.log(ref);
            
        },
        //考核项目值改变
        itemchange(val){
            for(let i=0;i<this.tablelist.length;i++){
                if (this.tablelist[i].id==val) {
                    this.Assessmentrules=this.tablelist[i].children;
                }
            }
        },
        //新增项
        AssessmentSettingOperation(){
            var url = "/api/PersonnelModule/AssessmentSettingOperation"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer '
                },
                data:{
                    name:that.ruleForm.name,
                    assessmentProportion:that.ruleForm.assessmentProportion,
                    assessmentStandard:that.ruleForm.assessmentStandard,
                    parentId:that.ruleForm.parentId==''?0:that.ruleForm.parentId,
                    id:that.ruleForm.id==''?0:that.ruleForm.id,
                    createId:that.userId,
                    remark:that.ruleForm.remark,
                }
            }).then(function (res) {
                if (res.data.code == 200) {
                    that.dialogTableVisible=false;
                    that.$message({
                        type: 'success',
                        message: res.data.msg
                    });
                    if (that.ruleForm.id!=0) {
                        that.GetPerformanceList();
                    }
                    that.QueryAssessmentSettingListOffset();
                } else {
                    that.dialogTableVisible=false;
                    that.$message.error(res.data.msg);
                }
            }).catch(function (error) {
                that.$message.error("出错！，请联系信息部。");
            });
        },
        //菜单切换
        caidanchange(val){
            this.allocationArgument.assessmentSettingId='';
            var savejob ={};
            this.parentmenuarr.forEach(item => {
                if(item.id==val){
                    savejob=item
                }
            });
            this.allocationArgument.assessmentSettingId=savejob.id;
        },
        //分配api
        AssessmentSettingOperationContent(){
            console.log(this.allocationArgument);
            this.allocationArgument.id=0
            var url = "/api/PersonnelModule/AssessmentSettingOperationContent"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer '
                },
                data:{
                    id:that.allocationArgument.id==""?0:that.allocationArgument.id,
                    createUserId:that.userId,
                    assessmentSettingId:that.allocationArgument.assessmentSettingId,
                    assessmentProportionChi:that.allocationArgument.assessmentProportionChi,
                    targetValue:that.allocationArgument.targetValue,
                    jobId:that.allocationArgument.jobId,
                    userId:that.allocationArgument.userId,
                    fixed:that.allocationArgument.fixed=='是'?1:2,
                    remark:that.allocationArgument.remark,
                }
            }).then(function (res) {
                if (res.data.code == 200) {
                    that.allocationVisible=false;
                    that.$message({
                        type: 'success',
                        message: res.data.msg
                    });
                    that.GetPerformanceList();
                } else {
                    that.allocationVisible=false;
                    that.$message.error(res.data.msg);
                }
            }).catch(function (error) {
                that.$message.error("出错！，请联系信息部。");
            });
        },
        //打开对话框
        ondialog(){
            this.ruleForm= {
                name: '',
                assessmentProportion: '',
                assessmentStandard: '',
                parentId: '',
                parentmenu:'',
                id:'',
                createId: '',
                remark: '',
            },
            this.dialogTableVisible=true;
        },
        //保存分数api
        SaveUserAssessmen(data,date){
            var url = "/api/PersonnelModule/SaveUserAssessmen"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer '
                },
                data:{
                    createUserId:that.userId,
                    assessmenData:date,
                    assessmenUserId:that.value,
                    data:data
                }
            }).then(function (res) {
                if (res.data.code == 200) {
                    that.$message({
                        type: 'success',
                        message: res.data.msg
                    });
                    that.GetPerformanceList();
                } else {
                    that.$message.error(res.data.msg);
                }
            }).catch(function (error) {
                that.$message.error("出错！，请联系信息部。");
            });
        },
        //保存分数
        saveclick(){
            console.log(this.datetime(this.monthdate));
            var itemdata=[];
            for (let y = 0; y <this.tablelist.length; y++) {
                for(let e=0;e<this.tablelist[y].children.length;e++){
                    for (let s = 0; s < this.tablelist[y].children[e].children.length; s++) {
                        console.log(this.tablelist[y].children[e].children[s]);
                        // console.log(this.isLeader);
                        if (this.isLeader) {
                            itemdata.push({
                                assessmentContentSettingId:this.tablelist[y].children[e].children[s].contentId,
                                selfAssessment:this.tablelist[y].children[e].children[s].selfAssessment,
                                higherUpAssessment:this.tablelist[y].children[e].children[s].higherUpAssessment,
                                leadersId:0,
                                status:this.tablelist[y].children[e].children[s].status,
                            })
                        }else{
                            if(this.tablelist[y].children[e].children[s].higherUpConfig!=1&&this.isLeader){
                                itemdata.push({
                                    assessmentContentSettingId:this.tablelist[y].children[e].children[s].contentId,
                                    selfAssessment:this.tablelist[y].children[e].children[s].selfAssessment,
                                    higherUpAssessment:this.tablelist[y].children[e].children[s].higherUpAssessment,
                                    leadersId:0,
                                    status:this.tablelist[y].children[e].children[s].status,
                                })
                            }
                        }
                    }
                }
            }
            this.SaveUserAssessmen(itemdata,this.datetime(this.monthdate));
        },
        onallocation(){
            this.allocationArgument={
                id:'',
                Corporation:'',
                Division:'',
                createUserId:'',
                assessmentSettingId:'',
                assessmentProportionChi:'',//占比
                targetValue:'',//目标值
                jobId:'',//岗位id
                userId:'',//员工id
                fixed:'',//固定标识 (1 是固定 2 是灵活)
                remark:'',//备注
            }
            this.allocationVisible=true
        },
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
            if (valid) {
                this.AssessmentSettingOperation();
            } else {
                console.log('error submit!!');
                return false;
            }
            });
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        },
        submitFormallocation(formName) {
            this.$refs[formName].validate((valid) => {
            if (valid) {
                this.AssessmentSettingOperationContent();
            } else {
                console.log('error submit!!');
                return false;
            }
            });
        },
        resetFormallocation(formName) {
            this.$refs[formName].resetFields();
        }
    },
    mounted(){
        this.GetWageSheetBasicsDataSource();
        this.getheight();
        this.QueryAssessmentSettingListOffset();
    },
    created(){
        this.monthdate=new Date();
        this.userId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId;
        this.token = JSON.parse(localStorage.getItem('userinif')).token;
        this.daraSource();
        window.addEventListener('resixe',this.getheight);
    }
}
</script>
<style>
.PerformanceT-all {
    width: 1599px;
    background-color: #fff;
    padding: 10px;
    box-shadow: 0 0 5px #0005;
    border-radius: 10px;
    min-height: 830px;
    color: #555;
    font-size: 12px;
}
.PerformanceT-table-box{
    display: flex;
    align-items: center;
    border-bottom: 1px solid #ebeef5;
}
.pf-table.PerformanceT-table-box :first-child {
    border-top: 1px solid #ebeef5;
}
.PerformanceT-table-box .second-box{
    display: flex;
    align-items: center;
}
.PerformanceT-table-box>div{
    display: inline-block;
}
.PerformanceT-title{
    display: flex;
}
.second-box{
    margin-top: -1px;
    border-top: 1px solid #ebeef5;
}
.pf-table{
    border-top: 1px solid #ebeef5;
    border-left: 1px solid #ebeef5;
    border-right: 1px solid #ebeef5;
}
.pf-onename{
    width:150px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-left: 1px solid #ebeef5;
    border-right: 1px solid #ebeef5;
}
.pf-zb{
    width: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-right: 1px solid #ebeef5;
}
.pf-twoname{
    display: flex;
    border-top: 1px solid #ebeef5;
    margin-top: -1px;
}
.pf-twoname>div{
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.PerformanceT-title{
    border-left: 1px solid #ebeef5;
    border-top: 1px solid #ebeef5;
}
.PerformanceT-title>div{
    text-align: center;
    border-right: 1px solid #ebeef5;
    padding: 10px 0;
}
.PerformanceT-hade{
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
}
.settings-dialog .el-form-item{
    width: 395px;
}
.settings-dialog .el-select,.el-input{
    width: 100%;
}
.settings-form{
    display: flex;
    flex-wrap:wrap ;
}
.allocation-dialog .el-form-item{
    width: 395px;
}
.allocation-dialog .el-select,.el-input{
    width: 100%;
}
.allocation-form{
    display: flex;
    flex-wrap:wrap ;
}
.pf-table .el-input-number.is-without-controls .el-input__inner{
    padding-left: 10px;
    padding-right: 10px;
}
.deleteXM{
    display: flex;
    align-items:center ;

}
.deleteXM label{
    width: 90px;
}

</style>


