
@extends('layouts.app')
@section('title')临时工报表-人事管理@endsection

@section('content')
    @component('personnel.laborReport.menu')@endcomponent

    <div class="d-none container-fluid modal-open" id="list" style="overflow: auto">
        <div id="form_div"></div>
        <span class="dropdown">
                <button class="btn btn-outline-dark btn-sm form-control-sm dropdown-toggle tooltipTarget mt-1 mb-1"
                        data-toggle="dropdown" title="导出所有页将会以搜索条件得到的筛选结果，将其全部记录（每一页）导出">
                    导出Excel
                </button>
                <div class="dropdown-menu">
                    <a class="dropdown-item" @click="laborReportExport(false)" href="javascript:">导出勾选内容</a>
                    <a class="dropdown-item" @click="laborReportExport(true)" href="javascript:">导出所有页</a>
                </div>
            </span>
        <table class="table table-sm table-hover table-striped d-none d-xl-block p-0 text-nowrap table-bordered td-min-width-80" id="table">
            <tr v-for="(laborReport,i) in laborReports"  @click="selectedColor(laborReport.id)" :style="{'font-weight': laborReport.id==selectedStyle?'bold':''}" @click="selectTableRow(i,$event)">
                <td>
                    <label><input class="checkItem" type="checkbox" :value="laborReport.id"/></label>
                </td>
                <td><span>@{{ i+1  }}</span></td>
                <td >
                    @can('人事管理-门卫审核')
                        <span >
                            <b v-if="laborReport.isAdult==1"   class="text-danger">童工</b>
                        <span v-else-if="laborReport.userDutyCheckVerifyUserId&&laborReport.amountOfJoined==1"  class="text-success">已审核</span>
                        <span v-else-if="laborReport.userDutyCheckVerifyUserId&&laborReport.amountOfJoined&&laborReport.sequence"  class="text-black">&nbsp;&nbsp;&nbsp;@{{laborReport.sequence}}/@{{laborReport.amountOfJoined}}</span>
                        <button v-else class="btn btn-sm btn-outline-secondary"  @click="guardClockAudit(laborReport.id,laborReport.user_duty_check_id)">门卫审核</button>
                        </span>
                    @else
                        <b v-if="laborReport.isAdult==1"   class="text-danger">童工</b>
                        <span v-else-if="laborReport.userDutyCheckVerifyUserId&&laborReport.amountOfJoined==1"  class="text-success">已审核</span>
                        <span v-else-if="laborReport.userDutyCheckVerifyUserId&&laborReport.amountOfJoined&&laborReport.sequence"  class="text-black">&nbsp;&nbsp;&nbsp;@{{ laborReport.sequence }}/@{{ laborReport.amountOfJoined }}</span>
                        <span v-else class="text-center"><b class="text-danger">门卫未审核</b></span>
                    @endcan
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    @can('人事管理-组长审核')
                        <span>
                                <button v-if="laborReport.groupUserId&&!laborReport.is_exportGroup&&!laborReport.is_export&&laborReport.has_group_verify_right" @click="groupExport(laborReport.id,laborReport.name)" class="btn btn-sm btn-outline-danger">退组</button>
                              <span  v-else-if="laborReport.groupUserId&&!laborReport.is_exportGroup&&!laborReport.is_export&&!laborReport.has_group_verify_right"><b class="text-success">在组</b></span>
                        <span v-else-if="laborReport.groupUserId&&laborReport.is_exportGroup&&!laborReport.is_export" class="text-info">已退组</span>
                            <span v-else-if="laborReport.is_export" class="text-black">已退场</span>
                        <button v-else-if="laborReport.user_workgroup_id&&laborReport.has_group_verify_right" @click="groupClockAudit(laborReport.id,laborReport.userWorkgroupNeedRemark)" class="btn btn-sm btn-outline-primary">组长审核</button>
                        </span>
                    @else
                        <span  v-if="laborReport.groupUserId&&!laborReport.is_exportGroup&&!laborReport.is_export"><b class="text-success">在组</b></span>
                        <span v-else-if="laborReport.groupUserId&&laborReport.is_exportGroup&&!laborReport.is_export" class="text-info">已退组</span>
                        <span v-else-if="laborReport.is_export" class="text-black">已退场</span>
                        <span v-else-if="laborReport.user_workgroup_id" class="text-center"><b class="text-danger">组长未审核</b></span>
                    @endcan
                </td>
                <td><span v-if="laborReport.thisRoundRecordWorkingTime">@{{laborReport.thisRoundRecordWorkingTime}}</span></td>
                <td><span>@{{laborReport.userWorkGroupName}}</span></td>
                <td><span>@{{laborReport.name}}</span></td>
                <td class="text-muted"><span>@{{laborReport.mobile_phone}}</span></td>
                <td class="text-muted"><span>@{{laborReport.identity_number}}</span></td>
                @can('人事管理-临时工报表-修改劳务所')
                    <td class="text-muted">
                        <select  class="form-control-sm" name="labor_company" id="labor_company"  @change="updateLaborCompany(laborReport.labor_company_id,laborReport.enter_number)" v-model="laborReport.labor_company_id">
                            <option v-for="laborCompany in laborCompanies" :value="laborCompany.name">@{{ laborCompany.value }}</option>
                        </select>
                    </td>
                @else
                    <td class="text-muted"><span>@{{laborReport.labor_company}}</span></td>
                @endcan
                <td class="text-muted"><span>@{{laborReport.enter_at}}</span></td>
                <td><span>@{{laborReport.checkInAt}}</span></td>
                <td class="text-muted"><span>@{{laborReport.checkOutAt}}</span></td>
                <td class="text-muted"><span>@{{laborReport.round_check_in_at}}</span></td>
                <td class="text-muted"><span>@{{laborReport.round_check_out_at}}</span></td>
                <td><span>@{{ laborReport.exit_at }}</span></td>
                <td class="text-muted"><span>@{{laborReport.verifyAt}}</span></td>
                <td class="text-muted"><span v-if="laborReport.verifyPerson">@{{laborReport.verifyPerson}}</span></td>
                <td class="text-muted"><span v-if="laborReport.relax_time">@{{laborReport.relax_time}}</span></td>
                {{--                        <td class="text-muted"><span v-if="laborReport.onlineDuration">@{{laborReport.onlineDuration}}</span></td>--}}
                <td class="text-muted"><span v-if="laborReport.thisRecordOnlineTime">@{{laborReport.thisRecordOnlineTime}}</span></td>
                <td class="text-muted"><span>@{{laborReport.enter_number}}</span></td>
                {{--                        <td><span v-if="laborReport.workingDuration">@{{laborReport.workingDuration}}</span></td>--}}
                <td>
                    @can('人事管理-临时工报表-编辑备注')
                        <span  v-if="laborReport.remark" class="btn-sm btn-outline-secondary btn" @click="laborReportRemarkCheck($event)" :data_id="laborReport.id">@{{laborReport.remark}}</span>
                        <input type="text" v-else class="form-control form-control-sm" @blur="addLaborReportRemark($event)" onfocus="$(this).css('width','85px')" :value="laborReport.remark" :data_id="laborReport.id" >
                        <input type="text" class="form-control form-control-sm"  @blur="updateLaborReportRemark($event)" :value="laborReport.remark" :data_id="laborReport.id" style="min-width:85px;display: none">
                    @else
                        <span v-if="laborReport.remark">@{{laborReport.remark}}</span>
                    @endcan
                </td>
                @can('人事管理-临时工报表-删除')
                    <td><span class="btn btn-sm btn-outline-danger" @click="删除(laborReport.id,laborReport.name)">删</span></td>
                @endcan
            </tr>
        </table>
        <table id="listOnPad" class="table table-striped table-bordered table-hover p-0 d-table  d-xl-none" style="background: rgb(255, 255, 255);">
            <tr v-for="laborReport in laborReports">
                <td style="filter:grayscale(30%);">
                    <div  class="pl-3 mt-1">
                        <div style="transform:scale(1)" class="pl-0">
                                        <span class="mr-3 text-nowrap">
                                            <span >操作：</span>
                                            <span >
                                                @can('人事管理-门卫审核')
                                                    <span >
                                <b v-if="laborReport.isAdult==1"   class="text-danger">童工</b>
                                <b v-else-if="laborReport.userDutyCheckVerifyUserId{{--&&laborReport.amountOfJoined==1--}}"   class="text-success">已审核</b>
                                <b v-else-if="laborReport.userDutyCheckVerifyUserId&&laborReport.amountOfJoined&&laborReport.sequence"  class="text-black">&nbsp;&nbsp;&nbsp;@{{laborReport.sequence}}/@{{laborReport.amountOfJoined}}</b>
                                <button v-else style="transform:scale(1.1)" class="btn btn-lg btn-outline-secondary"  @click="guardClockAudit(laborReport.id,laborReport.user_duty_check_id)">门卫审核</button>
                                </span>
                                                @else
                                                    <b v-if="laborReport.isAdult==1"   class="text-danger">童工</b>
                                                    <b v-else-if="laborReport.userDutyCheckVerifyUserId{{--&&laborReport.amountOfJoined==1--}}"  class="text-success">已审核</b>
                                                    <b v-else-if="laborReport.userDutyCheckVerifyUserId&&laborReport.amountOfJoined&&laborReport.sequence"  class="text-black">&nbsp;&nbsp;&nbsp;@{{ laborReport.sequence }}/@{{ laborReport.amountOfJoined }}</b>
                                                    <span v-else class="text-center"><b class="text-danger">门卫未审核</b></span>
                                                @endcan
                                    &nbsp;&nbsp;&nbsp;&nbsp;
                                @can('人事管理-组长审核')
                                                    <span>
                                <button v-if="laborReport.groupUserId&&!laborReport.is_exportGroup&&!laborReport.is_export&&laborReport.has_group_verify_right" @click="groupExport(laborReport.id,laborReport.name)" style="transform:scale(1.1)" class="btn btn-lg btn-danger">退组</button>
                                     <span  v-else-if="laborReport.groupUserId&&!laborReport.is_exportGroup&&!laborReport.is_export&&!laborReport.has_group_verify_right"><b class="text-success">在组</b></span>
                                     <b v-else-if="laborReport.groupUserId&&laborReport.is_exportGroup&&!laborReport.is_export" class="text-info">已退组</b>
                                    <b v-else-if="laborReport.is_export" class="text-black">已退场</b>
                                <button v-else-if="laborReport.user_workgroup_id&&laborReport.has_group_verify_right" @click="groupClockAudit(laborReport.id,laborReport.userWorkgroupNeedRemark)" class="btn btn-lg btn-outline-primary"  style="transform:scale(1.1)" >组长审核</button>

                                                    </span>
                                                @else
                                                    <span  v-if="laborReport.groupUserId&&!laborReport.is_exportGroup&&!laborReport.is_export"><b class="text-success">在组</b></span>
                                                    <b v-else-if="laborReport.groupUserId&&laborReport.is_exportGroup&&!laborReport.is_export" class="text-info">已退组</b>
                                                    <b v-else-if="laborReport.is_export" class="text-black">已退场</b>
                                                    <span v-else-if="laborReport.user_workgroup_id" class="text-center"><b class="text-danger">组长未审核</b></span>
                                                @endcan
                                            </span>
                                        </span>
                            <span class="mr-3   text-nowrap"><span class="text-black">进场时间：</span><span class="text-black-50">@{{laborReport.enter_at  }}</span></span>
                            <span class="mr-3 text-nowrap"><span class="text-muted">退组时间：</span><span style="color:#af7651" v-if="">@{{ laborReport.checkOutAt }} </span></span>
                            <span class="mr-3 text-nowrap"><span class="text-black">退场时间：</span><span style="color:#af7651">@{{ laborReport.exit_at }}</span></span>
                            {{--                                    <span class="mr-3 text-nowrap"><span class="text-black">进场编号：</span><span style="color:#af7651">@{{ laborReport.enter_number }}</span></span>--}}
                            <span class="mr-3  text-nowrap"><span class="text-black">小组：</span><span class="text-black-50">@{{laborReport.userWorkGroupName  }}</span></span>
                            <span class="mr-3   text-nowrap"><span class="text-black">临时工：</span><span class="text-black-50">@{{ laborReport.name }} </span></span>
                            <span class="mr-3 text-nowrap"><span class="text-black">电话：</span><span style="color:#af7651" v-if="">@{{ laborReport.mobile_phone }} </span></span>
                            <span class="text-nowrap"><span class="text-black">身份证号：</span><span style="color:#af7651" v-if="">@{{ laborReport.identity_number }} </span></span>
                            {{--                                    <span class="mr-3 text-nowrap"><span class="text-black">劳务所：</span><span style="color:#af7651" v-if="">@{{ laborReport.labor_company }} </span></span>--}}
                            {{--                                    <span class="mr-3 text-nowrap"><span class="text-black">进组时间：</span><span style="color:#af7651" v-if="">@{{ laborReport.checkInAt }} </span></span>--}}
                            {{--                                    <span class="mr-3 text-nowrap"><span class="text-black">审核时间：</span><span style="color:#af7651" v-if="">@{{ laborReport.verifyAt }} </span></span>--}}
                            {{--                                    <span class="mr-3 text-nowrap"><span class="text-black">审核人：</span><span style="color:#af7651" v-if="">@{{ laborReport.verifyPerson }} </span></span>--}}
                            {{--                                    <span class="mr-3 text-nowrap"><span class="text-black">晚饭打卡(分)：</span><span style="color:#af7651" v-if="">@{{ laborReport.relax_time }} </span></span>--}}
                            {{--                                    <span class="mr-3 text-nowrap"><span class="text-black">在线时长：</span><span style="color:#af7651" v-if="">@{{ laborReport.onlineDuration }} </span></span>--}}
                            {{--                                    <span class="mr-3 text-nowrap"><span class="text-black">本次工作时长：</span><span style="color:#af7651" v-if="">@{{ laborReport.workingDuration }} </span></span>--}}
                            @can('人事管理-临时工报表-删除')
                                <span style="transform:scale(1.1)" class="btn btn-sm btn-outline-danger" @click="删除(laborReport.id,laborReport.name)">删</span>
                            @endcan
                        </div>
                    </div>
                </td>
            </tr>
        </table>
        <div class="text-info h5 btn btn">{{$laborReports->count()}}/@{{ sum }}</div>
        <div>{{$laborReports->appends($paginateParams)->links()}}</div>
        {{--      选择晚饭时长弹框      --}}

        <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalLabel">晚餐时长</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <form>
                            <div class="form-group">
                                <label for="relax_time" class="col-form-label">选择晚饭时长:</label>
                                <select class="form-control" id="relax_time" v-model="relax_time">
                                    <option value="30">30分</option>
                                    <option value="60">60分</option>
                                </select>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span class="btn btn-block" aria-hidden="true">取消</span>
                        </button>
                        <button type="button" class="btn btn-primary" data-dismiss="modal" @click="makeSureRelax_time">确定</button>
                    </div>
                </div>
            </div>
        </div>
        {{--      特定组需要添加备注      --}}
        <div class="modal fade" id="remarkModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalLabel">添加所需备注</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <form>
                            <div class="form-group">
                                <label for="remark" class="col-form-label">备注:</label>
                                <textarea class="form-control" id="remark"></textarea>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span class="btn btn-block" aria-hidden="true">取消</span>
                        </button>
                        <button type="button" class="btn btn-primary" data-dismiss="modal" @click="addRemarkAndGroupClock">确定</button>
                    </div>
                </div>
            </div>
        </div>
        <!-- 是否晚餐弹框 -->
        <div class="modal fade" id="dinnerModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" >
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-body">
                        <b class="font-weight-bold">是否晚餐？</b>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span class="btn btn-block" @click="noDinner">否</span>
                        </button>
                        <button  type="button" class="btn btn-primary" data-dismiss="modal" @click="haveDinner">是</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('lastScript')
    <script type="text/javascript" src="{{mix('js/queryForm/export.js')}}"></script>
    <script type="text/javascript" src="{{mix('js/queryForm/queryForm.js')}}"></script>
    <script type="text/javascript" src="{{mix('js/queryForm/header.js')}}"></script>{{--新版2--}}
    <script>
        let today=(new Date());
        function isTomorrow(){
            let now=(new Date());
            const dateTime=new Date(now.setDate(now.getDate()+1));
            if(dateTime<=today)return true;
            else return false;
        }
        function reloadOnTomorrow(){
            if(isTomorrow()){
                window.location.reload();
            }
        }
        window.onfocus=reloadOnTomorrow;
        setInterval(reloadOnTomorrow,1000*60*60)
    </script>
    <script>
        let hideHeaderTitle = function (){
            let $listOnPad = $('#listOnPad');
            let $headerRoll = $('#headerRoll');
            if($listOnPad.css('display')!=='none'){
                $headerRoll.attr('hidden',true)
            }else{
                $headerRoll.attr('hidden',false)
                $headerRoll.find('tr').css('width',$(document).width());
            }
        };
        window.onresize= hideHeaderTitle;
        window.onscroll=hideHeaderTitle;
            @if(isset($request))
        let request={!! json_encode($request) !!};
            @endif
        let vue = new Vue({
                el:"#list",
                data:{
                    laborReports:[
                            @foreach($laborReports as $laborReport)
                        {id:'{{$laborReport->id}}',enter_number:'{{$laborReport->enter_number}}'
                            ,@if($laborReport->userWorkgroup)user_workgroup_id:'{{$laborReport->userWorkgroup->id}}',
                            userWorkgroupNeedRemark:'{{$laborReport->userWorkgroup->isNeedRemark}}',
                            userWorkGroupName:'{{$laborReport->userWorkgroup->name}}',@endif
                            userId:'{{$laborReport->user_id}}',name:'{{$laborReport->name}}'
                            ,mobile_phone:'{{$laborReport->mobile_phone}}',identity_number:'{{$laborReport->identity_number}}',
                            @if($laborReport->laborCompany)
                            labor_company:'{{$laborReport->laborCompany->name}}',labor_company_id:'{{$laborReport->laborCompany->id}}',@endif
                            checkInAt:'{{$laborReport->check_in_at}}', relax_time:'{{$laborReport->relax_time}}',
                            is_exportGroup:'{{$laborReport->is_exportGroup}}',is_export:'{{$laborReport->is_export}}',
                            verifyAt:'{{$laborReport->verify_at}}',groupUserId:'{{$laborReport->group_user_id}}',verifyPerson:'{{$laborReport->user['name']}}',
                            checkOutAt:'{{$laborReport->check_out_at}}',onlineDuration:'{{$laborReport->online_duration}}',
                            round_check_in_at:'{{$laborReport->round_check_in_at}}',round_check_out_at:'{{$laborReport->round_check_out_at}}',
                            workingDuration:'{{$laborReport->working_duration}}', created_at:'{{$laborReport->created_at}}',
                            enter_at:'{{$laborReport->enter_at}}',exit_at:'{{$laborReport->exit_at}}',
                            thisRecordOnlineTime:'{{$laborReport->thisRecordOnlineTime}}',
                            thisRecordWorkingTime:'{{$laborReport->thisRecordWorkingTime}}',
                            thisRoundRecordWorkingTime:'{{$laborReport->thisRoundRecordWorkingTime}}',
                            isAdult:'{{$laborReport->isAdult}}',has_group_verify_right:'{{$laborReport->has_group_verify_right}}',
                            sequence:'{{$laborReport->sequence}}',amountOfJoined:'{{$laborReport->amountOfJoined}}',remark:'{{$laborReport->remark}}',
                            @if($laborReport->userDutyCheck)user_duty_check_id:'{{$laborReport->userDutyCheck->id}}', userDutyCheckVerifyUserId:'{{$laborReport->userDutyCheck->verify_user_id}}'
                            ,userDutyCheckType:'{{$laborReport->userDutyCheck->type}}',userDutyCheckAt:'{{$laborReport->userDutyCheck->checked_at}}',@endif},
                        @endforeach
                    ],
                    i:0,
                    userWorkGroups:[
                            @foreach($userWorkGroups as $userWorkGroup)
                        {name:'{{$userWorkGroup->id}}',value:'{{$userWorkGroup->name}}'},
                        @endforeach
                    ],
                    permittingWorkgroups:{!! $permittingWorkgroups !!},
                    totalWorkingHours:{!! $totalWorkingHours !!},
                    laborCompanies:[
                            @foreach($laborCompanies as $laborCompany)
                        {name:'{{$laborCompany->id}}',value:'{{$laborCompany->name}}'},
                        @endforeach
                    ],
                    relax_time:'',dateTime:'',selectedStyle:'',laborReportId:null,
                    sum:{!! $laborReports->total() !!},
                    selectTr:''
                },
                mounted:function(){
                    initEcho();
                    let _this=this;
                    let laborReports=_this.laborReports;
                    //进场
                    let tokenOfBroadcastEnterAndLeave='{{$tokenOfBroadcastEnterAndLeave}}';
                    if(tokenOfBroadcastEnterAndLeave){
                        Echo.channel('{{$laravelEchoPrefix}}'+tokenOfBroadcastEnterAndLeave).listen('ImportEvent',(e)=>{
                            // let labor=e.laborReport;
                            // laborReports.push(labor);
                            setTimeout(function () {
                                window.location.reload();
                            },500);
                        });
                    }
                    //退场
                    Echo.channel('{{$laravelEchoPrefix}}laborReport').listen('ExportEvent',(e)=>{
                        setTimeout(function () {
                            window.location.reload();
                        },500);
                        // let labor=e.laborReport;
                        // laborReports.every(function (laborReport) {
                        //     if (laborReport.id==labor.id){
                        //         laborReport.thisRecordOnlineTime=labor.thisRecordOnlineTime;
                        //         laborReport.thisRecordWorkingTime=labor.thisRecordWorkingTime;
                        //         laborReport.is_export=labor.is_export;
                        //         laborReport.exit_at=labor.exit_at;
                        //         laborReport.remark=labor.remark;
                        //         return false
                        //     }
                        //     return true;
                        // });
                    });
                    //门卫审核
                    Echo.channel('{{$laravelEchoPrefix}}userDutyCheck').listen('GuardAuditEvent',(e)=>{
                        let userDutyCheck=e.userDutyCheck;
                        laborReports.every(function (laborReport) {
                            if (laborReport.user_duty_check_id==userDutyCheck.id){
                                laborReport.userDutyCheckVerifyUserId=userDutyCheck.verify_user_id;
                                laborReport.user_duty_check_id=userDutyCheck.id;
                                return false
                            }
                            return true;
                        });
                    });
                    //组长审核
                    Echo.channel('{{$laravelEchoPrefix}}laborReport').listen('TeamAuditEvent',(e)=>{
                        let labor=e.laborReport;
                        laborReports.every(function (laborReport) {
                            if (laborReport.id==labor.id){
                                if(labor.remark){
                                    laborReport.remark=labor.remark;
                                }
                                laborReport.verifyAt=labor.verify_at;
                                laborReport.groupUserId=labor.group_user_id;
                                laborReport.verifyPerson=labor.verifyPerson;
                                return false
                            }
                            return true;
                        });
                    });
                    //进组
                    _this.permittingWorkgroups.forEach(function(workgroup){
                        Echo.channel('{{$laravelEchoPrefix}}'+workgroup.token).listen('ClockinEvent',(e)=>{
                            // let res=false;
                            // laborReports.forEach(function (item){
                            //     if(item.id==labor.id){
                            //         res=true;
                            //     }
                            // })
                            // if (res){
                            //     laborReports.every(function (laborReport) {
                            //         if (laborReport.id==labor.id){
                            //             laborReport.userWorkGroupName=labor.user_workgroup.name;
                            //             laborReport.has_group_verify_right=labor.has_group_verify_right;
                            //             laborReport.user_workgroup_id=labor.user_workgroup_id;
                            //             laborReport.checkInAt=labor.check_in_at;
                            //             laborReport.round_check_in_at=labor.round_check_in_at;
                            //             return false
                            //         }
                            //         return true;
                            //     });
                            // }else {
                            //     labor.userWorkGroupName=labor.user_workgroup.name;
                            //     labor.checkInAt=labor.check_in_at;
                            //     labor.has_group_verify_right=labor.has_group_verify_right;
                            //     laborReports.push(labor);
                            // }
                            setTimeout(function () {
                                window.location.reload();
                            },500);
                        });
                    });
                    //退组
                    _this.permittingWorkgroups.forEach(function(workgroup){
                        Echo.channel('{{$laravelEchoPrefix}}'+workgroup.token).listen('ClockoutEvent',(e)=>{
                            let labor=e.laborReport;
                            laborReports.every(function (laborReport) {
                                if (laborReport.id==labor.id){
                                    laborReport.thisRecordOnlineTime=labor.thisRecordOnlineTime;
                                    laborReport.thisRecordWorkingTime=labor.thisRecordWorkingTime;
                                    laborReport.is_exportGroup=labor.is_exportGroup;
                                    laborReport.checkOutAt=labor.check_out_at;
                                    laborReport.round_check_out_at=labor.round_check_out_at;
                                    if (labor.relax_time){
                                        laborReport.relax_time=labor.relax_time;
                                    }
                                    return false
                                }
                                return true;
                            });
                        });
                    });
                    $(".tooltipTarget").tooltip({'trigger':'hover'});
                    $('#list').removeClass('d-none');
                    let data=[
                        [
                            {name:'created_at_start',type:'dateTime',tip:'选择显示指定日期的起始时间'},
                            {name:'user_workgroup_id',type:'select_multiple_select',tip:['输入关键词快速定位下拉列表，回车确定','选择要显示的小组'],
                                placeholder:['小组','定位或多选小组'],data:this.userWorkGroups},
                            {name:'labor_company_id',type:'select_multiple_select',tip:['输入关键词快速定位下拉列表，回车确定','选择要显示的劳务所'],
                                placeholder:['劳务所','定位或多选劳务所'],data:this.laborCompanies},
                            {name:'enter_number',type:'input',tip:'可支持多进场编号:支持15天内模糊搜索',placeholder: '进场编号'},
                            {name:'is_export',type:'checkbox',data:[{name:true,value:'显示已退场'}]},
                        ],
                        [
                            {name:'created_at_end',type:'dateTime',tip:'选择显示指定日期的结束时间'},
                            {name:'name',type:'input',tip:'可支持多姓名，模糊搜索可在两侧增加百分号(%)进行',placeholder: '姓名'},
                            {name:'mobile_phone',type:'input',tip:'可支持多电话号，模糊搜索可在两侧增加百分号(%)进行',placeholder: '电话号'},
                            {name:'identity_number',type:'input',tip:'可支持多身份证号:支持15天内模糊搜索',placeholder: '身份证号'},
                        ],
                    ];
                    this.form = new query({
                        el:"#form_div",
                        condition:data,
                    });
                    this.form.init();
                    let column = [
                        {name:'index',value: '序号', neglect: true},
                        {name:'operation',value: '操作', neglect: true},
                        {name:'thisRoundRecordWorkingTime',value:'本次工作时长', neglect: true},
                        {name:'userWorkGroupName',value: '小组', style:'background-color: rgb(241, 234, 190)'},
                        {name:'name',value: '临时工', style:'background-color: rgb(241, 234, 190)'},
                        {name:'mobile_phone',value: '电话', style:'background-color: rgb(241, 234, 190)'},
                        {name:'identity_number',value: '身份证号', style:'background-color: rgb(241, 234, 190)'},
                        {name:'labor_company',value: '劳务所', style:'background-color: rgb(241, 234, 190)'},
                        {name:'enter_at',value: '进场时间'},
                        {name:'checkInAt',value: '进组时间'},
                        {name:'checkOutAt',value: '退组时间'},
                        {name:'round_check_in_at',value: '进组取整时间'},
                        {name:'round_check_out_at',value: '退组取整时间'},
                        {name:'exit_at',value: '退场时间'},
                        {name:'verifyAt',value: '审核时间'},
                        {name:'verifyPerson',value: '审核人'},
                        {name:'relax_time',value: '晚饭打卡(分)', neglect: true},
                        {name:'thisRecordOnlineTime',value:'在线时长', neglect: true},
                        {name:'enter_number',value: '进厂编号', style:'background-color: rgb(241, 234, 190)'},
                        {name:'remark',value: '备注'},
                            @can('人事管理-临时工报表-删除')
                        {name:'remove',value: '操作'},
                        @endcan
                    ];
                    if (window.innerWidth > 543){
                        new Header({
                            el: "table",
                            name:"laborReport",
                            column: column,
                            data: this.laborReports,
                            fixedTop:($('#form_div').height())+2,
                        }).init();
                    }
                    setTimeout(function () {
                        let $dom_thisRecordWorkingTime=$('#dom_thisRoundRecordWorkingTime');
                        $dom_thisRecordWorkingTime.attr('title','用工总工时:'+_this.totalWorkingHours);
                        $dom_thisRecordWorkingTime.tooltip({'trigger':'manual'});
                        $dom_thisRecordWorkingTime.tooltip('show')
                    },0);
                },
                methods:{
                    selectTableRow(id,e){
                        $('#headerParent tr[class=focusing]').removeClass('focusing')
                        if (id === this.selectTr) {
                            this.selectTr = '';
                            return;
                        }
                        this.selectTr = id;
                        $(e.target).parent('tr').addClass('focusing')
                    },
                    //备注修改
                    laborReportRemarkCheck:function (e) {
                        let target = $(e.target);
                        target.hide();
                        let input = target.next();
                        input.show();
                        input.focus();
                    },
                    // 失焦事件
                    updateLaborReportRemark:function (e) {
                        let target = $(e.target);
                        let _this = this;
                        let span = target.prev();
                        let id = target.attr('data_id');
                        let oldRemark = span.text();
                        let remark = target.val();
                        if(remark !== span.text()){
                            let ajaxUrl= '{{url("laborReport/changeLaborReportRemark")}}';
                            axios.post(ajaxUrl,{'id':id,'remark':remark}).then(function (response) {
                                if(response.data.success){
                                    _this.updateLaborReports(id,remark);
                                    tempTip.setDuration(2000);
                                    tempTip.showSuccess('备注修改成功');
                                }else{
                                    tempTip.setDuration(3000);
                                    tempTip.show('备注修改失败!'+response.data.fail_info);
                                    _this.updateLaborReports(id,oldRemark);
                                }
                            }).catch(function (err) {
                                tempTip.setDuration(3000);
                                tempTip.show('备注修改失败!网络异常：'+err);
                                _this.updateLaborReports(id,oldRemark);
                            });
                        }
                        span.show();
                        target.hide();
                    },
                    addLaborReportRemark(e){
                        let target = $(e.target);
                        target.css('width','85px');
                        let _this = this;
                        let id = target.attr('data_id');
                        let remark = target.val();
                        let ajaxUrl= '{{url("laborReport/changeLaborReportRemark")}}';
                        if(remark === ''|| remark === null){
                            target.css('width','75px');
                            return;
                        }else{
                            axios.post(ajaxUrl,{'id':id,'remark':remark}).then(function (response) {
                                if(response.data.success){
                                    tempTip.setDuration(2000);
                                    tempTip.showSuccess('备注添加成功');
                                    _this.updateLaborReports(id,remark);
                                }else{
                                    tempTip.setDuration(3000);
                                    tempTip.show('备注添加失败!'+response.data.fail_info);
                                }
                            }).catch(function (err) {
                                tempTip.setDuration(3000);
                                tempTip.show('备注添加失败！网络异常：'+response.data.fail_info);
                            });
                            target.css('width','75px');
                        }
                    },
                    // 更新表格数据
                    updateLaborReports(id,newFee){
                        this.laborReports.some(function(laborReport){
                            if(laborReport.id === id){
                                laborReport.remark = newFee;
                                return true;
                            }
                        })
                    },
                    selectedColor(id){
                        if (id==this.selectedStyle){
                            this.selectedStyle='';
                            return;
                        }
                        this.selectedStyle=id;
                    },
                    laborReportExport(checkAllSign){
                        let url = '{{url('laborReport/export')}}';
                        let token='{{ csrf_token() }}';
                        excelExport(checkAllSign,checkData,url,this.sum,token);
                    },
                    //门卫审核
                    guardClockAudit(id,user_duty_check_id){
                        let url='{{url("laborReport/guardClockAudit")}}';
                        let _this=this;
                        axios.post(url,{id:id,user_duty_check_id:user_duty_check_id})
                            .then(function (response) {
                                if (!response.data.success){
                                    tempTip.setDuration(3000);
                                    tempTip.show(response.data.data);
                                    return;
                                }
                                _this.laborReports.every(function (laborReport) {
                                    if (laborReport.id==id){
                                        laborReport.userDutyCheckVerifyUserId=response.data.data;
                                        tempTip.setDuration(1000);
                                        tempTip.showSuccess('审核通过！');
                                        return false
                                    }
                                    return true;
                                });
                            }).catch(function (err) {
                            tempTip.setDuration(4000);
                            tempTip.show('审核失败！网络错误：'+err);
                        });
                    },
                    //组长打卡审核(特定组添加备注)
                    addRemarkAndGroupClock(){
                        let _this=this;
                        let id = getSelectId();
                        let remark=document.getElementById('remark').value;
                        let url='{{url("laborReport/addRemarkAndGroupClock")}}';
                        if (remark==null|| remark=='' || remark=="undefined"){
                            tempTip.setDuration(3000);
                            tempTip.show("您还未添加任何备注");
                            return;
                        }
                        axios.post(url,{id:id,remark:remark})
                            .then(function (response) {
                                if (!response.data.success){
                                    tempTip.setDuration(3000);
                                    tempTip.show(response.data.data);
                                    return;
                                }
                                _this.laborReports.every(function (laborReport) {
                                    if (laborReport.id==id){
                                        laborReport.groupUserId=response.data.data.group_user_id;
                                        laborReport.verifyAt=response.data.data.verify_at;
                                        laborReport.verifyPerson=response.data.data.verifyPerson;
                                        laborReport.remark=response.data.data.remark;
                                        tempTip.setDuration(1000);
                                        tempTip.showSuccess('审核通过！');
                                        return false
                                    }
                                    return true;
                                });
                            }).catch(function (err) {
                            tempTip.setDuration(4000);
                            tempTip.show('审核失败！网络错误：'+err);
                        });

                    },
                    //组长打卡审核
                    groupClockAudit(id,userWorkgroupNeedRemark){
                        let url='{{url("laborReport/groupClockAudit")}}';
                        let _this=this;
                        if (userWorkgroupNeedRemark){
                            selectId(id);
                            $('#remarkModal').modal('show');
                            return;
                        }
                        axios.post(url,{id:id})
                            .then(function (response) {
                                if (!response.data.success){
                                    tempTip.setDuration(3000);
                                    tempTip.show(response.data.data);
                                    return;
                                }
                                _this.laborReports.every(function (laborReport) {
                                    if (laborReport.id==id){
                                        laborReport.groupUserId=response.data.data.group_user_id;
                                        laborReport.verifyAt=response.data.data.verify_at;
                                        laborReport.verifyPerson=response.data.data.verifyPerson;
                                        tempTip.setDuration(1000);
                                        tempTip.showSuccess('审核通过！');
                                        return false
                                    }
                                    return true;
                                });
                            }).catch(function (err) {
                            tempTip.setDuration(4000);
                            tempTip.show('审核失败！网络错误：'+err);
                        });
                    },
                    //有晚餐
                    haveDinner(){
                        $('#exampleModal').modal('show');
                    },
                    noDinner(){
                        let _this=this;
                        let id = _this.laborReportId;
                        let url='{{url("laborReport/groupExport")}}';
                        axios.post(url,{id:id})
                            .then(function (response) {
                                if (!response.data.success){
                                    tempTip.setDuration(3000);
                                    tempTip.show(response.data.data);
                                    return;
                                }
                                _this.laborReports.every(function (laborReport) {
                                    if (laborReport.id==id){
                                        laborReport.checkOutAt=response.data.data.check_out_at;
                                        laborReport.workingDuration=response.data.data.working_duration;
                                        laborReport.is_exportGroup=response.data.data.is_exportGroup;
                                        laborReport.onlineDuration=response.data.data.online_duration;
                                        tempTip.setDuration(2000);
                                        tempTip.showSuccess('退组成功！');
                                        return false
                                    }
                                    return true;
                                });
                            }).catch(function (err) {
                            tempTip.setDuration(4000);
                            tempTip.show('退组失败！网络错误：'+err);
                        });
                    },
                    //退场有晚饭时间
                    makeSureRelax_time(){
                        let url='{{url("laborReport/groupExportEnsure")}}';
                        let _this=this;
                        let id = _this.laborReportId;
                        axios.post(url,{id:id,relax_time:_this.relax_time})
                            .then(function (response) {
                                if (!response.data.success){
                                    tempTip.setDuration(3000);
                                    tempTip.show(response.data.data);
                                    return;
                                }
                                _this.laborReports.every(function (laborReport) {
                                    if (laborReport.id==id){
                                        laborReport.checkOutAt=response.data.data.check_out_at;
                                        laborReport.workingDuration=response.data.data.working_duration;
                                        laborReport.relax_time=response.data.data.relax_time;
                                        laborReport.is_exportGroup=response.data.data.is_exportGroup;
                                        laborReport.onlineDuration=response.data.data.online_duration;
                                        tempTip.setDuration(2000);
                                        tempTip.showSuccess('退组成功！');
                                        return false
                                    }
                                    return true;
                                });
                            }).catch(function (err) {
                            tempTip.setDuration(4000);
                            tempTip.show('退组失败！网络错误：'+err);
                        });
                    },
                    //组长点击退组,
                    groupExport(id,name){
                        let _this=this;
                        _this.laborReports.every(function (laborReport) {
                            if (laborReport.id==id){
                                _this.dateTime=new Date(new Date(laborReport.created_at).toLocaleDateString());
                                return false;
                            }
                            return true;
                        });
                        const dateTime=new Date(_this.dateTime.setDate(_this.dateTime.getDate()+1));
                        const start = new Date(new Date(new Date().toLocaleDateString()).getTime()+19*60*60*1000);
                        if(!confirm("确定要临时工“"+name+"“退组吗？")){return}
                        if (new Date()>=start || new Date()>dateTime){
                            _this.laborReportId=id;
                            $('#dinnerModal').modal('show');
                            return;
                        }
                        let url='{{url("laborReport/groupExport")}}';
                        axios.post(url,{id:id})
                            .then(function (response) {
                                if (!response.data.success){
                                    tempTip.setDuration(3000);
                                    tempTip.show(response.data.data);
                                    return;
                                }
                                _this.laborReports.every(function (laborReport) {
                                    if (laborReport.id==id){
                                        laborReport.checkOutAt=response.data.data.check_out_at;
                                        laborReport.workingDuration=response.data.data.working_duration;
                                        laborReport.is_exportGroup=response.data.data.is_exportGroup;
                                        laborReport.onlineDuration=response.data.data.online_duration;
                                        tempTip.setDuration(2000);
                                        tempTip.showSuccess('退组成功！');
                                        return false
                                    }
                                    return true;
                                });
                            }).catch(function (err) {
                            tempTip.setDuration(5000);
                            tempTip.show('退组失败！网络错误：'+err);
                        });
                    },
                    owner_seek:function (e) {
                        let _this=this;
                        let $val=e.target.value;
                        if($val==='')_this.filterData.user_workgroup_id='';
                        else
                            _this.userWorkGroups.forEach(function (userWorkGroup) {
                                if (userWorkGroup.name.includes($val)){
                                    _this.filterData.user_workgroup_id=userWorkGroup.id;
                                }
                            });
                    },
                    updateLaborCompany(laborCompanyId,enter_number){
                        let _this=this;
                        let url='{{url("laborReport/updateLaborCompany")}}';
                        axios.post(url,{enter_number:enter_number,laborCompanyId:laborCompanyId}).then(function (response) {
                            if (!response.data.success){
                                tempTip.setDuration(3000);
                                tempTip.show('修改劳务所失败'+response.data.data);
                                return;
                            }else {
                                _this.laborReports.forEach(function (laborReport) {
                                    if (laborReport.enter_number==response.data.data.enter_number){
                                        laborReport.labor_company_id=response.data.data.labor_company_id;
                                        laborReport.labor_company=response.data.labor_company;
                                    }
                                })
                                tempTip.setDuration(3000);
                                tempTip.showSuccess('修改劳务所成功！');

                            }
                        }).catch(function (err) {
                            tempTip.setDuration(3000);
                            tempTip.show('修改劳务所失败！网络错误：'+err);
                        });
                    },
                    删除(id,name){
                        let _this=this;
                        if(!confirm('确定要删除临时工为：“'+name+'”的报表记录吗？')){return};
                        let url='{{url("laborReport/删除")}}/'+id;
                        axios.delete(url).then(
                            function (response) {
                                if(!response.data.success){
                                    tempTip.setDuration(3000);
                                    tempTip.show('临时工报表记录删除失败!'+response.data.data);
                                }else {
                                    _this.laborReports.every(function (laborReport,i) {
                                        if (response.data.data>0&&laborReport.id===id){
                                            _this.laborReports.splice(i,1);
                                            return false;
                                        }else {
                                            return true
                                        }
                                    });
                                    tempTip.setDuration(3000);
                                    tempTip.showSuccess('临时工报表记录删除成功!');
                                }
                            }
                        ).catch(function (err) {
                            tempTip.setDuration(3000);
                            tempTip.show('删除失败,网络链接错误！'+err);
                        });

                    },

                },
            });

        let select_id = 0;
        function selectId(id) {
            select_id = id;
        }
        function getSelectId() {
            return select_id;
        }
    </script>
@endsection
