<template>
    <section v-loading="zhoLoading">
        <!--列表-->
        <div>
            <el-card class="box-card daily" shadow="never">
                <div slot="header" class="clearfix" id="clearfix" style="padding-left: 255px;">
                    <div class="jjk" style="display:inline-block;position:fixed;top:70px;background:#fff;left:250px;">
                        <el-date-picker size="small" v-model="date" :editable="false" format="yyyy-MM" value-format="yyyy-MM"
                         style="width:190px;"
                         @change="changeMonthOut" :clearable="false" type="month" placeholder="选择月份"></el-date-picker>
                         <el-button style="margin-left:10px;" icon="iconfont firerock-icongongshitongji" size="mini"  @click="showMonthWorkTime"></el-button>
                    </div>
                        <span v-for="(item,index) in allDate" :id="'day'+index" :class="index==choseDay?'chooseDate date_item':'date_item'" 
                        @click="choseDate(index, item)" :key="index" >
                        <div :style="'display:inline-block;'+(item.state == null?'padding:0px 6px;':'')" >
                            <div><span>{{item.showDate}}</span>
                            <span style="font-size:10px;text-align:center;color:#999;">{{item.weekDay}}</span>
                            </div>
                        </div>
                        <i v-if="item.state != null" class="iconfont firerock-icondot" :class="statusStyle[item.state]"></i>
                        </span>
                </div>
                <div style="display:flex;">
                <div v-if="user.role > 0 || user.manageDeptId != 0" >
                    <div style="width:190px;">
                        <el-select v-model="selectState" size="small" @change="stateChange" >
                        <el-option value="-1" label="全部状态" >全部状态</el-option>
                        <el-option value="-2" label="未填报">未填报</el-option>
                        <el-option value="1" label="已通过">已通过</el-option>
                        <el-option value="0" label="待审核">待审核</el-option>
                        <el-option value="2" label="不通过">不通过</el-option>
                        <el-option value="3" label="待提交">待提交</el-option>
                        </el-select></div>
                    <div>
                        <el-tree :data="data"  @node-click="handleNodeClick" >
                            <span class="custom-tree-node" slot-scope="{ node, data}">
                            <span>{{ node.label }}</span>
                            <span v-if="data.membCount != null && data.isUser == null">({{data.membCount}})</span>
                            <div style="width:0%;float:right;">
                            <span v-if="data.isUser == 1 && data.state == null" style="color:red;">
                            未填报
                            </span>
                            <span v-if="data.isUser == 1 && data.state == 0" style="color:orange;">
                            待审核
                            </span>
                            <span v-if="data.isUser == 1 && data.state == 1" style="color:green;">
                            已通过
                            </span>
                            <span v-if="data.isUser == 1 && data.state == 2" style="color:red;">
                            未通过
                            </span>
                            <span v-if="data.isUser == 1 && data.state == 3" style="color:red;">
                            待提交
                            </span>
                            </div>
                        </span>
                        </el-tree>
                    </div>
                </div>
                
                <div :style="'height:'+tableHeight+'px;width:0.5px;background:#eee;margin-right:10px;margin-left:10px;'" ></div>
                <div class="allDaily" style="float:left;flex-grow:1">
                    <!--系统管理员和部门负责人 -->
                    <div class="report_title" >
                        
                        <span>工作日报 </span>
                        <span v-if="user.role==1||user.role==2||user.role==6||user.manageDeptId != 0">| {{depData != null ?depData.label:""}}
                        <span v-if="targetUid == null">
                         - 已填写
                        <el-link :underline="false" @click="showMembList(1)"><span style="margin-left:5px;margin-right:5px;color:green;">{{reportList.length}}</span></el-link>人，
                        未填写<el-link :underline="false" @click="showMembList(0)"><span style="margin-left:5px;margin-right:5px;color:red;">{{(depData == null?data[0].membCount:(depData.isUser == 1?1:depData.membCount))-reportList.length}}</span></el-link>人
                        </span>
                        </span>
                        <span style="float:right;">
                            <el-link type="primary" style="margin-right:10px;" :underline="false" @click="isSubstitude=false;fillInReport(-1,0)">填写日报</el-link>
                            <el-link v-if="reportTimeType.type != 0" type="primary" style="margin-right:10px;" :underline="false" @click="isSubstitude=false;fillInReportss()">按周填报</el-link>
                            <el-link type="primary" v-if="user.role==1||user.role==2||user.leader==1||user.manageDeptId != 0" style="margin-right:10px;" :underline="false" @click="isSubstitude=true; fillInReport(-1,0)">代填日报</el-link>
                            <el-link type="primary" style="margin-right:10px;" :underline="false" @click="isSubstitude=false;fillInReport(-1,1)">批量填报</el-link>
                            <el-link type="primary" v-if="user.role==1||user.role==2||user.role==6||user.manageDeptId != 0" style="margin-right:10px;" :underline="false" @click="imports()">工时导入</el-link>
                            <el-link type="primary" style="margin-right:10px;" :underline="false" @click="showExportDialog">导出日报</el-link>
                        </span>
                    </div>
                    <!--普通员工，含项目经理 -->
                    <!-- <div class="report_title" v-if="(user.role==0||user.role==3||user.role==5) && user.manageDeptId == 0"><span>日报列表</span>
                    <span style="float:right;" v-if="(user.role==0||user.role==3||user.role==5) && user.manageDeptId == 0">
                            <el-link type="primary" style="margin-right:10px;" :underline="false" @click="isSubstitude=false;fillInReport(-1,0)">填写日报</el-link>
                            <el-link v-if="reportTimeType.type != 0" type="primary" style="margin-right:10px;" :underline="false" @click="isSubstitude=false;fillInReportss()">按周填报</el-link>
                            <el-link type="primary" v-if="user.leader" style="margin-right:10px;" :underline="false" @click="isSubstitude=true; fillInReport(-1,0)">代填日报</el-link>
                            <el-link type="primary" style="margin-right:10px;" :underline="false" @click="isSubstitude=false;fillInReport(-1,1)">批量填报</el-link>
                    </span> -->
                    <!-- </div> -->
                    <div :style="'height:'+(tableHeight-50)+'px;overflow:scroll;padding-top:10px;'">
                        <div class="one_daily" v-for="(item1,index1) in reportList" :key="index1">
                            <i class="fa fa-circle"></i>{{item1.name}}
                            <span style="margin-left:30px;">
                                <span style="margin-right:20px;">
                                    <!-- <i v-if="parseFloat(item1.reportTime)>parseFloat(item1.calculateTime)+0.5" style="color:red;margin-right:8px;" class="fa fa-exclamation-triangle"></i> -->
                                    工作总时长：
                                    <!-- <span :style="parseFloat(item1.reportTime)>parseFloat(item1.calculateTime)+0.5?'color:red':''">{{item1.reportTime}}h</span> -->
                                    <span >{{item1.reportTime}}</span>h
                                    <span v-if="user.role ==1 || user.role == 2 ||user.role == 6"><span  style="margin-left:10px;">成本：</span>
                                    <span >{{item1.cost}}</span>元</span>
                                </span>
                            </span>
                            <div class="checkbtn" style="padding-right:20px;">
                                <el-button v-if="item1.state >= 2 && user.id == item1.id" type="primary" size="small" @click="isSubstitude=false; fillInReport(index1,0)">编辑日报</el-button>
                                <el-button v-if="(user.role == 1 || user.role == 2 || user.manageDeptId != 0) && item1.state != 1" size="small" @click="guanli(item1)" style="float: right;">删除</el-button>
                            </div>
                            <div class="one_daily_body">
                                <el-timeline>
                                    <el-timeline-item v-for="(item2,index2) in item1.data" :key="index2">
                                        <el-card shadow="never">
                                            <p>项目：<b>{{item2.project}}</b><span v-if="item2.subProjectName != null"> / {{item2.subProjectName}}</span>
                                            
                                            <span v-if="user.company.packageEngineering == 0">
                                            <span style="margin-left:15px;color:#DAA520;"  v-if="item2.state == 0">[ 
                                                <span v-if="item2.isDeptAudit==0">
                                                    <span v-if="item2.projectAuditState==0">
                                                        待项目负责人审核
                                                    </span>
                                                    <span style="color:#32CD32;" v-else-if="item2.projectAuditState==1">
                                                        项目负责人审核通过
                                                    </span>
                                                <!-- {{item2.isDeptAudit==0?(item2.projectAuditState==0?'待项目负责人审核':'项目负责人审核通过'):('待'+item2.auditDeptName+'审核')}} -->
                                                </span>
                                                <span v-else-if="item2.isDeptAudit==1">
                                                    {{('待'+item2.auditDeptName+'审核')}}
                                                </span>
                                                 ]</span>
                                            <span style="margin-left:15px;color:#DAA520;" v-else-if="item2.state == -1">[ 导入待审核 ]</span>
                                            <span style="margin-left:15px;color:#32CD32;" v-else-if="item2.state == 1">[ 已通过 ]</span>
                                            <span style="margin-left:15px;color:#FF0000;" v-else-if="item2.state == 2">[ 已驳回 ] 原因:{{item2.rejectReason}}</span>
                                            <span style="margin-left:15px;color:#FF0000;" v-else-if="item2.state == 3">[ 待提交 ]</span>
                                            </span>
                                            <!-- <el-button v-if="(user.role == 1 || user.role == 2) && item2.state != 1 && user.manageDeptId != 0" size="mini" @click="guanli(item2, item1)" style="float: right;">删除</el-button> -->
                                            <span v-if="user.company.packageEngineering == 1">
                                                <span style="margin-left:15px;color:#DAA520;" v-if="item2.state == -1">[ 导入待审核 ]</span>
                                                <span style="margin-left:15px;color:#DAA520;" v-if="item2.state == 0 && item2.departmentAuditState == -1">[ 待专业审核 ]</span>
                                                <span style="margin-left:15px;color:#DAA520;" v-if="item2.state == 0 && item2.departmentAuditState == 0">[ 待部门审核 ]</span>
                                                <span style="margin-left:15px;color:#DAA520;" v-if="item2.state == 0 && item2.departmentAuditState == 1">[ 待项目经理审核 ]</span>
                                                <span style="margin-left:15px;color:#32CD32;" v-else-if="item2.state == 1">[ 已通过 ]</span>
                                                <span style="margin-left:15px;color:#FF0000;" v-else-if="item2.state == 2">[ 已驳回 ] 原因:{{item2.rejectReason}}</span>
                                                <span style="margin-left:15px;color:#FF0000;" v-else-if="item2.state == 3">[ 待提交 ]</span>
                                            </span>

                                            <!--每个项目上单独审核 -->
                                            <span style="float:right;">
                                                <el-button v-if="(user.role == 1 || user.role == 2 || user.id == item2.inchargerId) && item2.state == 0 && item2.isDeptAudit==0 && item2.projectAuditState==0" type="primary" :loading="logining" 
                                                size="small" @click="approve(item1.id, item2)">通过</el-button>
                                                <el-button v-if="(user.role == 1 || user.role == 2 || user.id == item2.inchargerId) && item2.state == 0 && item2.isDeptAudit==0 && item2.projectAuditState==0" type="danger" :loading="logining" 
                                                size="small" @click="showDenyDialog(item1.id,0, item2)">驳回</el-button>
                                                <el-button v-if="(user.role == 1 || user.role == 2 || user.id == item2.inchargerId) && item2.state == 1" type="normal" :loading="logining" size="small" 
                                                @click="showDenyDialog(item1.id,1, item2)">撤销</el-button>
                                                <!--自己可以撤回待审核状态的报告 -->
                                                <el-button v-if="user.id == item1.id && (item2.state == 0 || item2.state == -1)" type="normal" :loading="logining" size="small" @click="cancel(item1)">撤回</el-button>
                                            </span>
                                            </p>
                                            <p v-if="user.timeType.customDegreeActive==1 && item2.degree_id != null">{{user.timeType.customDegreeName}}：{{item2.degreeName}}</p>
                                            <p v-if="user.company.packageEngineering == 1">
                                                专业进度：
                                                <span style="margin-right:10px;" v-for="progressItem in item2.professionProgress" :key="progressItem.id">{{progressItem.professionName}}({{progressItem.progress}}%) 
                                                    <el-tooltip v-if="progressItem.auditState == 0"  content="待审核" effect="light" placement="top">
                                                    <i class="iconfont firerock-icondaibandengdaishenhe"></i>
                                                    </el-tooltip>
                                                    <el-tooltip v-if="progressItem.auditState == 1" content="已通过" effect="light" placement="top">
                                                    <i  class="iconfont firerock-iconshenhetongguo"></i>
                                                    </el-tooltip>
                                                    <el-tooltip v-if="progressItem.auditState == 2" content="不通过" effect="light" placement="top">
                                                    <i  class="iconfont firerock-iconshenhebohui"></i>
                                                    </el-tooltip>
                                                    </span>
                                            </p>
                                            <p v-if="item2.taskId != null">任务：{{item2.taskName}}
                                            </p>
                                            <div v-if="item2.multiWorktime==0">
                                            <p style="display: inline-block;">时长：
                                                <span v-if="item2.reportTimeType == 0" style="margin-right:10px;">{{typeList[item2.timeType]}}</span>
                                                <span v-if="item2.reportTimeType == 2" style="margin-right:10px;">{{item2.startTime+'-'+item2.endTime}}</span>
                                            {{item2.time.toFixed(1)}}h  
                                            <el-tag type="danger" size="mini" style="margin-left: 65px" v-if="item2.isOvertime === 1">加班</el-tag>
                                            <!-- 阶段 -->
                                            <span v-if="item2.stage != null" style="margin-left:10px;"> 投入阶段：{{item2.stage}}</span>
                                            </p>
                                            <p>事项：<span v-html="item2.content"></span></p>
                                            </div>
                                            <div v-if="item2.multiWorktime==1" >
                                                <div v-for="(timeItem, tIndex) in item2.worktimeList" :key="tIndex"
                                                    style="border: 0.5px #ddd solid;margin-bottom:5px;padding:5px;">
                                                    <p style="display: inline-block;">时长：
                                                        <span v-if="item2.reportTimeType == 2" style="margin-right:10px;">{{timeItem.startTime+'-'+timeItem.endTime}}</span>
                                                    {{timeItem.time.toFixed(2)}}h  
                                                    <el-tag type="danger" size="mini" style="margin-left: 65px" v-if="item2.isOvertime === 1">加班</el-tag>
                                                    </p>
                                                    <p>事项：<span v-html="timeItem.content"></span></p>
                                                </div>
                                            </div>
                                            <!--照片的显示 -->
                                            <p v-if="item2.pics != null && item2.pics.length > 0"> 
                                                <el-image v-for="(pic, index) in item2.pics" :key="index"
                                                    style="width: 100px; height: 100px; margin-right:10px;"
                                                    :src="pic" 
                                                    :preview-src-list="item2.pics">
                                                </el-image>
                                            </p>
                                        </el-card>
                                    </el-timeline-item>
                                </el-timeline>
                            </div>
                        </div>
                        <!-- 简陋的无报告提示 -->
                        <div v-if="reportList.length==0" style="width:100%;font-size:17px;text-align:center;color:#aaa;">{{curDate}}暂无报告</div>
                    </div>
                </div>
                </div>
            </el-card>
        </div>

        <!-- 填写日报的dialog -->
        <el-dialog :title="isBatch==0?'填写日报':'批量填报'" :visible.sync="dialogVisible" width="60%" :close-on-click-modal="false" @closed="guanbi()">
            <el-form ref="workForm" :model="workForm" :rules="workRules" label-width="100px">
                <el-form-item label="选择人员" v-if="isSubstitude">
                    <el-input @focus="showChooseMembTree" v-model="workForm.userNames"
                    placeholder="请选择代填人员" ></el-input>
                </el-form-item>
                <el-form-item label="工作日期" prop="createDate">
                    <el-date-picker v-model="workForm.createDate" :editable="false" format="yyyy-MM-dd" value-format="yyyy-MM-dd" 
                    :style="'width:'+(isBatch==0?'200':'280')+'px;'" :type="isBatch==0?'date':'daterange'"
                    @change="changeMonth()" @blur="iptBlur(reportTimeType.type)" :clearable="false" placeholder="选择工作日期" :disabled="isDisable"></el-date-picker>
                    <div v-if="falsss" style="display: inline-block;">总{{jsDay}} 天, 共{{jsTime}} 小时</div>
                    <div v-if="isBatch!=0" style="display: inline-block;">总{{jsDay}} 天, 共{{jsTime}} 小时</div>
                    <span v-if="reportTimeType.type == 3" style="margin-left:30px;">{{isBatch==0?'总':'每日'}}时长:</span>
                    <el-input-number :disabled="!canEdit" v-if="reportTimeType.type == 3" style="margin-left:10px;" @change="changeAllTime"
                        v-model="reportTimeType.allday" :precision="1" :step="0.5" :max="12" :min="0.5"></el-input-number>
                    <span v-if="reportTimeType.type == 3">小时</span>
                </el-form-item>
                
                <div v-for="(domain, index) in workForm.domains" :key="domain.id">
                    <div v-if="reportTimeType.multiWorktime==0">
                    <el-form-item v-if="reportTimeType.type != 3" :label="reportTimeType.type ==2?'工作时间':'工作时长'" :prop="'domains.' + index + '.'+timeFields[reportTimeType.type]"
                        :rules="{ required: true, message: '请选择工作时长', trigger: 'blur' }">
                        <el-select v-model="domain.timeType" style="width:200px;"
                            v-if="reportTimeType.type == 0"
                            placeholder="请选择工作时长" 
                            :disabled="workForm.domains.length==0?true:(workForm.domains[index].state>=2?false:true)"
                            @change="onTimeTypeChange(domain.timeType)">
                            <el-option
                                v-for="item in timeType"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                            </el-option>
                        </el-select>
                        <!-- 数字时长选择 -->
                        <el-select v-model="domain.workingTime" style="width:200px;"
                        v-if="reportTimeType.type == 1"
                        :disabled="workForm.domains.length==0?true:(workForm.domains[index].state>=2?false:true)"
                        placeholder="请选择工作时长"
                        @change="seleChn(0)">
                        <el-option v-for="item in timeRange" :key="item" :value="item.toFixed(1)">{{item.toFixed(1)}}</el-option>
                        </el-select>
                        <span v-if="reportTimeType.type == 1">小时</span>

                        <span v-if="reportTimeType.type == 2">
                        <!--时间范围选择 -->
                        <el-time-picker 
                        :disabled="workForm.domains.length==0?true:(workForm.domains[index].state>=2?false:true)"
                            v-model="domain.startTime"
                            placeholder="起始时间"
                            style="width:120px;"
                            format="HH:mm"
                            value-format="HH:mm"
                            :picker-options="{
                            start: '08:00',
                            end: '23:30'
                            }"
                            @change="iptChang()">
                        </el-time-picker> - <el-time-picker 
                        :disabled="workForm.domains.length==0?true:(workForm.domains[index].state>=2?false:true)"
                            v-model="domain.endTime"
                            placeholder="结束时间"
                            style="width:120px;"
                            format="HH:mm"
                            value-format="HH:mm"
                            :picker-options="{
                            start: '08:00',
                            end: '23:30',
                            minTime: domain.startTime
                            }"
                            @change="iptChang()">
                        </el-time-picker>
                        </span>
                        <div class="overtime"><el-checkbox :disabled="!canEdit" v-model="domain.isOvertime">加班</el-checkbox></div>
                    </el-form-item>
                    
                    <el-form-item label="投入项目" :prop="'domains.' + index + '.projectId'"
                        :rules="{ required: true, message: '请选择投入项目', trigger: ['change','blur'] }">
                        <el-select v-model="domain.projectId" placeholder="请选择" style="width:200px;" clearable="true"  filterable="true"
                        @change="selectProject(domain, index)"
                        :disabled="workForm.domains.length==0?true:(workForm.domains[index].state>=2?false:true)">
                            <el-option v-for="item in projectList" :key="item.id" :label="item.projectName" :value="item.id"></el-option>
                        </el-select>
                        <!--子项目 -->
                        <el-select v-model="domain.subProjectId" placeholder="请选择" style="width:200px;" clearable="true" v-if="domain.subProjectList != null && domain.subProjectList.length> 0"
                        :disabled="workForm.domains.length==0?true:(workForm.domains[index].state>=2?false:true)">
                            <el-option v-for="item in domain.subProjectList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                        </el-select>
                        <!-- 项目的阶段 -->
                        <span v-if="user.company.packageProject == 1 && domain.stages != null && domain.stages.length> 0" 
                            style="margin-left:30px;">投入阶段</span>
                        <el-select v-model="domain.stage" placeholder="请选择" style="width:200px;margin-left:10px;" 
                        clearable="true" v-if="user.company.packageProject == 1 && domain.stages != null && domain.stages.length> 0"
                        @change="changeStages(domain, index)"
                        :disabled="workForm.domains.length==0?true:(workForm.domains[index].state>=2?false:true)">
                            <el-option v-for="item in domain.stages" :key="item" :label="item" :value="item"></el-option>
                        </el-select>

                        <el-link v-if="index >= 1" type="primary" :underline="false" @click="delDomain(index)" style="float:right;margin-right:10px;"
                            :disabled="workForm.domains.length==0?true:(workForm.domains[index].state>=2?false:true)">
                            <i class="fa fa-trash" style="color: red;;font-size:18px;"></i>
                        </el-link>
                        <el-link type="primary" v-if="workForm.domains[index].state == 0 || workForm.domains[index].state == 2"
                             :underline="false" style="margin-left:5px;" @click="copyProject(index)">复制</el-link>
                    </el-form-item>
                    <!-- 相关维度 -->
                    <el-form-item :label="yonghuUser.customDegreeName" v-if="domain.projectId && yonghuUser.customDegreeActive == 1">
                            <el-select v-model="domain.degreeId" clearable placeholder="请选择">
                                <el-option v-for="item in domain.wuduList" :key="item.value" :label="item.name" :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    <!-- </el-form-item> -->

                    <el-form-item v-if="reportTimeType.type == 3" label="用时占比" :prop="'domains.' + index + '.'+timeFields[reportTimeType.type]"
                        :rules="{ required: true, message: '请设置用时占比', trigger: 'blur' }">
                        <div style="width:300px;">
                            <el-col span="14"><el-slider :disabled="!canEdit" v-model="domain.progress" :min="10" :show-tooltip="false" :step="10" style="width:180px;" @input="domain.workingTime = (reportTimeType.allday*domain.progress/100).toFixed(1)" @change="seleChn(0)"></el-slider></el-col>
                            <el-col span="10"><span style="margin-left:10px;float:right;"><span style="margin-right:10px;">{{domain.progress}}%</span>{{domain.workingTime}}小时</span></el-col>
                        </div>
                        <div class="overtime"><el-checkbox :disabled="!canEdit" v-model="domain.isOvertime">加班</el-checkbox></div>
                    </el-form-item>
                    <!--工程专业版本模式下， 各个专业的进度填报 -->
                    <el-form-item label="专业进度" :prop="'domains.' + index + '.professionProgress'" v-if="user.company.packageEngineering==1">
                        <span v-for="item in domain.professionProgress" :key="item.professionId" style="margin-right:10px;">
                            <span>{{item.professionName}}</span> / 进度:
                            <el-input size="mini" style="width:60px;" v-model="item.progress"
                            @keyup.native="onProgressChange" 
                            :disabled="workForm.domains.length==0?true:(workForm.domains[index].state>=2?false:true)"></el-input>%
                        </span>
                    </el-form-item>
                    <!--项目管理专业版模式下，项目下的近期执行的任务 -->
                    <el-form-item label="相关任务" :prop="'domains.' + index + '.taskId'" v-if="user.company.packageProject==1" >
                        <el-select v-model="domain.taskId" placeholder="请选择" style="width:100%;" filterable="true" 
                        :disabled="workForm.domains.length==0?true:(workForm.domains[index].state>=2?false:true)">
                            <el-option v-for="item in domain.taskList" :key="item.taskId" :label="item.taskName" :value="item.taskId"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="工作事项" :prop="'domains.' + index + '.content'" >
                        <el-input v-model="domain.content" type="textarea" :rows="4" placeholder="请填写工作事项" clearable
                         :disabled="workForm.domains.length==0?true:(workForm.domains[index].state>=2?false:true)"></el-input>
                    </el-form-item>
                    </div>
                    <!--多个工作事项填报的情况 -->
                    <div v-if="reportTimeType.multiWorktime==1">
                        <el-form-item label="投入项目" :prop="'domains.' + index + '.projectId'"
                            :rules="{ required: true, message: '请选择投入项目', trigger: ['change','blur'] }">
                            <el-select v-model="domain.projectId" placeholder="请选择" style="width:200px;" clearable="true"  filterable="true"
                            @change="selectProject(domain, index)"
                            :disabled="workForm.domains.length==0?true:(workForm.domains[index].state>=2?false:true)">
                                <el-option v-for="item in projectList" :key="item.id" :label="item.projectName" :value="item.id"></el-option>
                            </el-select>
                            <!--子项目 -->
                            <el-select v-model="domain.subProjectId" placeholder="请选择" style="width:200px;" clearable="true" v-if="domain.subProjectList != null && domain.subProjectList.length> 0"
                            :disabled="workForm.domains.length==0?true:(workForm.domains[index].state>=2?false:true)">
                                <el-option v-for="item in domain.subProjectList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                            </el-select>
                            <!-- 项目的阶段 -->
                            <span v-if="user.company.packageProject == 1 && domain.stages != null && domain.stages.length> 0" 
                                style="margin-left:30px;">投入阶段</span>
                            <el-select v-model="domain.stage" placeholder="请选择" style="width:200px;margin-left:10px;" clearable="true" v-if="user.company.packageProject == 1 && domain.stages != null && domain.stages.length> 0"
                                @change="changeStages(domain, index)"
                            :disabled="workForm.domains.length==0?true:(workForm.domains[index].state>=2?false:true)">
                                <el-option v-for="item in domain.stages" :key="item" :label="item" :value="item"></el-option>
                            </el-select>

                            <el-link v-if="index >= 1" type="primary" :underline="false" @click="delDomain(index)" style="float:right;margin-right:10px;"
                                :disabled="workForm.domains.length==0?true:(workForm.domains[index].state>=2?false:true)">
                                <i class="fa fa-trash" style="color: red;;font-size:18px;"></i>
                            </el-link>
                            <el-link type="primary" v-if="workForm.domains[index].state == 0 || workForm.domains[index].state == 2"
                                :underline="false" style="margin-left:5px;" @click="copyProject(index)">复制</el-link>
                        </el-form-item>
                        <!--工程专业版本模式下， 各个专业的进度填报 -->
                        <el-form-item label="专业进度" :prop="'domains.' + index + '.professionProgress'" v-if="user.company.packageEngineering==1">
                            <span v-for="item in domain.professionProgress" :key="item.professionId" style="margin-right:10px;">
                                <span>{{item.professionName}}</span> / 进度:
                                <el-input size="mini" style="width:60px;" v-model="item.progress"
                                @keyup.native="onProgressChange" 
                                :disabled="workForm.domains.length==0?true:(workForm.domains[index].state>=2?false:true)"></el-input>%
                            </span>
                        </el-form-item>
                        <!-- 相关维度 -->
                        <el-form-item :label="yonghuUser.customDegreeName" v-if="domain.projectId && yonghuUser.customDegreeActive == 1">
                            <el-select v-model="domain.degreeId" clearable placeholder="请选择">
                                <el-option v-for="item in domain.wuduList" :key="item.value" :label="item.name" :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <!--项目管理专业版模式下，项目下的近期执行的任务 -->
                        <el-form-item label="相关任务" :prop="'domains.' + index + '.taskId'" v-if="user.company.packageProject==1" >
                            <el-select v-model="domain.taskId" placeholder="请选择" style="width:100%;" filterable="true" 
                            :disabled="workForm.domains.length==0?true:(workForm.domains[index].state>=2?false:true)">
                                <el-option v-for="item in domain.taskList" :key="item.taskId" :label="item.taskName" :value="item.taskId"></el-option>
                            </el-select>
                        </el-form-item>
                        <div v-for="(timeItem,tIndex) in domain.worktimeList" :key="tIndex" 
                            style="border: 0.5px #ddd solid;padding:5px;margin-bottom:15px;position:relative;">
                        <i v-if="tIndex>0&&workForm.domains[index].state>=2" @click="removeTimeItem(domain,tIndex)"  class="el-icon-delete" style="position:absolute;right:-7px;top:-7px;font-size:16px;"></i>
                        <el-form-item label="工作时间" :prop="'domains.' + index + '.worktimeList.'+tIndex+'.'+timeFields[reportTimeType.type]"
                            :rules="{ required: true, message: '请选择工作时间', trigger: 'blur' }">
                            
                            <span v-if="reportTimeType.type == 2">
                            <!-- <span> -->
                            <!--时间范围选择 -->
                            <el-time-picker 
                            :disabled="workForm.domains.length==0?true:(workForm.domains[index].state>=2?false:true)"
                                v-model="timeItem.startTime"
                                placeholder="起始时间"
                                style="width:120px;"
                                format="HH:mm"
                                value-format="HH:mm"
                                :picker-options="{
                                start: '00:00',
                                end: '23:59',
                                }"
                                @change="iptChangs()">
                            </el-time-picker> - <el-time-picker 
                            :disabled="workForm.domains.length==0?true:(workForm.domains[index].state>=2?false:true)"
                                v-model="timeItem.endTime"
                                placeholder="结束时间"
                                style="width:120px;"
                                format="HH:mm"
                                value-format="HH:mm"
                                :picker-options="{
                                start: '00:00',
                                end: '23:59',
                                minTime: timeItem.startTime
                                }"
                                @change="iptChangs()">
                            </el-time-picker>
                            </span>
                        </el-form-item>
                        <el-form-item label="工作事项" :prop="'domains.' + index + '.worktimeList.'+tIndex+'.content'" 
                        :rules="{ required: true, message: '填写工作事项', trigger: 'blur' }">
                            <el-input v-model="timeItem.content" type="textarea" :rows="2" placeholder="请填写工作事项" clearable
                            :disabled="workForm.domains.length==0?true:(workForm.domains[index].state>=2?false:true)"
                            ></el-input>
                        </el-form-item>
                        </div>
                        <el-link size="small" @click="addNewWorktime(index, domain)" style="margin-left:15px;margin-top:5px;margin-bottom:5px;">添加工时</el-link>
                    </div>

                    <!--照片的显示 -->
                    <p v-if="domain.pics != null && domain.pics.length > 0" style="text-align:center;"> 
                        <el-image v-for="(pic, index) in domain.pics" :key="index"
                            style="width: 100px; height: 100px; margin-right:10px;"
                            :src="pic" 
                            :preview-src-list="domain.pics">
                        </el-image>
                    </p>
                    <el-divider v-if="workForm.domains.length>1" style="margin-bottom:10px;"></el-divider>
                </div>
                <el-link v-if="showAddMore"  :disabled="!canEdit" type="primary" :underline="false" @click="addDomain(reportTimeType.type)" style="margin-left:40px">添加更多</el-link>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="deleteReport" v-if="workForm.domains[0].id != null">删除</el-button>
                <el-button @click="dialogVisible = false">取消</el-button>
                <el-button @click="submitDepartment(1)" :disabled="workForm.domains.length==0?true:(canEdit?false:true)">暂存</el-button>
                <el-button type="primary" @click="submitDepartment(0)"
                :disabled="workForm.domains.length==0?true:(canEdit?false:true)" >提交</el-button>
            </span>
        </el-dialog>

        <!-- 按周填报 -->
        <el-dialog title="按周填报" :visible.sync="diasZho" width="60%" :close-on-click-modal="false" @closed="guanbi()">
            <el-form ref="workForm" :model="workForm" :rules="workRules" label-width="100px">
                <el-form-item label="工作日期" prop="createDate">
                     <el-date-picker v-model="zhoRqi" format="yyyy-MM-dd" value-format="yyyy-MM-dd" @change="zhoRqis()" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="margin-right: 18px"></el-date-picker>
                     <el-button @click="handleGetPrevWeek()">上周</el-button>
                     <el-button @click="getCurrentWeek()">本周</el-button>
                     <el-button @click="handleGetNextvWeek()">下周</el-button>
                     <el-button @click="newDates()">新增日期</el-button>
                </el-form-item>
                <el-table :data="zhoData" style="width: 100%" v-loading="zhoLoading">
                    <el-table-column fixed="left" prop="zhoDataTime" label="日期" width="160">
                        <template slot-scope="scope">
                            {{scope.row.zhoDataTime}}（{{scope.row.zhoDataTime | zhoData}}）
                        </template>
                    </el-table-column>
                    <!-- <el-table-column align="center" v-for="(item, index) in projectList" :key="item.id" :label="item.projectName" width="200"> -->
                    <el-table-column align="center" v-for="item in projectList" :key="item.id" :label="item.projectName" width="200">
                        <template slot-scope="scope">
                            <div v-if="reportTimeType.multiWorktime == 0" slot="reference" @click="tianxies(scope.row[item.projectName], scope.$index, item.projectName, workForm.domains)">
                                <el-button v-if="scope.row[item.projectName].workingTime != null && scope.row[item.projectName].workingTime != '' && reportTimeType.type == 3 && scope.row[item.projectName].workingTime > 0" type="text" slot="reference">{{scope.row[item.projectName].workingTime}} h</el-button>
                                <el-button v-else-if="scope.row[item.projectName].workingTime != null && scope.row[item.projectName].workingTime != '' && reportTimeType.type == 1 && scope.row[item.projectName].workingTime > 0" type="text" slot="reference">{{scope.row[item.projectName].workingTime}} h</el-button>
                                <el-button v-else-if="scope.row[item.projectName].time != null && scope.row[item.projectName].time != '' && reportTimeType.type == 2" type="text" slot="reference">{{scope.row[item.projectName].time[0]}} - {{scope.row[item.projectName].time[1]}}</el-button>
                                <el-button v-else type="text" >请填写</el-button>
                            </div>
                            <div v-if="reportTimeType.multiWorktime == 1" slot="reference" @click="tianxies(scope.row[item.projectName], scope.$index, item.projectName, workForm.domains)">
                                <el-button v-if="scope.row[item.projectName].time != null && scope.row[item.projectName].time != '' && reportTimeType.type == 2" type="text" slot="reference">{{scope.row[item.projectName].time[0]}} - {{scope.row[item.projectName].time[1]}}</el-button>
                                <el-button v-else type="text" >请填写</el-button>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column fixed="right" prop="he" label="合计(h)" width="120">
                        <template slot-scope="scope">
                            <div class="zhiss">
                                <p>{{scope.row.he}}</p>
                                <el-button size="mini" icon="el-icon-delete" circle @click="zhoBtn(scope.$index)"></el-button>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="diasZho = false">取 消</el-button>
                <el-button type="primary" @click="zhoAdd()">提 交</el-button>
            </span>
        </el-dialog>
        <!-- 选择时间 -->
        <el-dialog title="时间选择" :visible.sync="btnZho" width="30%" :before-close="handleClose">
            <span>这是一段信息</span>
            <span slot="footer" class="dialog-footer"> 
                <el-button @click="btnZho = false">取 消</el-button>
                <el-button type="primary" @click="btnZho = false">确 定</el-button>
            </span>
        </el-dialog>

        <!-- 按周填报弹窗 -->
        <el-dialog title="请填写" :visible.sync="tianxieDialogVisible" width="30%" :before-close="handleClose">
            <div>
                <div class="zhoFel" v-if="zhoBao.subProjectList != null && zhoBao.subProjectList.length > 0">
                    <p>子项目</p>
                    <el-select v-model="zhoBao.subProjectId" placeholder="请选择" clearable="true" style="width: 355px">
                        <el-option v-for="item in zhoBao.subProjectList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                    </el-select>
                </div>
                <div class="zhoFel" v-if="user.company.packageProject == 1 && zhoBao.stages != null && zhoBao.stages.length> 0">
                    <p>投入阶段</p>
                    <el-select v-model="zhoBao.stage" placeholder="请选择" style="width: 355px" clearable="true">
                            <el-option v-for="item in zhoBao.stages" :key="item" :label="item" :value="item"></el-option>
                    </el-select>
                </div>
                <div class="zhoFel" v-if="reportTimeType.type == 2">
                    <p>选择时间</p>
                    <el-time-picker style="width: 355px" is-range v-model="zhoBao.time" format="HH:mm" value-format="HH:mm" range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" placeholder="选择时间范围"></el-time-picker>
                </div>
                <div class="zhoFel" v-if="reportTimeType.type == 1">
                    <p>选择时长</p>
                    <el-select clearable v-model="zhoBao.workingTime" style="width: 355px;" placeholder="请选择工作时长">
                        <el-option v-for="item in timeRange" :key="item" :value="item.toFixed(1)">{{item.toFixed(1)}}</el-option>
                    </el-select>
                </div>
                <div class="zhoFel" v-if="reportTimeType.type == 3">
                    <p>用时占比</p>
                    <div style="width:355px;display: flex;align-items: center;">
                        <el-col span="23"><el-slider style="margin-left: 5px;width:249px;" v-model="zhoBao.progress" :min="0" :show-tooltip="false" :step="10" @input="zhoBao.workingTime = (reportTimeType.allday*zhoBao.progress/100).toFixed(1)"></el-slider></el-col>
                        <el-col span="10"><span style="float:right;"><span style="margin-right:10px;">{{zhoBao.progress || 0}}%</span>{{zhoBao.workingTime | amounts}}小时</span></el-col>
                    </div>
                </div>
                <div class="zhoFel">
                    <p>工作事项</p>
                    <el-input type="textarea" v-model="zhoBao.con" placeholder="请输入工作事项" style="width: 355px" clearable></el-input>
                </div>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="tianxieDialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="btnTianxiaes()">确 定</el-button>
            </span>
        </el-dialog>

        <!-- 批量日报审核 -->
        <el-dialog title="批量项目报告审核" :visible.sync="approveDialogVisible" width="500px" >
            
            <el-checkbox v-model="isAllSelect" label="全选" style="margin-left:24px;" @change="selectAll" v-if="reportNames.length > 0"></el-checkbox>
            <el-tree ref="approveTree" node-key="id" :data="reportNames" show-checkbox="true" @check-change="handleCheckChange" >
            </el-tree>
            <div style="margin-left:30px;color:#999;" v-if="user.company.packageEngineering==1">仅能看到自己负责的待项目审核的日报填写人员</div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="approveDialogVisible = false">取消</el-button>
                <el-button type="primary" @click="submitBatchApprove" :disabled="batchShowData.length == 0">审核通过</el-button>
            </span>
        </el-dialog>
        <!--导出报表条件选择 -->
        <el-dialog title="日报导出" v-if="exportDialog" :visible.sync="exportDialog" customClass="customWidth" width="500px">
            <el-form ref="form3" :model="exportParam" >
                <el-form-item prop="projectId" label="选择项目">
                    <el-select v-model="exportParam.projectId" placeholder="全部项目"  clearable style="width:350px;">
                        <el-option v-for="item in projectList"  :key="item.id" :label="item.projectName" :value="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item prop="projectId" label="日期范围">
                    <el-date-picker
                        v-model="exportParam.dateRange" :editable="false" 
                        format="yyyy-MM-dd" value-format="yyyy-MM-dd" 
                        :clearable="true" 
                        range-separator="至"
                        type="daterange" 
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                    ></el-date-picker>
                </el-form-item>
                
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="exportReport" style="width:100%;" >导出</el-button>
            </div>
        </el-dialog>
        <!--人员列表 -->
        <el-dialog  :title="(isFill?'已填':'未填')+'人员列表'" v-if="membListVisible" :visible.sync="membListVisible"  width="500px">
            <el-table :show-header="false" :data="fillMembList" highlight-current-row :height="400" style="width: 100%;">
            <el-table-column type="index" width="60">
                <template slot-scope="scope" >
                        {{scope.$index+1}}
                    </template>
            </el-table-column>
            <el-table-column prop="label" label="姓名" ></el-table-column>
            <el-table-column prop="deptName" label="部门" >
            </el-table-column>

            </el-table>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="weixinNotify"  v-if="!isFill" :disabled="fillMembList == 0">微信催填</el-button>
                <el-button type="default" @click="exportMemb"  :disabled="fillMembList == 0">导出</el-button>
            </div>
        </el-dialog>

        
        <!-- 按部门选择人员 -->
        <el-dialog title="选择需要代填报的人员"  v-if="chooseParticipVisible" :visible.sync="chooseParticipVisible" :close-on-click-modal="false" customClass="customWidth" width="500px">
            <!-- <el-input style="width:100%" v-model="filterName" placeholder="请输入姓名搜索" @change="findUserInTree"></el-input> -->
            <div class="tree" style="height:400px">
                <el-scrollbar style="height:100%">
                <el-tree :data="deptMembData" show-checkbox :props="defaultProps" node-key="id"
                    ref="chooseMembTree" @check-change="onTreeItemChange" :default-checked-keys="workForm.userId"
                    highlight-current ></el-tree>
                </el-scrollbar>
            </div>
            <div>已选中&nbsp;{{chosenMembCount}}&nbsp;人</div>
            <div slot="footer" class="dialog-footer">
                <el-button  @click="chooseParticipVisible = false" >取消</el-button>
                <el-button type="primary" @click="chooseParticip()" >确定</el-button>
            </div>
        </el-dialog>

        <el-dialog title="员工每日填报工时数"   v-if="monthWorkTimeDialog" :visible.sync="monthWorkTimeDialog" :close-on-click-modal="false" customClass="customWidth" width="90%">
            <!-- <el-input style="width:100%" v-model="filterName" placeholder="请输入姓名搜索" @change="findUserInTree"></el-input> -->
            <el-table :data="monthWorkData" border :height="500"   highlight-current-row  style="width: 100%;">
            <el-table-column width="60" type="index" fixed="left" label="序号">
                <template slot-scope="scope" >
                        {{scope.$index+1}}
                    </template>
            </el-table-column>
            
            <el-table-column width="100" prop="name" fixed="left" label="姓名">

            </el-table-column>
            <el-table-column width="90" v-for="(item,index) in allDate" :key="index" :label="item.showDate+'/'+item.weekDay" align="center">
                <template slot-scope="scope">
                    <div style="color:red;" 
                    v-if="scope.row.worktimeList.filter(w=>w.createDate.split('-')[2] == item.date.split('月')[1].replace('日','') 
                        || w.createDate.split('-')[2] == '0'+item.date.split('月')[1].replace('日','') ).length > 0 && scope.row.worktimeList.filter(w=>w.createDate.split('-')[2] == item.date.split('月')[1].replace('日','') 
                                || w.createDate.split('-')[2] == '0'+item.date.split('月')[1].replace('日','') )[0].workingTime < reportTimeType.allday">
                                {{scope.row.worktimeList.filter(w=>w.createDate.split('-')[2] == item.date.split('月')[1].replace('日','') 
                                    || w.createDate.split('-')[2] == '0'+item.date.split('月')[1].replace('日','') )[0].workingTime
                        }}</div>
                    <div style="color:#20a0ff;" 
                     v-if="scope.row.worktimeList.filter(w=>w.createDate.split('-')[2] == item.date.split('月')[1].replace('日','') 
                        || w.createDate.split('-')[2] == '0'+item.date.split('月')[1].replace('日','') ).length > 0 && scope.row.worktimeList.filter(w=>w.createDate.split('-')[2] == item.date.split('月')[1].replace('日','') 
                                || w.createDate.split('-')[2] == '0'+item.date.split('月')[1].replace('日','') )[0].workingTime > reportTimeType.allday">
                                {{scope.row.worktimeList.filter(w=>w.createDate.split('-')[2] == item.date.split('月')[1].replace('日','') 
                                    || w.createDate.split('-')[2] == '0'+item.date.split('月')[1].replace('日','') )[0].workingTime
                        }}</div>
                    <div  v-if="scope.row.worktimeList.filter(w=>w.createDate.split('-')[2] == item.date.split('月')[1].replace('日','') 
                        || w.createDate.split('-')[2] == '0'+item.date.split('月')[1].replace('日','') ).length > 0 && scope.row.worktimeList.filter(w=>w.createDate.split('-')[2] == item.date.split('月')[1].replace('日','') 
                                || w.createDate.split('-')[2] == '0'+item.date.split('月')[1].replace('日','') )[0].workingTime == reportTimeType.allday">
                                {{scope.row.worktimeList.filter(w=>w.createDate.split('-')[2] == item.date.split('月')[1].replace('日','') 
                                    || w.createDate.split('-')[2] == '0'+item.date.split('月')[1].replace('日','') )[0].workingTime
                        }}</div>
                    <div v-if="scope.row.worktimeList.filter(w=>w.createDate.split('-')[2] == item.date.split('月')[1].replace('日','') 
                        || w.createDate.split('-')[2] == '0'+item.date.split('月')[1].replace('日','') ).length == 0">
                        0
                    </div>
                </template>
            </el-table-column>
            </el-table>
            <div slot="title" class="dialog-title">
                <label style="font-size:16px;">员工每日填报工时数</label>
                <el-link type="primary" style="float:right;margin-right:60px;" @click="exportMembWorkHours()" >导出数据</el-link>
                <!-- <el-button >导出</el-button> -->
            </div>
        </el-dialog>
        <!--驳回弹出框 -->
        <el-dialog title="请输入原因"  v-if="denyReasonDialog" :visible.sync="denyReasonDialog" :close-on-click-modal="false" customClass="customWidth" width="500px">
            <div>
                <el-input type="textarea" v-model="denyForm.reason" rows="2" :placeholder="'请输入您决定'+(denyForm.i==0?'驳回':'撤销')+'的原因'" />
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button  @click="denyReasonDialog = false" >取消</el-button>
                <el-button type="primary" @click="deny()" >确定</el-button>
            </div>
        </el-dialog>

        <!--批量导入日报 -->
        <el-dialog title="工时批量导入" v-if="importDialog" :visible.sync="importDialog" customClass="customWidth" width="500px">
            <p>1. 下载
            <el-link type="primary" style="margin-left:5px;" :underline="false" href="./upload/员工工时统计模板2.xlsx" download="员工工时导入模板.xlsx">员工工时统计模板.xlsx</el-link>
            </p>
            <p>2. 填写excel模板，请确保模板中的项目和人员已添加到系统中。</p>
            <p style="display: flex;justify-content: center;">
                <el-upload ref="upload"  action="#" :limit="1" :http-request="batchImportData" :show-file-list="false">
                <el-button type="primary" :underline="false" >开始导入</el-button>
            </el-upload>
            </p>
        </el-dialog>

        <!--基于企业微信考勤数据的工时导入 -->
        <el-dialog title="工时批量导入" v-if="importWxDialog" :visible.sync="importWxDialog" customClass="customWidth" width="1100px">
            <el-steps :active="active" finish-status="success">
            <el-step title="选择要导入工时的日期范围">
                
            </el-step>
            <el-step title="下载带考勤数据的模板"></el-step>
            <el-step title="填写模板，上传数据"></el-step>

            </el-steps>
            
                
            <div v-if="active==0" style="padding:30px;height:360px;">
                <div style="margin-top:50px;margin-left:280px;">
                <el-date-picker 
                    v-model="importWxParam.date" :editable="false" 
                    format="yyyy-MM-dd" value-format="yyyy-MM-dd" 
                    :clearable="true" 
                    range-separator="至"
                    type="daterange" 
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    @change="loadCheckInData"
                    ></el-date-picker>
            </div>
            </div>
            <div v-if="active==1" style="padding:10px;">
                <el-table border :data="checkinList" highlight-current-row v-loading="checkinLoading" :height="395" 
                style="width: 100%;margin-top:5px;" >
                <el-table-column prop="createDate" label="工作日期"  ></el-table-column>
                <el-table-column prop="weekDayTxt" label="星期"  ></el-table-column>
                <el-table-column prop="username" label="员工姓名"  ></el-table-column>
                <el-table-column prop="startTime" label="上班时间"  ></el-table-column>
                <el-table-column prop="endTime" label="下班时间" ></el-table-column>
                <el-table-column prop="workHours" label="实际工作时长"  align="right">
                    <template slot-scope="scope">
                        {{scope.row.workHours.toFixed(1)}}h
                    </template>
                </el-table-column>
                </el-table>
            </div>
            <div v-if="active==2" >
                <p style="display: flex;justify-content: center;height:390px;">
                    <el-upload style="margin-top:100px;" ref="upload"  action="#" :limit="1" :http-request="batchImportWxData" :show-file-list="false">
                        <el-button type="primary" :underline="false" >选择文件并上传</el-button>
                    </el-upload>
                </p>
            </div>
            <el-button style="margin: 0 auto;" @click="pre">上一步</el-button>
            
            <el-button style="float:right;" @click="next" :disabled="importWxParam.date==null" v-if="active<2">下一步</el-button>
            <el-link v-if="active==1" style="float:right;margin-right:350px;margin-top:10px;" 
                type="primary" @click="downloadCheckInExcel">下载员工工时统计模板.xlsx</el-link>
            
        </el-dialog>

        <!--基于企业微信考勤数据的工时导入 -->
        <el-dialog title="工时批量代填" v-if="batchSubFillDialog" :visible.sync="batchSubFillDialog" customClass="customWidth" width="90%">
            <div>
                <span>选择日期范围：</span><el-date-picker 
                    v-model="importWxParam.date" :editable="false" 
                    format="yyyy-MM-dd" value-format="yyyy-MM-dd" 
                    :clearable="true" 
                    range-separator="至"
                    type="daterange" 
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    @change="loadCheckInData"
                    ></el-date-picker>
                <el-button style="float:right;" type="primary" @click="submitBatchSubFillData">提交</el-button>
            </div>
                <el-table border :data="checkinList" highlight-current-row v-loading="checkinLoading" :height="520" 
                :key="timeStamp"
                style="width: 100%;margin-top:5px;" ref="tab">
                <el-table-column prop="createDate" label="工作日期"  width="100px" fixed="left"></el-table-column>
                <el-table-column prop="username" label="员工姓名"   width="80px" fixed="left"></el-table-column>
                <el-table-column prop="startTime" label="上班时间"  width="80px" fixed="left"></el-table-column>
                <el-table-column prop="endTime" label="下班时间"  width="80px" fixed="left"></el-table-column>
                <el-table-column prop="workHours" label="工作时长" width="80px" align="right" fixed="left">
                    <template slot-scope="scope">
                        {{scope.row.workHours.toFixed(1)}}h
                    </template>
                </el-table-column>
                <!--项目名称列表 -->
                <el-table-column v-for="(item, index) in projectColumns" :key="index" :label="item" min-width="150px">
                    <template slot-scope="scope">
                        <el-input v-model="scope.row[item]" style="width:60px;" @input="triggerTotalTime(scope.$index)"></el-input>&nbsp;h
                    </template>
                </el-table-column>
                <el-table-column prop="totalFillTime" label="总工时" fixed="right">
                    <template slot-scope="scope">
                        {{scope.row.totalFillTime==null?0.0:scope.row.totalFillTime}}&nbsp;h
                    </template>
                </el-table-column>
                </el-table>
        </el-dialog>
    </section>
</template>

<script>
    import util from "../../common/js/util";

    export default {
        data() {
            return {
                isDraft: 0,
                timeStamp: 0,
                projectColumns:[],
                checkinLoading:false,
                importWxParam:{date:null,},
                active:0,
                importWxDialog:false,
                importDialog:false,
                denyForm:null,
                denyReasonDialog:false,
                monthWorkTimeDialog: false,
                isSubstitude:false,
                isFill:false,
                unFillList:[],
                fillList:[],
                fillMembList:[],
                membListVisible: false,
                isBatch:0,//是否是批量填报
                weekDay : ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
                statusStyle:["waiting", "filledReportStyle", "RejectStyle", ""],
                fillStatusList: [],
                exportParam:{projectId: null, dateRange:[]},
                exportDialog:false,
                timeFields:['timeType', 'workingTime', 'startTime', 'progress'],
                subProjectList:[],
                canEdit: true,
                timeRange:[0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0,5.5,6.0,6.5,7.0,7.5,8.0,8.5,9.0,9.5,10.0,10.5,11.0,11.5,12.0,12.5,13.0,13.5,14.0,14.5,15.0],
                selectTime:null,
                reportTimeType:{},
                curDate:'',
                isAllSelect: false,
                approveDialogVisible:false,
                deptId:null,
                targetUid: null,
                membCount:0,
                selectState:"-1",
                user: JSON.parse(sessionStorage.getItem("user")),
                showAddMore:false,
                allDate: [],
                typeList:['全天','上午','下午'],
                date: sessionStorage.msg?sessionStorage.msg.split('-')[0]+"-"+sessionStorage.msg.split('-')[1]:util.formatDate.format(new Date(new Date()), "yyyy-MM"),
                choseDay: 0,

                tableHeight: 0,
                listLoading: false,

                projectList: [], //项目列表
                reportList: [], //日报列表
                reportNames:[], //批量审批列表

                dialogVisible: false, //项目弹窗
                report: '',
                workForm: {
                    createDate: sessionStorage.msg?sessionStorage.msg:util.formatDate.format(new Date(new Date()), "yyyy-MM-dd"),
                    domains: [{
                        id: null,
                        projectId: "",
                        workingTime: "",
                        timeType:0,
                        content: "",
                        state: 2,
                        multiWorktime:0,
                        worktimeList:[],
                        degreeId: null
                    }],
                },
                workRules: {
                    createDate: [{ required: true, message: "请选择工作日期", trigger: "change" }],
                },
                chooseParticipVisible: false,
                logining: false,
                isDisable: false,
                timeType:[],

                deptMembData: [
                    
                ],
                //部门人员树状结构
                data: [
                    {
                        id: -1,
                        label: '全部人员',
                        membCount:0
                    },
                    {
                        id: 0,
                        label: '未分配',
                    }
                ],
                allData:{},
                batchShowData:{},
                option: [],
                depData: {
                    id: -1,
                    label: '全部人员',
                },
                defaultProps: {
                    children: 'children',
                    label: 'label'
                },
                isNew: false,
                selected: false,
                valuet: new Date(),
                domObj: null,
                participator:[],
                chosenMembCount:0,
                jsDay: 0,
                jsTime: 0,
                falsss: false,
                weidu: [],
                weiduList: [],
                yonghuUser: [],
                dateAr: [],
                batchSubFillDialog: false,
                isSubstiS: false,
                diasZho: false,
                zhoData: [],
                zhoRqi: [],
                btnZho: false,
                zhoLoading: false,
                changdu: 6,
                tianxieDialogVisible: false,
                scopess: {},
                zhoBao: {
                    time: '',
                    workingTime: '',
                    progress: '',
                    con: '',
                    subProjectId: '',
                    stage: '',
                    subProjectList: [],
                    stages: [],
                },
                zhoBaoIdx: '',
                zhoBaoName: '',
                zhis: {}
            };
        },
        filters: {
            // 过滤
            amounts(value) {
                if(value == NaN || value == undefined || value == 'undefined' || value == null || value == 'null') {
                    return 0
                }
                var zhi = +value + 0
                return zhi.toFixed(1)
            },
            // zhoData
            zhoData(value) {
                var dateArray = value.split("-");
                var date = new Date(dateArray[0], parseInt(dateArray[1] - 1), dateArray[2]);
                return "周" + "日一二三四五六".charAt(date.getDay());
            }
        },
        methods: {
            //下载带企业微信考勤数据的工时统计模板
            downloadCheckInExcel() {
                this.http.post('/user-corpwx-time/exportCheckInExcel',{ 
                    startDate: this.importWxParam.date[0],
                    endDate: this.importWxParam.date[1],
                },
                res => {
                    if (res.code == "ok") {
                        var filePath = res.data;
                        const a = document.createElement('a'); // 创建a标签
                        var data = filePath.split("/");
                        a.setAttribute('download', data[data.length-1]);// download属性
                        a.setAttribute('href', filePath);// href链接
                        a.click(); //自执行点击事件
                        a.remove();
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.checkinLoading = false;
                    this.$message({
                        message: error,
                        type: "error"
                    });
                    }
                );
            },
            pre() {
                if (this.active == 0) return;
                this.active--;
            },
            next() {
                this.active++;
            },
            triggerTotalTime(index) {
                var item = this.checkinList[index];
                var total = 0.0;
                for (var i=0;i<this.projectColumns.length; i++) {
                    var key = this.projectColumns[i]; 
                    if (item[key] != null && item[key] != '') {
                        total += parseFloat(item[key]);
                    }
                }
                item.totalFillTime = total;
            },
            //提交批量代填的数据
            submitBatchSubFillData() {
                var data = JSON.stringify(this.checkinList);
                this.http.post('/user-corpwx-time/submitProjectTime',{ 
                    json: data,
                    projectColumns: JSON.stringify(this.projectColumns)
                },
                res => {
                    if (res.code == "ok") {
                        this.$message({message:'提交成功', type:'success'});
                        this.importWxDialog = false;
                    } 
                },
                error => {
                    this.checkinLoading = false;
                    this.$message({
                        message: error,
                        type: "error"
                    });
                    }
                );
            },
           
            loadCheckInData() {
                if (this.importWxParam.date == null) {
                    this.checkinList = [];
                    return;
                }
                this.checkinLoading = true;
                this.http.post('/user-corpwx-time/getMyDeptMembsData',{ 
                    startDate: this.importWxParam.date[0],
                    endDate: this.importWxParam.date[1],
                },
                res => {
                    if (res.code == "ok") {
                        this.checkinLoading = false;
                        this.checkinList = res.data.list;
                        this.projectColumns = res.data.projects;
                        // 自定义表格会导致表格错乱，需重新计算表格
                        this.$nextTick(()=>{
                            this.$refs.tab.doLayout()
                        })
                    } 
                },
                error => {
                    this.checkinLoading = false;
                    this.$message({
                        message: error,
                        type: "error"
                    });
                    }
                );
            },
            batchImportWxData(item) {
                //首先判断文件类型
                let str = item.file.name.split(".");
                let format = str[str.length - 1];
                if (format != "xls" && format != "xlsx") {
                    this.$message({
                        message: "请选择.xls或.xlsx文件",
                        type: "error"
                    });
                } else {
                    this.listLoading = true;
                    let formData = new FormData();
                    formData.append("file", item.file);
                    formData.append("companyId", this.user.companyId);
                    formData.append("withCheckIn", 1);
                    this.http.uploadFile('/report/importData', formData,
                    res => {
                        this.$refs.upload.clearFiles();
                        this.listLoading = false;
                        if (res.code == "ok") {
                            this.$message({
                                message: "成功导入"+res.data+"条工时数据",
                                type: "success"
                            });
                            this.getReportList();
                            this.importWxDialog = false;
                        } else {
                            this.$message({
                                message: res.msg,
                                type: "error"
                            });
                        }
                    },
                    error => {
                        this.$refs.upload.clearFiles();
                        this.listLoading = false;
                        this.$message({
                            message: error,
                            type: "error"
                        });
                    });
                }
            },
            batchImportData(item) {
                //首先判断文件类型
                let str = item.file.name.split(".");
                let format = str[str.length - 1];
                if (format != "xls" && format != "xlsx") {
                    this.$message({
                        message: "请选择.xls或.xlsx文件",
                        type: "error"
                    });
                } else {
                    this.listLoading = true;
                    let formData = new FormData();
                    formData.append("file", item.file);
                    formData.append("companyId", this.user.companyId);
                    this.http.uploadFile('/report/importData', formData,
                    res => {
                        this.$refs.upload.clearFiles();
                        this.listLoading = false;
                        if (res.code == "ok") {
                            this.$message({
                                message: "成功导入"+res.data+"名人员的工时数据",
                                type: "success"
                            });
                            this.getReportList();
                            this.importDialog = false;
                        } else {
                            this.$message({
                                message: res.msg,
                                type: "error"
                            });
                        }
                    },
                    error => {
                        this.$refs.upload.clearFiles();
                        this.listLoading = false;
                        this.$message({
                            message: error,
                            type: "error"
                        });
                    });
                }
            },
            userssHu() {
                this.http.post('/time-type/getCompanyTimeSetting',{ 
                    companyId: this.user.companyId
                },
                res => {
                    if (res.code == "ok") {
                        this.yonghuUser = res.data
                    } 
                },
                error => {
                    this.$message({
                        message: error,
                        type: "error"
                    });
                    }
                );
            },
            iptBlur(i) {
                if(this.isBatch == 0) {
                    return
                }
                var stat = this.workForm.createDate[0]
                var end = this.workForm.createDate[1]
                // this.jsDay = 10
                this.http.post('/report/getWorkDays',{ 
                    startDate: stat,
                    endDate: end
                },
                res => {
                    if (res.code == "ok") {
                        this.jsDay = res.data
                        this.chuji(i)
                    } 
                },
                error => {
                    this.$message({
                        message: error,
                        type: "error"
                    });
                    }
                );

                var sl = this.workForm.domains
                this.chuji(i)
            },
            chuji(i) {
                if(i == 0) {
                    this.seleChn(1)
                } else if(i == 1) {
                    this.seleChn(0)
                } else if(i == 2) {
                    if(this.workForm.domains[0].multiWorktime > 0) {
                        this.iptChangs()
                    } else {
                        this.iptChang()
                    }
                } else if(i == 3) {
                    this.seleChn(0)
                }
            },
            seleChn(e) {
                if(e == 1) {
                    for(var i in this.workForm.domains) {
                        if(this.workForm.domains[i].timeType == 0) {
                            this.workForm.domains[i].workingTime = 8
                        } else {
                            this.workForm.domains[i].workingTime = 4
                        }
                    }
                }
                var quanbu = 0 
                var spl = this.workForm.domains
                var zhi = ''
                for(var i in spl) {
                    var sp = +spl[i].workingTime + 0
                    zhi = this.jsDay * sp
                    quanbu = +quanbu + zhi
                }
                this.jsTime = quanbu
            },
            iptChang() {
                var sl = this.workForm.domains
                var quanbu = 0 
                var zhi = ''
                for(var i in sl) {
                    if(sl[i].startTime && sl[i].endTime) {
                        var date2 = '2021/12/12 ' + sl[i].endTime +':00'
                        var date1 = '2021/12/12 ' + sl[i].startTime +':00'
                        var date3 = new Date(date2).getTime() - new Date(date1).getTime();
                        var leave1=date3%(24*3600*1000)
                        var hours=Math.floor(leave1/(3600*1000))
                        var leave2=leave1%(3600*1000)
                        var minutes=Math.floor(leave2/(60*1000))
                        var shi = hours+'.'+ minutes
                        var sll = +shi + 0
                        zhi = this.jsDay * sll
                        quanbu = +quanbu + zhi
                    }
                }
                this.jsTime = quanbu
            },
            iptChangs() {
                var sl = this.workForm.domains
                var quanbu = 0 
                var zhi = ''
                for(var i in sl) {
                    for(var j in sl[i].worktimeList){
                        if(sl[i].worktimeList[j].startTime && sl[i].worktimeList[j].endTime) {
                            var date2 = '2021/12/12 ' + sl[i].worktimeList[j].endTime +':00'
                            var date1 = '2021/12/12 ' + sl[i].worktimeList[j].startTime +':00'
                            var date3 = new Date(date2).getTime() - new Date(date1).getTime();
                            var leave1=date3%(24*3600*1000)
                            var hours=Math.floor(leave1/(3600*1000))
                            var leave2=leave1%(3600*1000)
                            var minutes=Math.floor(leave2/(60*1000))
                            var shi = hours+'.'+ minutes
                            var sll = +shi + 0
                            zhi = this.jsDay * sll
                            quanbu = +quanbu + zhi
                        }
                    }
                }
                this.jsTime = quanbu
            },
            removeTimeItem(item, index) {
                item.worktimeList.splice(index, 1);
                this.iptChangs()
            },
            //添加工时
            addNewWorktime(index, item) {
                if(item.worktimeList == null ) {
                    item.worktimeList = []
                }
                item.worktimeList.push({});
            },

            //复制项目
            copyProject(index) {
                var leftProgress = 10;
                if (this.reportTimeType.type == 3) {
                    //计算已经待分配工时比例
                    let array = this.workForm.domains;
                    let totalProgress = 0;
                    for (var i=0;i<array.length; i++) {
                        totalProgress += array[i].progress;
                    }
                    if (totalProgress < 100) {
                        leftProgress = 100 - totalProgress;
                    }
                }
                var newIndex = index+1;
                var itemDomain = {
                        projectId: this.workForm.domains[index].projectId,
                        workingTime: this.reportTimeType.type == 3?(leftProgress*this.reportTimeType.allday/100).toFixed(1):"",
                        content: "",
                        progress:leftProgress,
                        state:2,//2-表示待提交
                };
                this.workForm.domains.splice(newIndex, 0,itemDomain);
                
                if (this.reportTimeType.type == 0) {
                    //全天上下午模式下，检测时间段数量，达到2个，不能再加了
                    var length = this.workForm.domains.length;
                    if (length == 2) {
                        this.showAddMore = false;
                    }
                }

                this.selectProject(itemDomain, newIndex);
            },
            //导出员工每日填报工时数
            exportMembWorkHours() {
                this.http.post('/report/exportUserDailyWorkTime',{ 
                        month: this.date
                    },
                    res => {
                        if (res.code == "ok") {
                            var url = res.data;
                            this.downloadByA("人员每日工时统计.xls", url);
                        } 
                    },
                    error => {
                        this.$message({
                            message: error,
                            type: "error"
                        });
                        }
                    );
            },
            downloadByA(name, url) {
                const a = document.createElement('a'); // 创建a标签
                a.setAttribute('download', name);// download属性
                a.setAttribute('href', url);// href链接
                a.click();// 自执行点击事件
                a.remove();
            },
            showMonthWorkTime() {
                this.monthWorkTimeDialog = true;
                this.http.post('/report/getUserDailyWorkTime',{ 
                        month: this.date
                    },
                    res => {
                        if (res.code == "ok") {
                            this.monthWorkData = res.data.list;
                            this.$forceUpdate();
                        } 
                    },
                    error => {
                        this.$message({
                            message: error,
                            type: "error"
                        });
                        }
                    );
            },
            onProgressChange() {
                this.$forceUpdate();
            },
            showChooseMembTree() {
                this.chosenMembCount = this.participator.length;
                this.chooseParticipVisible = true;
            },
            onTreeItemChange() {
                var chosenList = this.$refs.chooseMembTree.getCheckedNodes();
                var list = chosenList.filter(item=>item.isUser == 1);
                this.chosenMembCount = list.length;
            },
            findUserInTree() {
                if (this.filterName == '') {
                    this.deptMembData = this.allMembData;
                } else {
                    var list = this.findRecursively(this.filterName, this.allMembData);
                    this.deptMembData = list;
                }
            },

            findRecursively(username, list) {
                var filterList = [];
                for (var i=0;i<list.length; i++) {
                    if (list[i].isUser == 1) {
                        if (list[i].label.indexOf(username) >= 0) {
                            //匹配上了
                            filterList.push(list[i]);
                        }
                    } else if (list[i].children != null && list[i].children.length > 0) {
                        var subList = this.findRecursively(username, list[i].children);
                        if (subList.length > 0) {
                            subList.forEach(s=>filterList.push(s));
                        }
                    }
                }
                return filterList;
            },

            //确定选择参与人
            chooseParticip() {
                this.chooseParticipVisible = false;
                var chosenList = this.$refs.chooseMembTree.getCheckedNodes();
                this.chosenMembList = chosenList.filter(item=>item.isUser == 1);
                this.workForm.userNames = '';
                this.workForm.userId = [];
                this.participator = [];
                for (var i=0;i<this.chosenMembList.length; i++) {
                    this.workForm.userId.push(this.chosenMembList[i].id);
                    this.workForm.userNames += this.chosenMembList[i].label+',';
                    var item = {id:this.chosenMembList[i].id, name:this.chosenMembList[i].label};
                    this.participator.push(item);
                }
                if (this.workForm.userNames.length > 0) {
                    this.workForm.userNames = this.workForm.userNames.substring(0, this.workForm.userNames.length-1);
                }
                
            },

            //微信通知人员填写
            weixinNotify() {
                if (this.fillMembList.length == 0) return;
                var ids = '';
                this.fillMembList.forEach(f=>{
                    ids += f.id+',';
                })
                this.http.post('/user/pushFillReport',{ 
                        ids: ids, date: this.curDate
                    },
                    res => {
                        if (res.code == "ok") {
                            this.$message({
                                message: '已发送成功',
                                type: "success"
                            });
                        } 
                    },
                    error => {
                        this.$message({
                            message: error,
                            type: "error"
                        });
                        }
                    );
            },
            //导出人员列表
            exportMemb() {
                if (this.fillMembList.length == 0) return;
                var ids = '';
                this.fillMembList.forEach(f=>{
                    ids += f.id+',';
                })
                this.http.post('/user/exportMembList',{ 
                        ids: ids,isFill: this.isFill, date: this.curDate
                    },
                    res => {
                        if (res.code == "ok") {
                            var aTag = document.createElement('a');
                            aTag.download = this.curDate+(this.isFill?"已填":"未填")+"人员列表.xls";
                            aTag.href = res.data;
                            aTag.click();
                        } 
                    },
                    error => {
                        this.$message({
                            message: error,
                            type: "error"
                        });
                        }
                    );
            },
            showMembList(fill) {
                this.membListVisible = true;
                if (fill == 0) {
                    this.fillMembList = this.unFillList;
                    this.isFill = false;
                } else {
                    this.fillMembList = this.fillList;
                    this.isFill = true;
                }
            },
            //获取自己填写的日报状态
            getReportFillStatus() {
                this.http.post('/report/getReportFillStatus',{ 
                        startDate: this.date+"-01", endDate: this.date+"-31", userId: this.user.id
                    },
                    res => {
                        if (res.code == "ok") {
                            this.fillStatusList = res.data;
                            this.allDate.forEach(d=>{
                                var fillInfo = null;
                                d.state = null;
                                this.fillStatusList.forEach(s=>{
                                    var d1 = s.createDate.split('-')[2];
                                    var d2 = d.date.split('月')[1].split('日')[0];
                                    if (d1.indexOf('0') == 0) {
                                        d1 = d1.substring(1,d1.length);
                                    }
                                    
                                    if (d1 == d2) {
                                        d.state = s.state;
                                    }
                                })
                            })
                            this.$forceUpdate();
                        } 
                    },
                    error => {
                        this.$message({
                            message: error,
                            type: "error"
                        });
                        }
                    );
            },
            scrollFunction () {
                this.domObj = document.getElementById('clearfix') // 通过id获取要设置的div
                if (this.domObj.attachEvent) { // IE
                this.domObj.attachEvent('onmousewheel', this.mouseScroll)
                } else if (this.domObj.addEventListener) {
                this.domObj.addEventListener('DOMMouseScroll', this.mouseScroll, false)
                }
                this.domObj.onmousewheel = this.domObj.onmousewheel = this.mouseScroll
            },

            mouseScroll(event) { // google 浏览器下
                let detail = event.wheelDelta || event.detail
                let moveForwardStep = -1
                let moveBackStep = 1
                let step = 0
                step = detail > 0 ? moveForwardStep * 100 : moveBackStep * 100
                event.preventDefault() // 阻止浏览器默认事件
                this.domObj.scrollLeft = this.domObj.scrollLeft + step
            },

            // //左右滚动
            // wheel(e){
            //     var a = document.getElementById("dateScroll");
            //     var scroll_width = 80; //滚动一下的距离
            //     var e = e || window.event, v;
            //     e.wheelDelta ? v=e.wheelDelta : v=e.detail;
            //     if(v>3||-v>3) v=-v;
            //     v>0 ? a.scrollLeft+=scroll_width : a.scrollLeft-=scroll_width;
                
            //     e.preventDefault(); //阻止浏览器的默认滚动
            // },

            showExportDialog() {
                this.exportDialog = true;
            },
            changeAllTime() {
                //总时长发生改变，自动按比例计算
                this.workForm.domains.forEach(d=>{
                    d.workingTime = (d.progress*this.reportTimeType.allday/100).toFixed(1);
                });
            },

            // 是否加班的单机事件
            check() {
                this.selected = !this.selected
                this.isNew = this.selected
                
            },
            //项目选中了， 加载子项目
            selectProject(domain, index) {
                console.log(domain, index, '加载')
                this.http.post('/sub-project/list',{
                    projectId: domain.projectId
                },
                res => {
                    if (res.code == "ok") {
                        this.workForm.domains[index].subProjectList = res.data;
                        this.$forceUpdate();
                    } 
                },
                error => {
                    this.$message({
                        message: error,
                        type: "error"
                    });
                    }
                );
                //项目相关的近期任务
                if (this.user.company.packageProject == 1) {
                    this.http.post('/task/getRecentTask',{ 
                        projectId: domain.projectId,
                        isSubstitude:this.isSubstitude?1:0
                    },
                    res => {
                        if (res.code == "ok") {
                            this.workForm.domains[index].allTaskList = res.data;
                            this.workForm.domains[index].taskList = res.data;
                            this.$forceUpdate();
                        } 
                    },
                    error => {
                        this.$message({
                            message: error,
                            type: "error"
                        });
                        }
                    );
                }
                //获取项目相关专业
                if (this.user.company.packageEngineering == 1) {
                    this.getProjectProfessions(domain, index);
                }
                //获取项目相关的任务阶段
                if (this.user.company.packageProject == 1) {
                    this.getProjectStages(domain, index);
                }
                // 获取项目相关的维度
                this.dimension(domain, index)
            },
            // 获取维度数据
            dimension(domain, index) {
                if(domain.projectId == '') {
                    return
                }
                this.http.post('/project/getDegreeList',{ 
                    projectId: domain.projectId,
                },
                res => {
                    if (res.code == "ok") {
                        this.workForm.domains[index].wuduList = res.data
                        // this.workForm = this.workForm
                        this.$forceUpdate()
                    } 
                },
                error => {
                    this.$message({
                        message: error,
                        type: "error"
                    });
                    }
                );
            },
            //切换任务阶段
            changeStages(domain, index) {
                if (domain.stage == null || domain.stage == '') {
                    this.workForm.domains[index].taskList = this.workForm.domains[index].allTaskList;
                } else {
                    this.workForm.domains[index].taskList = this.workForm.domains[index].allTaskList.filter(t=>t.stagesName == domain.stage);
                }
            },

            getProjectStages(domain, index) {
                this.http.post("/stages/getProjectStages", {projectId: domain.projectId},
                    res => {
                        if (res.code == "ok") {
                            this.workForm.domains[index].stages = res.data;
                            this.$forceUpdate();
                        }
                    },
                    error => {
                        this.$message({
                            message: error,
                            type: "error"
                        });
                    });
            },

            getProjectProfessions(domain, index) {
                this.http.post("/project-profession/getMyProfession", {projectId: domain.projectId},
                    res => {
                        if (res.code == "ok") {
                            this.workForm.domains[index].professionProgress = res.data;
                            this.$forceUpdate();
                        }
                    },
                    error => {
                        this.$message({
                            message: error,
                            type: "error"
                        });
                    });
            },
            //删除自己的日报
           deleteReport() {
               this.$confirm("确定要删除该日报吗?","提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                })
                .then(() => {
                    this.listLoading = true;
                    this.http.post('/report/delete',{ 
                        userId: this.user.id,
                        date: this.workForm.createDate
                    },
                    res => {
                        this.listLoading = false;
                        if (res.code == "ok") {
                            this.$message({
                                message: "删除成功",
                                type: "success"
                            });
                            this.getReportList();
                            this.getDepartment();
                            this.dialogVisible = false;
                        } else {
                            this.$message({
                                message: res.msg,
                                type: "error"
                            });
                        }
                    },
                    error => {
                        this.listLoading = false;
                        this.$message({
                            message: error,
                            type: "error"
                        });
                        }
                    );
                })
                .catch(() => {});
                
           },
            // 管理员删除日报
            guanli(item) {
                
                let day = (this.choseDay + 1) > 9 ? "-" + (this.choseDay + 1) : "-0" + (this.choseDay + 1);
                let param = {date: this.date + day, userId: item.id};
                
                this.$confirm("确定要删除该日报吗?","提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                })
                .then(() => {
                    this.listLoading = true;
                    this.http.post('/report/delete',param,
                    res => {
                        this.listLoading = false;
                        if (res.code == "ok") {
                            this.$message({
                                message: "删除成功",
                                type: "success"
                            });
                            this.getReportList();
                            this.getDepartment();
                            this.dialogVisible = false;
                        } else {
                            this.$message({
                                message: res.msg,
                                type: "error"
                            });
                        }
                    },
                    error => {
                        this.listLoading = false;
                        this.$message({
                            message: error,
                            type: "error"
                        });
                        }
                    );
                })
                .catch(() => {});
            },
            //提交批量审核数据
            submitBatchApprove() {
                var data = this.$refs.approveTree.getCheckedNodes();
                var ids = '';
                if (data.length == 0) {
                    this.$message({
                            message: '请选择要审核的人员',
                            type: "error"
                        });
                    return;
                }
                for (var i=0;i<data.length; i++) {
                    ids += data[i].id;
                    if (i < data.length-1) {
                        ids += ',';
                    }
                }
                let day = (this.choseDay+1) > 9 ? "-" + (this.choseDay + 1) : "-0" + (this.choseDay + 1);
                
                this.http.post("/report/batchApproveReport", {ids:ids, date:this.date + day},
                res => {
                    if (res.code == "ok") {
                        this.$message({
                            message: '审核成功',
                            type: "success"
                        });
                        this.getReportList();
                        this.getDepartment();
                        this.approveDialogVisible = false;
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },
            selectAll() {
                if (this.isAllSelect) {
                    var keys = [];
                    this.reportNames.forEach(b=>{
                        keys.push(b.id);
                    })
                    this.$refs.approveTree.setCheckedKeys(keys);
                } else {
                    this.$refs.approveTree.setCheckedKeys([]);
                }
            },
            //批量审核
            batchApprove() {
                this.approveDialogVisible = true;
                
                this.reportNames = [];
                for (var i=0;i<this.reportList.length; i++) {
                    var report = this.reportList[i];
                    var hasUnChecked =false;
                    var id = '';
                    for (var j=0;j<report.data.length; j++) {
                        if (report.data[j].state == 0 
                            && (this.user.company.packageEngineering==0 || (this.user.company.packageEngineering==1 && report.data[j].departmentAuditState == 1))
                            && (this.user.role == 1 || this.user.role == 2 || report.data[j].inchargerId == this.user.id)) {
                            hasUnChecked = true;
                            id += report.data[j].id+',';
                        }
                    }
                    if (hasUnChecked) {
                        this.reportNames.push({id:id, label: report.name});
                    }
                }
            },
            removeEmptyNode(list) {
                for (var i=0;i<list.length;i++) {
                    var cnt = 0;
                    if (list[i].membCount == 0) {
                        list.splice(i, 1);
                        i--;
                    } else if (list[i].children != null) {
                        this.removeEmptyNode(list[i].children);
                    }
                }
            },
            calculateMembCount(list) {
                for (var i in list) {
                    var cnt = 0;
                    if (list[i].children != null) {
                        this.calculateMembCount(list[i].children);
                        for (var m in list[i].children) {
                            cnt += list[i].children[m].membCount;
                        }
                    }
                    
                    if (list[i].isUser == 1) {
                        cnt++;
                        this.membCount++;
                    } 
                    list[i].membCount = cnt;
                }
            },
            stateChange() {
                this.membCount = 0;
                if (this.selectState == -1) {
                    //全部状态
                    this.data = this.allData;
                } else {
                    //未填报
                    var newData = JSON.parse(JSON.stringify(this.allData));
                    this.filterState(this.selectState, newData);
                    this.data = newData;
                }
                this.calculateMembCount(this.data);
                this.data[0].membCount = this.membCount;//总人数
            },
            //按状态过滤部门人员
            filterState(state, list) {
                for (var i =0;i<list.length; i++) {
                    var obj = list[i];
                    if (obj.isUser == 1) {
                        var match = false;
                        if (state == -2) {
                            if (obj.state == null) {
                                match = true;
                            }
                        } else {
                            if (obj.state == state) {
                                match = true;
                            }
                        }
                        if (!match) {
                            list.splice(i, 1);
                            i--;
                        } else {
                        }
                    } else {
                        if (obj.children != null) {
                            this.filterState(state, obj.children);
                        }
                    }
                }
            },
            // 部门列表点击
            handleNodeClick(data) {
                this.depData = data;
                var list = [];
                if (data.id == -1) {
                    this.deptId = null;
                    this.targetUid = null;
                    list = this.data;
                } else if (data.isUser == 1) {
                    this.deptId = null;
                    this.targetUid = data.id;
                } else {
                    this.deptId = data.id;
                    this.targetUid = null;
                    list.push(data);
                }
                this.getReportList();
                if (list.length > 0) {
                    this.unFillList = this.getUserMembListFromDeptList(list, 0);
                    this.fillList = this.getUserMembListFromDeptList(list, 1);
                } 
                
            },

            //获取可以选择的代填的人员列表
            getSubstitudeUserDeptList() {
                if (this.deptMembData.length == 0) {
                    this.http.post("/department/listMyMembs", {},
                        res => {
                            if (res.code == "ok") {
                                let noAllData = JSON.parse(JSON.stringify(res.data));
                                if (noAllData.length > 0) {
                                    if (noAllData[0].label == '全部人员') {
                                        noAllData.splice(0,1);
                                    }
                                }
                                this.setUserToDept(noAllData);
                                this.deptMembData = noAllData;
                            } else {
                                this.$message({
                                    message: res.msg,
                                    type: "error"
                                });
                            }
                        },
                        error => {
                            this.$message({
                                message: error,
                                type: "error"
                            });
                        });
                }
            },
            
            // 获取部门列表
            getDepartment() {
                let day = (this.choseDay+1) > 9 ? "-" + (this.choseDay + 1) : "-0" + (this.choseDay + 1);
                var param = {date:this.date + day};
                if (this.user.manageDeptId != 0 && this.user.role < 2) {
                    param.manageDeptId = this.user.manageDeptId;
                }
                this.http.post("/report/getMembList", param,
                res => {
                    if (res.code == "ok") {
                        var list = res.data , list1 = JSON.parse(JSON.stringify(res.data));
                        // let noAllData = JSON.parse(JSON.stringify(res.data));
                        // if (this.user.role > 0) {
                            
                        // }
                        list.splice(0,0,{
                                id: -1,
                                label: '全部人员',
                            })
                        this.membCount = 0;
                        //设置员工到部门下面
                        this.setUserToDept(list);
                        this.data = list;
                        this.allData = list;
                        
                        // if (noAllData.length > 0) {
                        //     if (noAllData[0].label == '全部人员') {
                        //         noAllData.splice(0,1);
                        //     }
                        // }
                        // this.setUserToDept(noAllData);
                        // this.deptMembData = noAllData;

                        this.option = this.changeArr(list1);
                        list[0].membCount = this.membCount;
                        if (this.depData.id == -1) {
                            this.depData.membCount = this.membCount;
                            this.unFillList = this.getUserMembListFromDeptList(this.data, 0);
                            this.fillList = this.getUserMembListFromDeptList(this.data, 1);
                        } else {
                            if (this.depData.isUser == null) {
                                var dep = this.findTargetDept(this.data, this.depData.id);
                                var membDeptList = [];
                                membDeptList.push(dep);
                                this.unFillList = this.getUserMembListFromDeptList(membDeptList, 0);
                                this.fillList = this.getUserMembListFromDeptList(membDeptList, 1);
                            }
                        }
                        if (this.depData.isUser == null) {
                            if (this.isFill) {
                                this.fillMembList = this.fillList;
                            } else {
                                this.fillMembList = this.unFillList;
                            }
                        }
                        
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });

                this.getReportFillStatus();
            },

            findTargetDept(list, deptId) {
                var t = null;
                for (var i=0;i<list.length; i++) {
                    if (list[i].isUser == null && list[i].id == deptId) {
                        t = list[i];
                        break;
                    }
                }
                if (t == null) {
                    for (var i=0;i<list.length; i++) {
                        if (list[i].children != null && list[i].children.length > 0) {
                            t = this.findTargetDept(list[i].children, deptId);
                            if (t != null) {
                                break;
                            }
                        }
                    }
                }
                return t;
            },

            getUserMembListFromDeptList(list, isFill) {
                var membList = [];
                for (var i in list) {
                    var deptName = list[i].label;
                    if (list[i].userList != null) {
                        list[i].userList.forEach(element => {
                            if (isFill == 0) {
                                //获取未填的
                                if (element.state == null) {
                                    var obj = {id: element.id, label:element.name, deptId:element.departmentId, deptName: deptName};
                                    membList.push(obj);
                                }
                            } else {
                                if (element.state != null) {
                                    var obj = {id: element.id, label:element.name, deptId:element.departmentId, deptName: deptName};
                                    membList.push(obj);
                                }
                            }
                            
                        });
                    }

                    if (list[i].children != null) {
                        membList = membList.concat(this.getUserMembListFromDeptList(list[i].children, isFill));
                    }
                }

                return membList;
            },

            setUserToDept(list) {
                for (var i in list) {
                    var cnt = 0;
                    if (list[i].children != null) {
                        this.setUserToDept(list[i].children);
                        for (var m in list[i].children) {
                            cnt += list[i].children[m].membCount;
                        }
                    }
                    
                    if (list[i].userList != null) {
                        if (list[i].children == null) {
                            list[i].children = [];
                        }
                        list[i].userList.forEach(element => {
                            var obj = {id: element.id, label:element.name, state:element.state, parentId:element.departmentId, isUser:1};
                            list[i].children.push(obj);
                            this.membCount++;
                            cnt++;
                        });
                    }
                    list[i].membCount = cnt;
                }
            },

            // 修改数组
            changeArr(arr) {
                for (var i = 0; i < arr.length; i++) {
                    if(arr[i].id != -1 && arr[i].id != 0) {
                        if (arr[i].children != null && arr[i].children.length>0) {
                            arr[i].children = this.changeArr(arr[i].children);
                        }
                        arr[i].id && (arr[i].value = arr[i].id);
                        delete arr[i].id;
                    }
                }
                for(var i in arr) {
                    if(arr[i].id == -1 || arr[i].id == 0) {
                        arr.splice(i,1)
                    }    
                }
                return arr;
            },
            //时间段范围设置改动，监听
            onTimeTypeChange(timeType) {
                this.seleChn(1)
                this.showAddMore = true;
                for(var i in this.workForm.domains) {
                    if (this.workForm.domains[i].timeType == 0) {
                        this.showAddMore = false;
                        break;
                    }
                }
                if (this.showAddMore) {
                    //检测数量
                    if (this.workForm.domains.length == 2) {
                        this.showAddMore = false;
                    } else {
                        this.showAddMore = true;
                    }
                }
            },
            getTimeType() {
                this.http.post('/time-type/getCompanyTimeSetting', { companyId: this.user.companyId},
                    res => {
                        if (res.code == "ok") {
                            var t = res.data;
                            this.reportTimeType = t;
                            if (this.reportTimeType.type > 0) {
                                this.showAddMore = true;
                            }
                            //转化时间格式
                            if (t.allday != null) {
                                this.timeType.push({value:0, label:'全天 - '+t.allday+'小时', hours:t.allday});
                            }
                            if (t.am != null) {
                                this.timeType.push({value:1, label:'上午 - '+t.am+'小时', hours: t.am});
                            }
                            if (t.pm != null) {
                                this.timeType.push({value:2, label:'下午 - '+t.pm+'小时', hours: t.pm});
                            }
                        } else {
                            this.$message({
                                message: res.msg,
                                type: "error"
                            });
                        }
                    },
                    error => {
                        this.listLoading = false;
                        this.$message({
                            message: error,
                            type: "error"
                        });
                    });
            },  
            // 改变月份
            changeMonthOut() {
                this.getAllDate();
                this.getReportList();
                this.getDepartment();
            },

            // 选择日期
            choseDate(i, item) {
                this.choseDay = i;
                let day = (this.choseDay +1)> 9 ? "-" + (this.choseDay + 1) : "-0" + (this.choseDay + 1);
                sessionStorage.msg = this.date + day,
                this.getReportList();
                this.getDepartment();
                this.curDate = item.date;
            },

            // 获取日期列表
            getAllDate() {
                var dayArry = [];
                var day = this.getCountDays();
                let curMonthDay = null;
                for (var k = 1; k <= day; k++) {
                    var str = new Date(this.date.replace(/-/g, "/")+'/01').getMonth() + 1 + "月" + k+'日';
                    var showStr = new Date(this.date.replace(/-/g, "/")+'/01').getMonth() + 1+'.'+k;
                    if ( new Date(this.date.replace(/-/g, "/")+'/01').getFullYear() == new Date(new Date()).getFullYear() &&
                    new Date(this.date.replace(/-/g, "/")+'/01').getMonth() == new Date(new Date()).getMonth()) {
                        if(sessionStorage.msg) {
                            if(parseInt(sessionStorage.msg.split("-")[2]) == k) {
                                this.choseDay = k - 1;
                                curMonthDay = str;
                            }
                        } else {
                            if (new Date().getDate() == k) {
                                this.choseDay = k - 1;
                            }   
                        }
                    } else {
                        this.choseDay = 0;
                    }
                    var curDateStr = (this.date +'-'+ (k<10?('0'+k):k));
                    var curDateTime = util.formatDate.parse(curDateStr, 'yyyy-MM-dd');
                    dayArry.push({date:str, weekDay:this.weekDay[curDateTime.getDay()], showDate:showStr});
                }
                this.allDate = dayArry;
                //不能超过最大日期
                if (this.choseDay > day-1) {
                    this.choseDay = day-1;
                }
                //从消息点击跳转过来的，直接加载指定日期
                if (sessionStorage.from == 1 && sessionStorage.msg) {
                    this.curDate = sessionStorage.msg;
                    sessionStorage.from = 0;
                } else {
                    if (curMonthDay != null) {
                        this.curDate = curMonthDay;
                    } else {
                        var d = new Date(this.date.replace(/-/g, "/")+'/01')
                        this.curDate = (d.getMonth()+1)+'月'+d.getDate()+'日';  
                    }
                }
                this.getReportFillStatus();
            },

            getCountDays() {
                var newstr = this.date.replace(/-/g, "/");
                var curDate = new Date(newstr+'/01');
                var curMonth = curDate.getMonth();
                curDate.setMonth(curMonth + 1);
                curDate.setDate(0);
                return curDate.getDate();
            },

            //获取日报列表
            getReportList() {
                this.listLoading = true;
                let day = (this.choseDay + 1) > 9 ? "-" + (this.choseDay + 1) : "-0" + (this.choseDay + 1);
                let param = {date: this.date + day};
                if (this.deptId != null) {
                    param.deptId = this.deptId;
                }
                if (this.targetUid != null) {
                    param.userId = this.targetUid;
                }
                this.http.post( this.port.report.list, param,
                res => {
                    this.listLoading = false;
                    if (res.code == "ok") {
                        this.reportList = res.data;
                        document.querySelector("#day"+this.choseDay).scrollIntoView(true);
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.listLoading = false;
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },

            //导出日报
            exportReport() {
                this.listLoading = true;
                var param = {};
                if (this.exportParam.dateRange != null) {
                    param = {startDate:this.exportParam.dateRange[0], endDate: this.exportParam.dateRange[1]};
                }
                if (this.exportParam.projectId != null) {
                    param.projectId = this.exportParam.projectId;
                }
                this.http.post( this.port.report.export, param,
                res => {
                    this.listLoading = false;
                    if (res.code == "ok") {
                        location.href = res.data;
                        this.exportDialog = false;
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.listLoading = false;
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },

            //获取项目列表
            getProjectList() {
                this.listLoading = true;
                this.http.post( this.port.project.list, {},
                res => {
                    this.listLoading = false;
                    if (res.code == "ok") {
                        this.projectList = res.data;
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.listLoading = false;
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },

            // 获取个人某天的日报
            getReport() {
                this.http.post( this.port.report.getPort, {
                    date: this.workForm.createDate
                },
                res => {
                    if (res.code == "ok") {
                        var quanbu = 0 
                        this.jsDay = 1
                        var zhi = ''
                        var slp = res.data.report
                        for(var i in slp) {
                            var sp = +slp[i].workingTime + 0
                            zhi = this.jsDay * sp
                            quanbu = +quanbu + zhi
                        }
                        this.jsTime = quanbu
                        var list = res.data;
                        this.report = list;
                        if(list.report.length != 0) {
                            var arr = [];
                            this.canEdit = false;
                            for(var i in list.report) {
                                var flg = null
                                list.report[i].isOvertime == 1 ? flg = true : flg = false
                                // var srr = []
                                // if(list.report[i].degreeId != null) {
                                //     var a = list.report[i].degreeId + ''
                                //     var ace = a.split('')
                                //     for(var b in ace) {
                                //         var nnm = +ace[b] + 0
                                //         srr.push(nnm)
                                //     }
                                // }
                                
                                arr.push({
                                    id: list.report[i].id,
                                    projectId: list.report[i].projectId,
                                    workingTime: list.report[i].workingTime,
                                    content: list.report[i].content,
                                    state: list.report[i].state,
                                    timeType: list.report[i].timeType,
                                    subProjectList: list.report[i].subProjectList,
                                    taskList: list.report[i].taskList,
                                    subProjectId: list.report[i].subProjectId,
                                    taskId: list.report[i].taskId,
                                    // startTime: `Fri May 16 2021 ${list.report[i].startTime}:12 GMT+0800 (中国标准时间)`,
                                    startTime: list.report[i].startTime,
                                    // endTime: `Fri May 16 2021 ${list.report[i].endTime}:12 GMT+0800 (中国标准时间)`,
                                    endTime: list.report[i].endTime,
                                    isOvertime: flg,
                                    progress:list.report[i].progress,
                                    professionProgress: list.report[i].professionProgressList,
                                    stages:list.report[i].stages,
                                    stage:list.report[i].stage,
                                    pics: list.report[i].pics,
                                    multiWorktime: list.report[i].multiWorktime,
                                    worktimeList: list.report[i].worktimeList,
                                    degreeId: list.report[i].degreeId,
                                    wuduList: list.report[i].degreeList,
                                })
                                if (list.report[i].state >= 2) {
                                    this.canEdit = true;
                                }
                            }
                            this.workForm = {
                                createDate: this.workForm.createDate,
                                domains: arr,
                                userNames:null,
                                userId:null,
                            }
                        } else {
                            this.workForm = {
                                createDate: this.workForm.createDate,
                                domains: [{
                                    id: null,
                                    projectId: "",
                                    workingTime: this.reportTimeType.type==3?(this.reportTimeType.allday).toFixed(1):"",
                                    content: "",
                                    progress:100,
                                    state: 2,
                                    timeType:0,
                                    multiWorktime: this.reportTimeType.multiWorktime,
                                    worktimeList:[{}],
                                }],
                                userId:null,
                                userNames:null,
                            }
                            this.canEdit = true;
                        }
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },
            guanbi() {
                this.falsss = false
            },
            // wuduLists(id) {
            //     this.http.post('/project/getDegreeList',{ 
            //         projectId: id,
            //     },
            //     res => {
            //         if (res.code == "ok") {
            //             return res.data
            //         } 
            //     },
            //     error => {
            //         this.$message({
            //             message: error,
            //             type: "error"
            //         });
            //         }
            //     );
            // },

            // 打开日报填写
            fillInReport(i, isBatch) {
                if(i != 1) {
                    this.falsss = false 
                } else {
                    this.falsss = true
                }
                if (this.isSubstitude) {
                    this.getSubstitudeUserDeptList();
                }
                if(i == -1 || this.isSubstitude) {
                    this.isDisable = false;
                } else {
                    this.isDisable = true;
                }
                let day = (this.choseDay + 1) > 9 ? "-" + (this.choseDay + 1) : "-0" + (this.choseDay + 1);
                this.isBatch = isBatch;
                if (this.isBatch == 0 && !this.isSubstitude) {
                    this.workForm.createDate = this.date + day; // 获取个人某天的日报
                    this.getReport(i);
                } else {
                    this.workForm = {
                                createDate: null,//批量填报没有日期
                                domains: [{
                                    id: null,
                                    projectId: "",
                                    workingTime: this.reportTimeType.type==3?(this.reportTimeType.allday).toFixed(1):"",
                                    content: "",
                                    progress:100,
                                    state: 2,
                                    timeType:0,
                                    multiWorktime: this.reportTimeType.multiWorktime,
                                    worktimeList:[{}],
                                }],
                            }
                    this.canEdit = true;
                }
                
                this.dialogVisible = true;
                
            },
            // 按周填报里内容的填写
            tianxies(item, i, names, row) {
                console.log(item, i, names, row[0], '你好')
                var idd = ''
                var obj = {}
                for(var l in this.projectList) {
                    if(this.projectList[l].projectName == names) idd = this.projectList[l].id
                }
                obj.projectId = idd
                this.selectProject(obj, 0)
                console.log(this.workForm.domains[0], '打印出来的')
                this.tianxieDialogVisible = true
                this.scopess = item
                var sss = {}
                sss.con = item.con
                sss.progress = item.progress
                sss.time = item.time
                sss.workingTime = item.workingTime
                var that = this
                setTimeout(() =>{
                    if(Object.keys(item).length < 5) {
                        console.log(456)
                        sss.subProjectId = that.workForm.domains[0].subProjectId
                        sss.stage = that.workForm.domains[0].stage
                        sss.subProjectList = that.workForm.domains[0].subProjectList
                        sss.stages = that.workForm.domains[0].stages
                    } else {
                        console.log(123)
                        sss.subProjectId = item.subProjectId
                        sss.stage = item.stage
                        sss.subProjectList = item.subProjectList
                        sss.stages = item.stages
                    }
                    console.log(sss, '数据')
                    that.zhoBaoIdx = i
                    that.zhoBaoName = names
                    that.zhoBao = sss
                    that.zhis = row
                },200);
                // if(Object.keys(sss).length <= 4) {
                //     sss.subProjectId = this.workForm.domains[0].subProjectId
                //     sss.stage = this.workForm.domains[0].stage
                //     sss.subProjectList = this.workForm.domains[0].subProjectList
                //     sss.stages = this.workForm.domains[0].stages
                // } else {
                //     sss.subProjectId = item.subProjectId
                //     sss.stage = item.stage
                //     sss.subProjectList = item.subProjectList
                //     sss.stages = item.stages
                // }
                // console.log(sss, '数据')
                // this.zhoBaoIdx = i
                // this.zhoBaoName = names
                // this.zhoBao = sss
                // this.zhis = row
                // this.selectProject(row[0], i)
            },
            // 按周填报里内容的填写点击确定
            btnTianxiaes() {
                this.tianxieDialogVisible = false
                var zhong = this.zhoData
                zhong[this.zhoBaoIdx][this.zhoBaoName] = this.zhoBao
                this.zhoData = zhong
                if(this.reportTimeType.type == 1) this.zhoXuan(this.zhoBao, this.zhoBaoIdx)
                if(this.reportTimeType.type == 2) this.zhoTimes(this.zhoBao, this.zhoBaoIdx)
                if(this.reportTimeType.type == 3) this.addBli(this.zhoBao, this.zhoBaoIdx)
            },
            // 获取本周
            getCurrentWeek() {
                const currentDate = new Date()
                const week = currentDate.getDay()
                const millisecond = 1000 * 60 * 60 * 24
                const minusDay = week != 0 ? week - 1 : 4
                const monday = new Date(currentDate.getTime() - minusDay * millisecond)
                const sunday = new Date(monday.getTime() + 4 * millisecond)
                var stat = this.dealdate(monday)
                var end = this.dealdate(sunday)
                this.zhoRqi = [stat, end]
                this.zhoRqis()
                this.jiazai()
            },
            // 获取上周
            handleGetPrevWeek() {
                const Time = new Date(this.zhoRqi[0])
                let weekNum = Time.getDay() 
                weekNum = weekNum == 0 ? 7 : weekNum
                let lastDate = new Date(Time.getTime() - weekNum * 24 * 60 * 60 * 1000)
                let fitstDate = new Date(
                    Time.getTime() - (weekNum + 6) * 24 * 60 * 60 * 1000
                )
                let startDate = `${fitstDate.getFullYear()}-${
                    fitstDate.getMonth() + 1 < 10
                    ? '0' + (fitstDate.getMonth() + 1)
                    : fitstDate.getMonth() + 1
                }-${
                    fitstDate.getDate() < 10
                    ? '0' + fitstDate.getDate()
                    : fitstDate.getDate()
                }`
                let endDate = `${lastDate.getFullYear()}-${
                    lastDate.getMonth() + 1 < 10
                    ? '0' + (lastDate.getMonth() + 1)
                    : lastDate.getMonth() + 1
                }-${
                    lastDate.getDate() < 10 ? '0' + lastDate.getDate() : lastDate.getDate()
                }`
                var stat = this.dealdate(startDate)
                var ends = this.dealdate(endDate)
                var end = this.dateChange(-2, ends)
                this.zhoRqi = [stat, end]
                this.zhoRqis()
                this.jiazai()
            },
            // 获取下周
            handleGetNextvWeek() {
                const Time = new Date(this.zhoRqi[1])
                let weekNum = Time.getDay()
                weekNum = weekNum == 0 ? 7 : weekNum

                let fitstDate = new Date(
                    Time.getTime() + (7 - weekNum + 1) * 24 * 60 * 60 * 1000
                )
                let lastDate = new Date(
                    Time.getTime() + (7 - weekNum + 7) * 24 * 60 * 60 * 1000
                )
                let startDate = `${fitstDate.getFullYear()}-${
                    fitstDate.getMonth() + 1 < 10
                    ? '0' + (fitstDate.getMonth() + 1)
                    : fitstDate.getMonth() + 1
                }-${
                    fitstDate.getDate() < 10
                    ? '0' + fitstDate.getDate()
                    : fitstDate.getDate()
                }`
                let endDate = `${lastDate.getFullYear()}-${
                    lastDate.getMonth() + 1 < 10
                    ? '0' + (lastDate.getMonth() + 1)
                    : lastDate.getMonth() + 1
                }-${
                    lastDate.getDate() < 10 ? '0' + lastDate.getDate() : lastDate.getDate()
                }`
                var stat = this.dealdate(startDate)
                var ends = this.dealdate(endDate)

                var end = this.dateChange(-2, ends)
                this.zhoRqi = [stat, end]
                this.zhoRqis()
                this.jiazai()
            },
            // 新增日期
            newDates() {
                console.log(this.zhoRqi, '看卡')
                this.zhoRqi[1] = this.dateChange(1, this.zhoRqi[1])
                console.log(this.zhoRqi[1])
                var obj = {}
                obj.zhoDataTime = this.zhoRqi[1]
                obj.he = 0
                for(var j in this.projectList) {
                    var xinzhi = this.projectList[j].projectName 
                    obj[xinzhi] = {}
                    obj[xinzhi].time = ''
                    obj[xinzhi].con = ''
                    obj[xinzhi].progress = 0
                    obj[xinzhi].workingTime = 0
                }
                this.zhoData.push(obj)
            },
            // 减去时间
            dateChange(num = 1,date = false) {
            　　if (!date) {
            　　　　date = new Date();//没有传入值时,默认是当前日期
            　　　　date = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
            　　}
            　　date += " 00:00:00";//设置为当天凌晨12点
            　　date = Date.parse(new Date(date))/1000;//转换为时间戳
            　　date += (86400) * num;//修改后的时间戳
            　　var newDate = new Date(parseInt(date) * 1000);//转换为时间
                var nian = newDate.getFullYear()
                var yue = ''
                var ri = ''
                var yues = (newDate.getMonth() + 1)
                var ris = newDate.getDate()
                yues > 9 ? yue = yues : yue = '0' + yues
                ris > 9 ? ri = ris : ri = '0' + ris
                return nian +'-'+yue+'-'+ri
            },
            // 加载动画 
            jiazai() {
                this.zhoLoading = true
                var that = this
                setTimeout(() =>{
                    that.zhoLoading = false
                },1000);
            },
            // 转时间格式
            dealdate(date) {
                const dt = new Date(date)
                const y = dt.getFullYear()
                const m = (dt.getMonth() + 1 + '').padStart(2, '0')
                const d = (dt.getDate() + '').padStart(2, '0')
                return `${y}-${m}-${d}`
            },
            // 按周填报
            fillInReportss() {
                window.addEventListener('scroll', this.handleScroll, true)
                this.jiazai()
                this.diasZho = true
                this.getCurrentWeek()
            },
            handleScroll() {
                this.changdu = this.projectList.length + 1
            },
            // 自动选择时间点的事件
            zhoTimes(item, i, ims, event) {
                var iss = i
                if(item.time == null) {
                    return
                } else {
                    var zhi = this.zhoData[iss]
                    var he = 0
                    for(var i in zhi) {
                        if(zhi[i].time && zhi[i].time.length > 0  && i != 'zhoDataTime' && i != 'he') {
                            var date2 = '2021/12/12 ' + zhi[i].time[1] +':00'
                            var date1 = '2021/12/12 ' + zhi[i].time[0] +':00'
                            var date3 = new Date(date2).getTime() - new Date(date1).getTime();
                            var leave1=date3%(24*3600*1000)
                            var hours=Math.floor(leave1/(3600*1000))
                            var leave2=leave1%(3600*1000)
                            var minutes=Math.floor(leave2/(60*1000))
                            var shi = hours+'.'+ minutes
                            he += +shi
                        }
                    }
                    zhi.he = he + 'h'
                }
            },
            // 自动选择事件长度的事件
            zhoXuan(item, i) {
                var iss = i
                if(item.time == null) {
                    return
                } else {
                    var zhi = this.zhoData[iss]
                    var he = 0
                    for(var i in zhi) {
                        if(i != 'zhoDataTime' && i != 'he' && zhi[i].workingTime && zhi[i].workingTime.length > 0) {
                            he += +zhi[i].workingTime
                        }
                    }
                    zhi.he = he + 'h'
                }
            },
            // 按时间比例
            addBli(item, i) {
                var iss = i
                if(item.time == null) {
                    return
                } else {
                    var zhi = this.zhoData[iss]
                    var he = 0
                    for(var i in zhi) {
                        if(i != 'zhoDataTime' && i != 'he' && zhi[i].workingTime && zhi[i].workingTime.length > 0) {
                            he += +zhi[i].workingTime
                        }
                    }
                    zhi.he = he.toFixed(1) + 'h'
                }
            },
            zhoRqis() {
                this.zhoData = []
                if(this.zhoRqi) { 
                    var stime = this.zhoRqi[0]
                    var etime = this.zhoRqi[1]
                    var zhi = this.getdiffdate(stime, etime)
                    var arrst = []
                    for(var i in zhi) {
                        var obj = {}
                        obj.zhoDataTime = zhi[i]
                        obj.he = 0
                        for(var j in this.projectList) {
                            var xinzhi = this.projectList[j].projectName 
                            obj[xinzhi] = {}
                            obj[xinzhi].time = ''
                            obj[xinzhi].con = ''
                            obj[xinzhi].progress = 0
                            obj[xinzhi].workingTime = 0
                        }
                        arrst.push(obj)
                    }
                    this.zhoData = arrst
                }
            },
            zhoZhi(res, i) {
                var zhi = 0
                for(var i in res) {
                    if(i != 'zhoDataTime' && i != 'he') {
                        zhi += +res[i]
                    }
                }
                res.he = zhi
            },
            zhoBtn(i) {
                // this.zhoData.split(i, 1)
                var arr = this.zhoData
                arr.splice(i, 1)
            },
            // 提交按周填报
            zhoAdd() {
                var zhi = this.zhoData
                var ll = 0
                console.log(this.reportTimeType.type)
                console.log(this.reportTimeType.multiWorktime)
                if(this.reportTimeType.type == 2) {
                    for(var i in zhi) {
                        this.dateAr = []
                        var alp = []
                        var zhis = zhi[i]
                        for(var j in zhis) {
                            if(j != 'zhoDataTime' && j != 'he' && zhis[j].time != null && zhis[j].time != 'null' && zhis[j].time != '') {
                                let objs = {}
                                objs.s = zhis[j].time[0]
                                objs.e = zhis[j].time[1]
                                alp.push(objs)
                            } 
                        }
                        this.dateAr = alp
                        if(this.dateAr.length > 0) {
                            let trus = this.fns()
                            ll += 1
                            if(!trus) {
                                this.$message({
                                    message: '填写的时间段重叠',
                                    type: 'error'
                                })
                                return false
                            }
                        }
                           
                    }
                     if(ll == 0) {
                        this.$message({
                            message: '请填写时间',
                            type: 'error'
                        })
                        return false
                    }
                } else if(this.reportTimeType.type == 1){
                    for(var i in zhi) {
                        var zhis = zhi[i]
                        for(var j in zhis) {
                            if(j != 'zhoDataTime' && j != 'he' && zhis[j].workingTime != null && zhis[j].workingTime != 'null' && zhis[j].workingTime != '') {
                                ll += 1
                            } 
                        }
                    }
                    if(ll == 0) {
                        this.$message({
                            message: '请选择时间',
                            type: 'error'
                        })
                        return false
                    }
                }
                    var submits = []
                    let formData = new FormData();
                    if(this.reportTimeType.multiWorktime == 1){
                        for (var i in this.zhoData) {
                            var zhoD = this.zhoData[i]
                            var flgs = false
                            for(var j in zhoD) {     
                                if(j != 'zhoDataTime' && j != 'he' && zhoD[j].time && zhoD[j].time.length > 0 && zhoD[j].time != null && zhoD[j].time != 'null') {
                                    flgs = true
                                    formData.append("degreeId", "-1");
                                    formData.append("id", '-1');
                                    for(var s in this.projectList) {
                                        if(j == this.projectList[s].projectName) {
                                            formData.append("projectId", this.projectList[s].id);
                                        }
                                    }
                                    zhoD[j].subProjectId ? formData.append("subProjectId", zhoD[j].subProjectId) : formData.append("subProjectId", '0');
                                    formData.append("taskId", 0);
                                    formData.append("reportTimeType", this.reportTimeType.type);
                                    formData.append("endTime", '');
                                    formData.append("startTime", '');
                                    formData.append("multiWorktime", this.reportTimeType.multiWorktime);
                                    var lix = []
                                    var objjs = {}
                                    objjs.startTime = zhoD[j].time[0]
                                    objjs.endTime = zhoD[j].time[1]
                                    if (zhoD[j].con == null || zhoD[j].con == '') {
                                        zhoD[j].con == '-'
                                    }
                                    objjs.content = zhoD[j].con
                                    lix.push(objjs)
                                    var zhiZhi = JSON.stringify(lix)
                                    zhiZhi = zhiZhi.replace(/,/g,"@");
                                    formData.append("content", zhiZhi)
                                    formData.append("isOvertime", 0)
                                    formData.append("professionProgress", "[]")
                                    zhoD[j].stage ? formData.append("stage", zhoD[j].stage) : formData.append("stage", '');
                                    formData.append("createDate",zhoD.zhoDataTime)
                                }
                            }
                        }
                    } else {
                        for (var i in this.zhoData) {
                            var zhoD = this.zhoData[i]
                            var flgs = false
                            if(this.reportTimeType.type == 2) {
                                for(var j in zhoD) {     
                                    if(j != 'zhoDataTime' && j != 'he' && zhoD[j].time && zhoD[j].time.length > 0 && zhoD[j].time != null && zhoD[j].time != 'null') {
                                        flgs = true
                                        formData.append("degreeId", "-1");
                                        formData.append("id", '-1');
                                        for(var s in this.projectList) {
                                            if(j == this.projectList[s].projectName) {
                                                formData.append("projectId", this.projectList[s].id);
                                            }
                                        }
                                        zhoD[j].subProjectId ? formData.append("subProjectId", zhoD[j].subProjectId) : formData.append("subProjectId", '0');
                                        formData.append("taskId", 0);
                                        formData.append("reportTimeType", this.reportTimeType.type);
                                        formData.append("endTime", zhoD[j].time[1]);
                                        formData.append("startTime", zhoD[j].time[0]);
                                        formData.append("multiWorktime", this.reportTimeType.multiWorktime);
                                        zhoD[j].con == '' || zhoD[j].con == null ? formData.append("content", '-') : formData.append("content", zhoD[j].con)
                                        formData.append("isOvertime", 0)
                                        formData.append("professionProgress", "[]")
                                        zhoD[j].stage ? formData.append("stage", zhoD[j].stage) : formData.append("stage", '');
                                        formData.append("createDate",zhoD.zhoDataTime)

                                    }
                                }
                            } else {
                                for(var j in zhoD) {     
                                    if(j != 'zhoDataTime' && j != 'he' && zhoD[j].workingTime && zhoD[j].workingTime.length > 0 && zhoD[j].workingTime > 0 && zhoD[j].workingTime != null && zhoD[j].workingTime != 'null') {
                                        flgs = true
                                        formData.append("degreeId", "-1");
                                        formData.append("id", '-1');
                                        for(var s in this.projectList) {
                                            if(j == this.projectList[s].projectName) {
                                                formData.append("projectId", this.projectList[s].id);
                                            }
                                        }
                                        zhoD[j].subProjectId ? formData.append("subProjectId", zhoD[j].subProjectId) : formData.append("subProjectId", '0')
                                        // formData.append("subProjectId", zhoD[j].subProjectId);
                                        formData.append("taskId", 0);
                                        formData.append("reportTimeType", this.reportTimeType.type);
                                        if(this.reportTimeType.type == 1) {
                                            formData.append("workingTime", zhoD[j].workingTime);
                                        } else if(this.reportTimeType.type == 2) {
                                            formData.append("endTime", zhoD[j].time[1]);
                                            formData.append("startTime", zhoD[j].time[0]);
                                        } else if(this.reportTimeType.type == 3) {
                                            formData.append("progress", zhoD[j].progress);
                                            formData.append("workingTime", zhoD[j].workingTime);
                                        }
                                        formData.append("multiWorktime", this.reportTimeType.multiWorktime);
                                        zhoD[j].con == '' || zhoD[j].con == null ? formData.append("content", '-') : formData.append("content", zhoD[j].con)
                                        formData.append("isOvertime", 0)
                                        formData.append("professionProgress", "[]")
                                        zhoD[j].stage ? formData.append("stage", zhoD[j].stage) : formData.append("stage", '');
                                        formData.append("createDate",zhoD.zhoDataTime)

                                    }
                                }
                            }
                        }
                    } 
                    // else {
                    //     for (var i in this.zhoData) {
                    //         var zhoD = this.zhoData[i]
                    //         var flgs = false
                    //         for(var j in zhoD) {     
                    //             if(j != 'zhoDataTime' && j != 'he' && zhoD[j].workingTime && zhoD[j].workingTime.length > 0 && zhoD[j].workingTime > 0 && zhoD[j].workingTime != null && zhoD[j].workingTime != 'null') {
                    //                 flgs = true
                    //                 formData.append("degreeId", "-1");
                    //                 formData.append("id", '-1');
                    //                 for(var s in this.projectList) {
                    //                     if(j == this.projectList[s].projectName) {
                    //                         formData.append("projectId", this.projectList[s].id);
                    //                     }
                    //                 }
                    //                 formData.append("subProjectId", '0');
                    //                 formData.append("taskId", 0);
                    //                 formData.append("reportTimeType", this.reportTimeType.type);
                    //                 formData.append("progress", zhoD[j].progress);
                    //                 formData.append("workingTime", zhoD[j].workingTime);
                    //                 formData.append("content", zhoD[j].con);
                    //                 formData.append("multiWorktime", this.reportTimeType.multiWorktime);
                    //                 formData.append("isOvertime", 0)
                    //                 formData.append("professionProgress", "[]")
                    //                 formData.append("stage", "");
                    //                 formData.append("createDate",zhoD.zhoDataTime)

                    //             }
                    //         }
                    //     }
                    // }
                    this.http.uploadFile( this.port.report.editPort, formData,
                        res => {
                            this.listLoading = false;
                            if (res.code == "ok") {
                                this.$message({
                                    message: "填报成功",
                                    type: "success"
                                });
                                this.diasZho = false
                                this.zhoData = []
                                this.zhoRqi = ''
                                this.getReportList();
                                this.getDepartment();
                            } else {
                                this.$message({
                                    message: res.msg,
                                    type: "error"
                                });
                            }
                        },
                        error => {
                            this.listLoading = false;
                            this.$message({
                                message: error,
                                type: "error"
                            });
                        });
                // 关闭弹窗 并 清空
                // this.diasZho = false
                // this.zhoData = []
                // this.zhoRqi = ''
            },
            ChangeHourMinutestr (str) {
                if (str !== "0" && str !== "" && str !== null) {
                    return ((Math.floor(str / 60)).toString().length < 2 ? "0" + (Math.floor(str / 60)).toString() : 
                    (Math.floor(str / 60)).toString()) + ":" + ((str % 60).toString().length < 2 ? "0" + (str % 60).toString() : (str % 60).toString());
                } else {
                    return "";
                }
            },
            // 得到两个日期中间的日期
            getdiffdate(stime,etime){
                //初始化日期列表，数组
                var diffdate = new Array();
                var i=0;
                //开始日期小于等于结束日期,并循环
                while(stime<=etime){
                    diffdate[i] = stime;
                    
                    //获取开始日期时间戳
                    var stime_ts = new Date(stime).getTime();
                    
                    //增加一天时间戳后的日期
                    var next_date = stime_ts + (24*60*60*1000);
                    
                    //拼接年月日，这里的月份会返回（0-11），所以要+1
                    var next_dates_y = new Date(next_date).getFullYear()+'-';
                    var next_dates_m = (new Date(next_date).getMonth()+1 < 10)?'0'+(new Date(next_date).getMonth()+1)+'-':(new Date(next_date).getMonth()+1)+'-';
                    var next_dates_d = (new Date(next_date).getDate() < 10)?'0'+new Date(next_date).getDate():new Date(next_date).getDate();
            
                    stime = next_dates_y+next_dates_m+next_dates_d;
                    
                    //增加数组key
                    i++;
                }
                return diffdate;
            },
            // 添加模块
            addDomain(i) {
                var leftProgress = 10;
                if (this.reportTimeType.type == 3) {
                    //计算已经待分配工时比例
                    let array = this.workForm.domains;
                    let totalProgress = 0;
                    for (var i=0;i<array.length; i++) {
                        totalProgress += array[i].progress;
                    }
                    if (totalProgress < 100) {
                        leftProgress = 100 - totalProgress;
                    }
                }
                this.workForm.domains.push({
                        projectId: "",
                        workingTime: this.reportTimeType.type == 3?(leftProgress*this.reportTimeType.allday/100).toFixed(1):"",
                        content: "",
                        progress:leftProgress,
                        state:2,//2-表示待提交
                        multiWorktime: this.reportTimeType.multiWorktime,
                        worktimeList:[{}],
                        // degreeId: '',
                });
                
                if (this.reportTimeType.type == 0) {
                    //全天上下午模式下，检测时间段数量，达到2个，不能再加了
                    var length = this.workForm.domains.length;
                    if (length == 2) {
                        this.showAddMore = false;
                    }
                }

                this.chuji()
                
            },

            // 移除模块
            delDomain(i) {
                this.workForm.domains.splice(i,1)
                //检测当前剩下的一个，时间类型是否是全天
                if (this.reportTimeType.type == 0) {
                    if (this.workForm.domains[0].timeType == 0) {
                        this.showAddMore = false;
                    } else {
                        this.showAddMore = true;
                    }
                }
                
                if(this.user.timeType.multiWorktime == 1) {
                    this.iptChangs()
                } else {
                    this.seleChn(0)
                }
            },

            // 改变月份
            changeMonth() {
                if (this.isBatch == 0 && !this.isSubstitude) {
                    //只有按天填报才能获取当天的日报
                    this.getReport()
                }
            },
            // 判断时间段
            fns() {
                for (let k in this.dateAr) {
                    if (!this.judege(k)) {
                    return false
                    }
                }
                return true
            },
            judege(idx){
                for (let k in this.dateAr) {
                    if (idx !== k) {
                        if (this.dateAr[k].s <= this.dateAr[idx].s && this.dateAr[k].e > this.dateAr[idx].s) {
                        return false
                        }
                        if (this.dateAr[k].s < this.dateAr[idx].e && this.dateAr[k].e >= this.dateAr[idx].e) {
                        return false
                        }
                    }
                }
                return true
            },

            // 保存日报
            submitDepartment(isDraft) {
                this.isDraft = isDraft;
                this.$refs.workForm.validate(valid => {
                    if (valid) {
                        this.dateAr = []
                        let alp = []
                        if(this.user.timeType.multiWorktime != 1) {
                            for(var p in this.workForm.domains) {
                                if(this.workForm.domains[p].startTime || this.workForm.domains[p].endTime) {
                                    let objs = {}
                                    objs.s = this.workForm.domains[p].startTime
                                    objs.e = this.workForm.domains[p].endTime
                                    alp.push(objs)
                                }
                            }
                            this.dateAr = alp
                            if(this.dateAr.length > 0) {
                                let trus = this.fns()
                                if(!trus) {
                                    this.$message({
                                        message: '填写的时间段重叠',
                                        type: "error"
                                    });
                                    return
                                }
                            }
                        } else {
                            for(var p in this.workForm.domains) {
                                var slll = this.workForm.domains[p]
                                for(var o in slll.worktimeList) {
                                    if(slll.worktimeList[o].startTime || slll.worktimeList[o].endTime) {
                                        let objs = {}
                                        objs.s = slll.worktimeList[o].startTime
                                        objs.e = slll.worktimeList[o].endTime
                                        alp.push(objs)
                                    }
                                }
                            }
                            this.dateAr = alp
                            if(this.dateAr.length > 0) {
                                let trus = this.fns()
                                if(!trus) {
                                    this.$message({
                                        message: '填写的时间段重叠',
                                        type: "error"
                                    });
                                    return
                                }
                            }
                        }

                        // return
                        //代填的情况，检查人员是否已经选择
                        if (this.isSubstitude) {
                            if (this.workForm.userNames == null || this.workForm.userNames.length == 0) {
                                this.$message({
                                        message: "请选择代填的人员",
                                        type: "error"
                                    });
                                return;
                            }
                        }
                        //检查时间，全天和上下午不能同时存在
                        if (this.reportTimeType.type == 0) {
                            var alldayNum = 0;
                            var amNum = 0;
                            var pmNum = 0;
                            for(var i in this.workForm.domains) {
                                if (this.workForm.domains[i].timeType == 0) {
                                    alldayNum ++;
                                } else if (this.workForm.domains[i].timeType == 1) {
                                    amNum++;
                                } else if (this.workForm.domains[i].timeType == 2) {
                                    pmNum++;
                                }
                            }
                            if (alldayNum > 1) {
                                this.$message({
                                        message: "工作时间-全天，只能选择一次",
                                        type: "error"
                                    });
                                return;
                            }
                            if (amNum > 1) {
                                this.$message({
                                        message: "工作时间-上午，只能选择一次",
                                        type: "error"
                                    });
                                return;
                            }
                            if (pmNum > 1) {
                                this.$message({
                                        message: "工作时间-下午，只能选择一次",
                                        type: "error"
                                    });
                                return;
                            }
                            if (alldayNum == 1 && (amNum > 0 || pmNum > 0)) {
                                this.$message({
                                        message: "工作时间-全天，不能和上下午同时存在",
                                        type: "error"
                                    });
                                return;
                            }
                        } else if (this.reportTimeType.type == 3) {
                            //总百分比不能超过100%
                            let total = 0;
                            this.workForm.domains.forEach(w=>{total += w.progress});
                            if (total > 100) {
                                this.$message({
                                        message: "用时比例之和不能超过100%",
                                        type: "error"
                                    });
                                return;
                            } else if (total < 100) {
                                this.$message({
                                        message: "工时尚未完全分配，无法提交",
                                        type: "error"
                                    });
                                return;
                            }
                        }
                        
                        this.listLoading = true;
                        let formData = new FormData();
                        formData.append("draft", this.isDraft);
                        for(var i in this.workForm.domains) {
                            if(this.workForm.domains[i].degreeId) {
                                // var sss = this.workForm.domains[i].degreeId.toString()
                                formData.append("degreeId", this.workForm.domains[i].degreeId);
                            } else {
                                formData.append("degreeId", "-1");
                            }
                            if (this.workForm.domains[i].id != null) {
                                formData.append("id", this.workForm.domains[i].id);
                            } else {
                                formData.append("id", -1);
                            }
                            formData.append("projectId", this.workForm.domains[i].projectId);
                            if (this.workForm.domains[i].subProjectId != null) {
                                formData.append("subProjectId", this.workForm.domains[i].subProjectId);
                            } else {
                                formData.append("subProjectId", 0);
                            }
                            if (this.workForm.domains[i].taskId != null) {
                                formData.append("taskId", this.workForm.domains[i].taskId);
                            } else {
                                formData.append("taskId", 0);
                            }
                            
                            formData.append("reportTimeType", this.reportTimeType.type);
                            if (this.reportTimeType.type == 0) {
                                formData.append("timeType", this.workForm.domains[i].timeType);
                                var workingTime = this.timeType.filter(t=>t.value == this.workForm.domains[i].timeType)[0].hours;
                                formData.append("workingTime", workingTime);
                            } else if (this.reportTimeType.type == 1){
                                formData.append("workingTime", this.workForm.domains[i].workingTime);
                            } else if (this.reportTimeType.type == 2) {
                                formData.append("endTime", this.workForm.domains[i].endTime);
                                formData.append("startTime", this.workForm.domains[i].startTime);
                            } else if (this.reportTimeType.type == 3) {
                                //按比例分配
                                formData.append("progress", this.workForm.domains[i].progress);
                                formData.append("workingTime", this.workForm.domains[i].workingTime);
                            }
                            
                            
                            //处理多个时间事项
                            formData.append("multiWorktime", this.workForm.domains[i].multiWorktime);
                            if (this.reportTimeType.multiWorktime == 1) {
                                //检查时间是否有重叠
                                var workList = this.workForm.domains[i].worktimeList;
                                for (var j=0;j<workList.length; j++) {
                                    var curItem = workList[j];
                                    //检查开始时间是否大于结束时间
                                    if (curItem.startTime >= curItem.endTime) {
                                        this.$message({
                                            message: "时间段"+curItem.startTime+'-'+curItem.endTime+"有误："+ 
                                                "结束时间必须大于开始时间",
                                            type: "error"
                                        });
                                        return;
                                    }
                                    for (var p = j+1;p<workList.length; p++) {
                                        var jItem = workList[p];
                                        if ((jItem.startTime>=curItem.startTime&&jItem.startTime < curItem.endTime)
                                                || (jItem.endTime>curItem.startTime&&jItem.endTime <= curItem.endTime)) {
                                            this.$message({
                                                message: "时间段"+curItem.startTime+'-'+curItem.endTime+"与"+ 
                                                    jItem.startTime+'-'+jItem.endTime+ "存在重叠，请修改。",
                                                type: "error"
                                            });
                                            return;
                                        }
                                    }
                                }
                                let m = JSON.stringify(this.workForm.domains[i].worktimeList);
                                m = m.replace(/,/g,"@");//replaceAll(',','@');企业微信不兼容replaceAll
                                formData.append("content", m);
                            } else {
                                if (this.workForm.domains[i].content == null || this.workForm.domains[i].content == '') {
                                    formData.append("content", '-');
                                } else {
                                    formData.append("content", this.workForm.domains[i].content);
                                }
                            }
                            
                            if (this.isBatch == 0) {
                                formData.append("createDate", this.workForm.createDate);
                            } else {
                                //批量填报，时间范围
                                formData.append("createDate", this.workForm.createDate[0]+'@'+this.workForm.createDate[1]);
                            }
                            
                            if(this.workForm.domains[i].isOvertime == undefined ) {
                                this.workForm.domains[i].isOvertime = '0'
                                formData.append("isOvertime", this.workForm.domains[i].isOvertime);
                            } else if (this.workForm.domains[i].isOvertime == false){
                                this.workForm.domains[i].isOvertime = '0'
                                formData.append("isOvertime", this.workForm.domains[i].isOvertime);
                            } else {
                                this.workForm.domains[i].isOvertime = '1'
                                formData.append("isOvertime", this.workForm.domains[i].isOvertime);
                            }
                            
                            if (this.workForm.userId != null) {
                                var targetUids = '';
                                this.workForm.userId.forEach(u=>{
                                    targetUids += u + '@';
                                });
                                if (targetUids.length > 0) {
                                    targetUids = targetUids.substring(0, targetUids.length -1);
                                    formData.append("targetUids", targetUids);
                                }
                            }
                            //项目专业进度
                            if (this.workForm.domains[i].professionProgress != null) {
                                var m = JSON.stringify(this.workForm.domains[i].professionProgress);
                                
                                m = m.replace(/,/g,"@");//replaceAll(',','@');企业微信不兼容replaceAll
                                
                                formData.append("professionProgress", m);
                            } else {
                                formData.append("professionProgress", "[]");
                            }
                            if (this.workForm.domains[i].stage != null) {
                                formData.append("stage", this.workForm.domains[i].stage);
                            } else {
                                formData.append("stage", "");
                            }
                        }
                        // formData.forEach((value, key) => {
                        //     })
                        // return
                        this.http.uploadFile( this.port.report.editPort, formData,
                        res => {
                            this.listLoading = false;
                            if (res.code == "ok") {
                                this.$message({
                                    message: this.isDraft==0?"提交成功":"暂存成功",
                                    type: "success"
                                });
                                this.dialogVisible = false;
                                this.jsDay = 0
                                this.jsTime = 0
                                this.getReportList();
                                this.getDepartment();
                            } else {
                                this.$message({
                                    message: res.msg,
                                    type: "error"
                                });
                            }
                        },
                        error => {
                            this.listLoading = false;
                            this.$message({
                                message: error,
                                type: "error"
                            });
                        });
                    }
                });
            },
            cli() {
                
            },
            // 判断是展示那个工时导入
            imports() {
                if(this.user.timeType.syncCorpwxTime == 0) {
                    this.importDialog = true
                } else {
                    this.importWxDialog = true
                }
            },
            // 跳转
            junpToDeskTop(id) {
                let day = (this.choseDay + 1) > 9 ? "-" + (this.choseDay + 1) : "-0" + (this.choseDay + 1);
                this.$router.push("/desktop/" + id + "/" + this.date +day);
            },

            // 通过日报
            approve(id, item) {
                this.logining = true;
                let day = (this.choseDay + 1) > 9 ? "-" + (this.choseDay + 1) : "-0" + (this.choseDay + 1);

                var ids = item.id;
                // var data = item.data;
                // data.forEach(element => {
                //     ids +=(element.id+',');
                // });
                this.http.post( this.port.report.approve, {id: id , date: this.date +day, reportIds: ids},
                res => {
                    this.logining = false;
                    if (res.code == "ok") {
                        this.$message({
                            message: "审核成功",
                            type: "success"
                        });
                        this.getReportList();
                        this.getDepartment();
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.logining = false;
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },

            //撤回日报
            cancel(item) {
                this.logining = true;
                
                var ids = '';
                var data = item.data;
                data.forEach(element => {
                    ids +=(element.id+',');
                });
                this.http.post(this.port.report.cancelReport, {userId: this.user.id, reportIds: ids},
                res => {
                    this.logining = false;
                    if (res.code == "ok") {
                        this.$message({
                            message:"撤回成功",
                            type: "success"
                        });
                        this.getReportList();
                        this.getDepartment();
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.logining = false;
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },
            showDenyDialog(id,i, item) {
                this.denyReasonDialog = true;
                let day = (this.choseDay+1) > 9 ? "-" + (this.choseDay + 1) : "-0" + (this.choseDay + 1);
                var ids = item.id;
                // var data = item.data;
                // data.forEach(element => {
                //     ids +=(element.id+',');
                // });
                this.denyForm = {id: id ,i:i, date: this.date +day, reportIds: ids, reason:null};
            },
            // 未通过日报
            deny() {
                this.logining = true;
                
                this.http.post( this.port.report.deny, this.denyForm,
                res => {
                    this.logining = false;
                    if (res.code == "ok") {
                        this.$message({
                            message: this.denyForm.i==0?"驳回成功":"撤销成功",
                            type: "success"
                        });
                        this.getReportList();
                        this.getDepartment();
                        this.denyReasonDialog = false;
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.logining = false;
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            }

        },
        created() {
            let height = window.innerHeight;
            this.tableHeight = height - 178;
            const that = this;
            window.onresize = function temp() {
                that.tableHeight = window.innerHeight - 178;
            };

        },
        mounted() {
            var now = new Date();
            var t = util.formatDate.format(now, 'yyyy-MM-dd');
            var startStr = util.formatDate.format(new Date(), 'yyyy-MM') + "-01";
            this.exportParam.dateRange = [startStr,t];
            this.getAllDate();
            this.getReportList();
            this.getProjectList();
            this.getTimeType();
            this.getDepartment();
            this.scrollFunction()
            this.userssHu()
        }
    };
</script>

<style lang="scss" scoped>
.waiting {
    color:orange;
}
.filledReportStyle {
    color:#32CD32;

}
.RejectStyle {
    color:red;
}
    .allDaily {
        width:82%;
    }
    .report_title {
        padding:10px 0;
        color:#666;
    }
    .clearfix {
        overflow-x: auto;
        white-space: nowrap;
        padding: 15px 0;
        // overflow-y: hidden;
        .date_item {
            padding: 0 3px;
            cursor: pointer;
        }
        .chooseDate {
            color: #20a0ff;
        }
    }

    .one_daily {
        i {
            color: #9ed0ff;
            margin-right: 5px;
        }
        .one_daily_body {
            padding: 15px 0px;
            p {
            margin: 0;
            line-height: 30px;
            }
        }
        ul {
            padding: 0;
        }
    }

    .checkbtn {
        float: right;
        margin-top: -10px;
    }
</style>

<style lang="scss">
    .daily {
        .el-card__body {
            height: 80%;
            overflow-y: auto;
        }

        .el-card__header {
            padding: 0 20px;
        }
    }
    
</style>

<style scoped>
/* 项目标签的样式 */
    .el-tag + .el-tag {
        margin-left: 10px;
    }
    .button-new-tag {
        margin-left: 10px;
        height: 32px;
        line-height: 30px;
        padding-top: 0;
        padding-bottom: 0;
    }
    .input-new-tag {
        width: 90px;
        margin-left: 10px;
        vertical-align: bottom;
    }
</style>

<style lang="scss" scoped>
    // 加班样式
    .overtime {
        display: inline-block;
        margin-left: 20px;

        input {
            display: inline-block;
            margin-top: 5px;
        }
    }
    .plus {
        display: inline-block;
    }
    // .tages {
    //     float: right;
    // }
    .overtime {
        display: inline-block;
        margin-left: 30px;
    }
    .bloks {
        display: inline-block;
        width: 380px;
    }
    .zhiss {
        display: flex;
        justify-content: space-around;
        align-items: center;
    }
    .zhoFel {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
</style>